protected PlanNode createCanonicalPlan ( QueryContext context , Query query ) { PlanNode plan = null ; // Process the source of the query ... Map < SelectorName , Table > usedSources = new HashMap < SelectorName , Table > ( ) ; plan = createPlanNode ( context , query . source ( ) , usedSources ) ; // Attach criteria (on top) ... Map < String , Subquery > subqueriesByVariableName = new HashMap < String , Subquery > ( ) ; plan = attachCriteria ( context , plan , query . constraint ( ) , query . columns ( ) , subqueriesByVariableName ) ; // Attach groupbys (on top) ... // plan = attachGrouping(context,plan,query.getGroupBy()); // Attach the project ... plan = attachProject ( context , plan , query . columns ( ) , usedSources ) ; // Attach duplicate removal ... if ( query . isDistinct ( ) ) { plan = attachDuplicateRemoval ( context , plan ) ; } // Process the orderings and limits ... plan = attachSorting ( context , plan , query . orderings ( ) ) ; plan = attachLimits ( context , plan , query . getLimits ( ) ) ; // Capture if we're limiting the results to 1 row and no offset and no sorting ... if ( query . getLimits ( ) . isLimitedToSingleRowWithNoOffset ( ) && query . orderings ( ) . isEmpty ( ) ) { context . getHints ( ) . isExistsQuery = true ; } // Now add in the subqueries as dependent joins, in reverse order ... plan = attachSubqueries ( context , plan , subqueriesByVariableName ) ; // Validate that all the parts of the query are resolvable ... validate ( context , query , usedSources ) ; // Now we need to validate all of the subqueries ... for ( Subquery subquery : Visitors . subqueries ( query , false ) ) { // Just do it by creating a plan, even though we aren't doing anything with these plans ... createPlan ( context , subquery . getQuery ( ) ) ; } return plan ; }
Create a canonical query plan for the given query .