@@ -104,7 +104,6 @@ static double get_number_of_groups(PlannerInfo *root,
104104static RelOptInfo * create_grouping_paths (PlannerInfo * root ,
105105 RelOptInfo * input_rel ,
106106 PathTarget * target ,
107- AttrNumber * groupColIdx ,
108107 List * rollup_lists ,
109108 List * rollup_groupclauses );
110109static RelOptInfo * create_window_paths (PlannerInfo * root ,
@@ -125,9 +124,7 @@ static RelOptInfo *create_distinct_paths(PlannerInfo *root,
125124static RelOptInfo * create_ordered_paths (PlannerInfo * root ,
126125 RelOptInfo * input_rel ,
127126 double limit_tuples );
128- static PathTarget * make_scanjoin_target (PlannerInfo * root , List * tlist ,
129- AttrNumber * * groupColIdx );
130- static int get_grouping_column_index (Query * parse , TargetEntry * tle );
127+ static PathTarget * make_scanjoin_target (PlannerInfo * root , List * tlist );
131128static List * postprocess_setop_tlist (List * new_tlist , List * orig_tlist );
132129static List * select_active_windows (PlannerInfo * root , WindowFuncLists * wflists );
133130static List * make_windowInputTargetList (PlannerInfo * root ,
@@ -1462,7 +1459,6 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
14621459 {
14631460 /* No set operations, do regular planning */
14641461 PathTarget * sub_target ;
1465- AttrNumber * groupColIdx ;
14661462 double tlist_rows ;
14671463 List * grouping_tlist ;
14681464 WindowFuncLists * wflists = NULL ;
@@ -1656,8 +1652,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
16561652 * because the target width estimates can use per-Var width numbers
16571653 * that were obtained within query_planner().
16581654 */
1659- sub_target = make_scanjoin_target (root , tlist ,
1660- & groupColIdx );
1655+ sub_target = make_scanjoin_target (root , tlist );
16611656
16621657 /*
16631658 * Forcibly apply that tlist to all the Paths for the scan/join rel.
@@ -1714,7 +1709,6 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
17141709 current_rel ,
17151710 create_pathtarget (root ,
17161711 grouping_tlist ),
1717- groupColIdx ,
17181712 rollup_lists ,
17191713 rollup_groupclauses );
17201714 }
@@ -3077,7 +3071,6 @@ get_number_of_groups(PlannerInfo *root,
30773071 *
30783072 * input_rel: contains the source-data Paths
30793073 * target: the pathtarget for the result Paths to compute
3080- * groupColIdx: array of indexes of grouping columns in the source data
30813074 * rollup_lists: list of grouping sets, or NIL if not doing grouping sets
30823075 * rollup_groupclauses: list of grouping clauses for grouping sets,
30833076 * or NIL if not doing grouping sets
@@ -3092,7 +3085,6 @@ static RelOptInfo *
30923085create_grouping_paths (PlannerInfo * root ,
30933086 RelOptInfo * input_rel ,
30943087 PathTarget * target ,
3095- AttrNumber * groupColIdx ,
30963088 List * rollup_lists ,
30973089 List * rollup_groupclauses )
30983090{
@@ -3236,7 +3228,6 @@ create_grouping_paths(PlannerInfo *root,
32363228 path ,
32373229 target ,
32383230 (List * ) parse -> havingQual ,
3239- groupColIdx ,
32403231 rollup_lists ,
32413232 rollup_groupclauses ,
32423233 & agg_costs ,
@@ -3766,24 +3757,19 @@ create_ordered_paths(PlannerInfo *root,
37663757 * into PathTarget format, which is more compact and includes cost/width.
37673758 *
37683759 * 'tlist' is the query's target list.
3769- * 'groupColIdx' receives an array of column numbers for the GROUP BY
3770- * expressions (if there are any) in the returned target list.
37713760 *
37723761 * The result is the PathTarget to be applied to the Paths returned from
37733762 * query_planner().
37743763 */
37753764static PathTarget *
37763765make_scanjoin_target (PlannerInfo * root ,
3777- List * tlist ,
3778- AttrNumber * * groupColIdx )
3766+ List * tlist )
37793767{
37803768 Query * parse = root -> parse ;
37813769 List * sub_tlist ;
37823770 List * non_group_cols ;
37833771 List * non_group_vars ;
3784- int numCols ;
3785-
3786- * groupColIdx = NULL ;
3772+ ListCell * tl ;
37873773
37883774 /*
37893775 * If we're not grouping or aggregating or windowing, there's nothing to
@@ -3800,64 +3786,35 @@ make_scanjoin_target(PlannerInfo *root,
38003786 sub_tlist = NIL ;
38013787 non_group_cols = NIL ;
38023788
3803- numCols = list_length (parse -> groupClause );
3804- if (numCols > 0 )
3789+ foreach (tl , tlist )
38053790 {
3806- /*
3807- * If grouping, create sub_tlist entries for all GROUP BY columns, and
3808- * make an array showing where the group columns are in the sub_tlist.
3809- *
3810- * Note: with this implementation, the array entries will always be
3811- * 1..N, but we don't want callers to assume that.
3812- */
3813- AttrNumber * grpColIdx ;
3814- ListCell * tl ;
3815-
3816- grpColIdx = (AttrNumber * ) palloc0 (sizeof (AttrNumber ) * numCols );
3817- * groupColIdx = grpColIdx ;
3791+ TargetEntry * tle = (TargetEntry * ) lfirst (tl );
38183792
3819- foreach (tl , tlist )
3793+ if (tle -> ressortgroupref && parse -> groupClause &&
3794+ get_sortgroupref_clause_noerr (tle -> ressortgroupref ,
3795+ parse -> groupClause ) != NULL )
38203796 {
3821- TargetEntry * tle = (TargetEntry * ) lfirst (tl );
3822- int colno ;
3823-
3824- colno = get_grouping_column_index (parse , tle );
3825- if (colno >= 0 )
3826- {
3827- /*
3828- * It's a grouping column, so add it to the result tlist and
3829- * remember its resno in grpColIdx[].
3830- */
3831- TargetEntry * newtle ;
3832-
3833- newtle = makeTargetEntry (tle -> expr ,
3834- list_length (sub_tlist ) + 1 ,
3835- NULL ,
3836- false);
3837- newtle -> ressortgroupref = tle -> ressortgroupref ;
3838- sub_tlist = lappend (sub_tlist , newtle );
3797+ /*
3798+ * It's a grouping column, so add it to the result tlist as-is.
3799+ */
3800+ TargetEntry * newtle ;
38393801
3840- Assert (grpColIdx [colno ] == 0 ); /* no dups expected */
3841- grpColIdx [colno ] = newtle -> resno ;
3842- }
3843- else
3844- {
3845- /*
3846- * Non-grouping column, so just remember the expression for
3847- * later call to pull_var_clause. There's no need for
3848- * pull_var_clause to examine the TargetEntry node itself.
3849- */
3850- non_group_cols = lappend (non_group_cols , tle -> expr );
3851- }
3802+ newtle = makeTargetEntry (tle -> expr ,
3803+ list_length (sub_tlist ) + 1 ,
3804+ NULL ,
3805+ false);
3806+ newtle -> ressortgroupref = tle -> ressortgroupref ;
3807+ sub_tlist = lappend (sub_tlist , newtle );
3808+ }
3809+ else
3810+ {
3811+ /*
3812+ * Non-grouping column, so just remember the expression for later
3813+ * call to pull_var_clause. There's no need for pull_var_clause
3814+ * to examine the TargetEntry node itself.
3815+ */
3816+ non_group_cols = lappend (non_group_cols , tle -> expr );
38523817 }
3853- }
3854- else
3855- {
3856- /*
3857- * With no grouping columns, just pass whole tlist to pull_var_clause.
3858- * Need (shallow) copy to avoid damaging input tlist below.
3859- */
3860- non_group_cols = list_copy (tlist );
38613818 }
38623819
38633820 /*
@@ -3886,37 +3843,6 @@ make_scanjoin_target(PlannerInfo *root,
38863843 return create_pathtarget (root , sub_tlist );
38873844}
38883845
3889- /*
3890- * get_grouping_column_index
3891- * Get the GROUP BY column position, if any, of a targetlist entry.
3892- *
3893- * Returns the index (counting from 0) of the TLE in the GROUP BY list, or -1
3894- * if it's not a grouping column. Note: the result is unique because the
3895- * parser won't make multiple groupClause entries for the same TLE.
3896- */
3897- static int
3898- get_grouping_column_index (Query * parse , TargetEntry * tle )
3899- {
3900- int colno = 0 ;
3901- Index ressortgroupref = tle -> ressortgroupref ;
3902- ListCell * gl ;
3903-
3904- /* No need to search groupClause if TLE hasn't got a sortgroupref */
3905- if (ressortgroupref == 0 )
3906- return -1 ;
3907-
3908- foreach (gl , parse -> groupClause )
3909- {
3910- SortGroupClause * grpcl = (SortGroupClause * ) lfirst (gl );
3911-
3912- if (grpcl -> tleSortGroupRef == ressortgroupref )
3913- return colno ;
3914- colno ++ ;
3915- }
3916-
3917- return -1 ;
3918- }
3919-
39203846/*
39213847 * postprocess_setop_tlist
39223848 * Fix up targetlist returned by plan_set_operations().
0 commit comments