Skip to content

Commit

Permalink
TEIID-4498
Browse files Browse the repository at this point in the history
adding proper projection and project node handling of subqueries
  • Loading branch information
shawkins committed Dec 12, 2018
1 parent 4c12648 commit 78eae36
Show file tree
Hide file tree
Showing 14 changed files with 994 additions and 675 deletions.
Expand Up @@ -27,7 +27,7 @@
import org.teiid.query.util.CommandContext;

/**
* Aggregates XML entries
* Aggregates Json entries
*/
public class JSONArrayAgg extends SingleArgumentAggregateFunction {

Expand Down
Expand Up @@ -36,7 +36,7 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
import org.teiid.query.optimizer.relational.rules.RuleChooseJoinStrategy;
import org.teiid.query.optimizer.relational.rules.RuleMergeCriteria;
import org.teiid.query.optimizer.relational.rules.RulePlanSubqueries;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.processor.proc.ForEachRowPlan;
import org.teiid.query.processor.proc.ProcedurePlan;
Expand Down Expand Up @@ -171,7 +171,7 @@ private ProcessorPlan rewritePlan(TriggerAction ta, IDGenerator idGenerator,
//map to the query form - changes references back to element form
SymbolMap queryMapping = new SymbolMap();
queryMapping.asUpdatableMap().putAll(mapping);
ExpressionMappingVisitor visitor = new RuleMergeCriteria.ReferenceReplacementVisitor(queryMapping);
ExpressionMappingVisitor visitor = new RulePlanSubqueries.ReferenceReplacementVisitor(queryMapping);
DeepPostOrderNavigator.doVisit(queryExpression.getSelect(), visitor);

//now we can return a plan based off a single insert statement
Expand All @@ -181,7 +181,7 @@ private ProcessorPlan rewritePlan(TriggerAction ta, IDGenerator idGenerator,
List<Expression> values = mapped.getValues();
SymbolMap queryMapping = new SymbolMap();
queryMapping.asUpdatableMap().putAll(mapping);
ExpressionMappingVisitor visitor = new RuleMergeCriteria.ReferenceReplacementVisitor(queryMapping);
ExpressionMappingVisitor visitor = new RulePlanSubqueries.ReferenceReplacementVisitor(queryMapping);
Select select = new Select();
select.addSymbols(values);
DeepPostOrderNavigator.doVisit(select, visitor);
Expand Down
Expand Up @@ -991,8 +991,10 @@ public RuleStack buildRules() {

//TODO: update plan sorts to take advantage of semi-join ordering
if (hints.hasJoin || hints.hasCriteria || hints.hasRowBasedSecurity) {
rules.push(new RuleMergeCriteria(idGenerator, capFinder, analysisRecord, context, metadata));
rules.push(RuleConstants.MERGE_CRITERIA);
}

rules.push(new RulePlanSubqueries(idGenerator, capFinder, analysisRecord, context, metadata));

if(hints.hasJoin) {
rules.push(RuleConstants.IMPLEMENT_JOIN_STRATEGY);
Expand Down Expand Up @@ -1681,7 +1683,7 @@ void buildTree(FromClause clause, final PlanNode parent)
//insert is null criteria
IsNullCriteria criteria = new IsNullCriteria((Expression) at.getArrayValue().clone());
if (sfc.getCommand().getCorrelatedReferences() != null) {
RuleMergeCriteria.ReferenceReplacementVisitor rrv = new RuleMergeCriteria.ReferenceReplacementVisitor(sfc.getCommand().getCorrelatedReferences());
RulePlanSubqueries.ReferenceReplacementVisitor rrv = new RulePlanSubqueries.ReferenceReplacementVisitor(sfc.getCommand().getCorrelatedReferences());
PreOrPostOrderNavigator.doVisit(criteria, rrv, PreOrPostOrderNavigator.PRE_ORDER);
}
criteria.setNegated(true);
Expand Down Expand Up @@ -1893,6 +1895,9 @@ public static PlanNode createSelectNode(final Criteria crit, boolean isHaving) {
/*|| !ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(crit).isEmpty()*/)) {
critNode.setProperty(NodeConstants.Info.IS_HAVING, Boolean.TRUE);
}
if (crit instanceof DependentSetCriteria) {
critNode.setProperty(Info.IS_DEPENDENT_SET, true);
}
// Add groups to crit node
critNode.addGroups(GroupsUsedByElementsVisitor.getGroups(crit));
critNode.addGroups(GroupsUsedByElementsVisitor.getGroups(critNode.getCorrelatedReferenceElements()));
Expand Down
Expand Up @@ -311,8 +311,7 @@ public void replaceChild(PlanNode child, PlanNode replacement) {
}

/**
* Add the node as this node's parent. NOTE: This node
* must already have a parent.
* Add the node as this node's parent.
* @param node
*/
public void addAsParent(PlanNode node) {
Expand Down
Expand Up @@ -443,7 +443,7 @@ private static void estimateJoinNodeCost(PlanNode node, QueryMetadataInterface m
nonEquiJoinCriteria = joinCriteria;
}

if (!nonEquiJoinCriteria.isEmpty()) {
if (nonEquiJoinCriteria != null && !nonEquiJoinCriteria.isEmpty()) {
Criteria crit = Criteria.combineCriteria(nonEquiJoinCriteria);
//TODO: we may be able to get a fairly accurate join estimate if the
//unknown side is being joined with a key
Expand Down Expand Up @@ -1575,7 +1575,10 @@ private static LinkedList<PlanNode> determineTargets(
throws QueryPlannerException, TeiidComponentException {
LinkedList<PlanNode> targets = new LinkedList<PlanNode>();
LinkedList<PlanNode> critNodes = new LinkedList<PlanNode>();
critNodes.add(RelationalPlanner.createSelectNode(new DependentSetCriteria(depExpr, null), false));
PlanNode select = RelationalPlanner.createSelectNode(new DependentSetCriteria(depExpr, null), false);
// mark as not a dependent set so that the flag doesn't inadvertently change anything
select.setProperty(Info.IS_DEPENDENT_SET, false);
critNodes.add(select);
LinkedList<PlanNode> initialTargets = new LinkedList<PlanNode>();
initialTargets.add(dependentNode);
while (!critNodes.isEmpty()) {
Expand Down
Expand Up @@ -675,10 +675,7 @@ public static PlanNode getDependentCriteriaNode(String id, List<Expression> inde
static PlanNode createDependentSetNode(String id, List<DependentSetCriteria.AttributeComparison> expressions) {
DependentSetCriteria crit = createDependentSetCriteria(id, expressions);

PlanNode selectNode = RelationalPlanner.createSelectNode(crit, false);

selectNode.setProperty(NodeConstants.Info.IS_DEPENDENT_SET, Boolean.TRUE);
return selectNode;
return RelationalPlanner.createSelectNode(crit, false);
}

static DependentSetCriteria createDependentSetCriteria(String id, List<DependentSetCriteria.AttributeComparison> expressions) {
Expand Down
Expand Up @@ -707,7 +707,7 @@ void buildQuery(PlanNode accessRoot, PlanNode node, Query query, CommandContext

SymbolMap map = (SymbolMap)node.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
if (map != null) {
ExpressionMappingVisitor visitor = new RuleMergeCriteria.ReferenceReplacementVisitor(map);
ExpressionMappingVisitor visitor = new RulePlanSubqueries.ReferenceReplacementVisitor(map);
DeepPostOrderNavigator.doVisit(newQuery, visitor);
sfc.setLateral(true);
}
Expand Down Expand Up @@ -883,7 +883,7 @@ public static void prepareSubquery(SubqueryContainer container) {
}
final SymbolMap map = container.getCommand().getCorrelatedReferences();
if (map != null) {
ExpressionMappingVisitor visitor = new RuleMergeCriteria.ReferenceReplacementVisitor(map);
ExpressionMappingVisitor visitor = new RulePlanSubqueries.ReferenceReplacementVisitor(map);
DeepPostOrderNavigator.doVisit(command, visitor);
}
command.setProcessorPlan(container.getCommand().getProcessorPlan());
Expand Down
Expand Up @@ -49,4 +49,5 @@ private RuleConstants() { }
public static final OptimizerRule SUBSTITUTE_EXPRESSIONS = new RuleSubstituteExpressions();
public static final OptimizerRule PLAN_OUTER_JOINS = new RulePlanOuterJoins();
public static final OptimizerRule PUSH_LARGE_IN = new RulePushLargeIn();
public static final OptimizerRule MERGE_CRITERIA = new RuleMergeCriteria();
}

0 comments on commit 78eae36

Please sign in to comment.