protected Set<LogicalVariable> computeGbyVarsUsingPksOnly(Set<LogicalVariable> varSet, AbstractLogicalOperator op, IOptimizationContext context) throws AlgebricksException { PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context); List<FunctionalDependency> fdList = context.getFDList(op); if (fdList == null) { return null; } // check if any of the FDs is a key for (FunctionalDependency fd : fdList) { if (fd.getTail().containsAll(varSet)) { return new HashSet<LogicalVariable>(fd.getHead()); } } return null; }
protected Set<LogicalVariable> computeGbyVars(AbstractLogicalOperator op, Set<LogicalVariable> freeVars, IOptimizationContext context) throws AlgebricksException { PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context); List<FunctionalDependency> fdList = context.getFDList(op); if (fdList == null) { return null; } // check if any of the FDs is a key List<LogicalVariable> all = new ArrayList<LogicalVariable>(); VariableUtilities.getLiveVariables(op, all); all.retainAll(freeVars); for (FunctionalDependency fd : fdList) { if (fd.getTail().containsAll(all)) { return new HashSet<LogicalVariable>(fd.getHead()); } } return null; }
private IPhysicalPropertiesVector newPropertiesDiff(AbstractLogicalOperator newChild, IPhysicalPropertiesVector required, boolean mayExpandPartitioningProperties, IOptimizationContext context) throws AlgebricksException { IPhysicalPropertiesVector newDelivered = newChild.getDeliveredPhysicalProperties(); Map<LogicalVariable, EquivalenceClass> newChildEqClasses = context.getEquivalenceClassMap(newChild); List<FunctionalDependency> newChildFDs = context.getFDList(newChild); if (newChildEqClasses == null || newChildFDs == null) { FDsAndEquivClassesVisitor fdsVisitor = new FDsAndEquivClassesVisitor(); newChild.accept(fdsVisitor, context); newChildEqClasses = context.getEquivalenceClassMap(newChild); newChildFDs = context.getFDList(newChild); } if (AlgebricksConfig.ALGEBRICKS_LOGGER.isTraceEnabled()) { AlgebricksConfig.ALGEBRICKS_LOGGER.trace( ">>>> Required properties for new op. " + newChild.getPhysicalOperator() + ": " + required + "\n"); } return newDelivered.getUnsatisfiedPropertiesFrom(required, mayExpandPartitioningProperties, newChildEqClasses, newChildFDs); }
private IPhysicalOperator createHashConnector(IOptimizationContext ctx, IPhysicalPropertiesVector deliveredByChild, INodeDomain domain, IPhysicalPropertiesVector requiredAtChild, IPartitioningProperty rqdPartitioning, int childIndex, ILogicalOperator parentOp) { IPhysicalOperator hashConnector; List<LogicalVariable> vars = new ArrayList<>(((UnorderedPartitionedProperty) rqdPartitioning).getColumnSet()); String hashMergeHint = (String) ctx.getMetadataProvider().getConfig().get(HASH_MERGE); if (hashMergeHint == null || !hashMergeHint.equalsIgnoreCase(TRUE_CONSTANT)) { hashConnector = new HashPartitionExchangePOperator(vars, domain); return hashConnector; } List<ILocalStructuralProperty> cldLocals = deliveredByChild.getLocalProperties(); List<ILocalStructuralProperty> reqdLocals = requiredAtChild.getLocalProperties(); boolean propWasSet = false; hashConnector = null; if (reqdLocals != null && cldLocals != null && allAreOrderProps(cldLocals)) { AbstractLogicalOperator c = (AbstractLogicalOperator) parentOp.getInputs().get(childIndex).getValue(); Map<LogicalVariable, EquivalenceClass> ecs = ctx.getEquivalenceClassMap(c); List<FunctionalDependency> fds = ctx.getFDList(c); if (PropertiesUtil.matchLocalProperties(reqdLocals, cldLocals, ecs, fds)) { List<OrderColumn> orderColumns = getOrderColumnsFromGroupingProperties(reqdLocals, cldLocals); hashConnector = new HashPartitionMergeExchangePOperator(orderColumns, vars, domain); propWasSet = true; } } if (!propWasSet) { hashConnector = new HashPartitionExchangePOperator(vars, domain); } return hashConnector; }
List<FunctionalDependency> fds = context.getFDList(op); if (fds != null && !fds.isEmpty()) { return false;
private boolean isRedundantSort(Mutable<ILogicalOperator> opRef, IPhysicalPropertiesVector delivered, IPhysicalPropertiesVector diffOfProperties, IOptimizationContext context) { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.ORDER || (op.getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.STABLE_SORT && op.getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.IN_MEMORY_STABLE_SORT) || delivered.getLocalProperties() == null) { return false; } AbstractStableSortPOperator sortOp = (AbstractStableSortPOperator) op.getPhysicalOperator(); sortOp.computeLocalProperties(op); ILocalStructuralProperty orderProp = sortOp.getOrderProperty(); return PropertiesUtil.matchLocalProperties(Collections.singletonList(orderProp), delivered.getLocalProperties(), context.getEquivalenceClassMap(op), context.getFDList(op)); }
mayExpandPartitioningProperties, context.getEquivalenceClassMap(child), context.getFDList(child));