@@ -108,7 +108,6 @@ static bool choose_hashed_distinct(PlannerInfo *root,
108
108
static List * make_subplanTargetList (PlannerInfo * root , List * tlist ,
109
109
AttrNumber * * groupColIdx , bool * need_tlist_eval );
110
110
static int get_grouping_column_index (Query * parse , TargetEntry * tle );
111
- static int get_sort_column_index (Query * parse , TargetEntry * tle );
112
111
static void locate_grouping_columns (PlannerInfo * root ,
113
112
List * tlist ,
114
113
List * sub_tlist ,
@@ -2460,13 +2459,6 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
2460
2459
parse -> limitCount ,
2461
2460
offset_est ,
2462
2461
count_est );
2463
- if (parse -> sortClause && tlist != result_plan -> targetlist )
2464
- {
2465
- result_plan = (Plan * ) make_result (root ,
2466
- tlist ,
2467
- NULL ,
2468
- result_plan );
2469
- }
2470
2462
}
2471
2463
2472
2464
/*
@@ -4033,8 +4025,8 @@ make_subplanTargetList(PlannerInfo *root,
4033
4025
bool * need_tlist_eval )
4034
4026
{
4035
4027
Query * parse = root -> parse ;
4036
- List * sub_tlist = NIL ;
4037
- List * non_group_cols = NIL ;
4028
+ List * sub_tlist ;
4029
+ List * non_group_cols ;
4038
4030
List * non_group_vars ;
4039
4031
int numCols ;
4040
4032
@@ -4047,61 +4039,6 @@ make_subplanTargetList(PlannerInfo *root,
4047
4039
if (!parse -> hasAggs && !parse -> groupClause && !parse -> groupingSets && !root -> hasHavingQual &&
4048
4040
!parse -> hasWindowFuncs )
4049
4041
{
4050
- if (parse -> sortClause && limit_needed (parse )) {
4051
- ListCell * tl ;
4052
- bool contains_non_vars = false;
4053
- * need_tlist_eval = false; /* only eval if not flat tlist */
4054
- foreach (tl , tlist )
4055
- {
4056
- TargetEntry * tle = (TargetEntry * ) lfirst (tl );
4057
- int colno ;
4058
-
4059
- colno = get_sort_column_index (parse , tle );
4060
- if (colno >= 0 )
4061
- {
4062
- TargetEntry * newtle ;
4063
-
4064
- newtle = makeTargetEntry (tle -> expr ,
4065
- list_length (sub_tlist ) + 1 ,
4066
- NULL ,
4067
- false);
4068
- sub_tlist = lappend (sub_tlist , newtle );
4069
- if (!(newtle -> expr && IsA (newtle -> expr , Var )))
4070
- * need_tlist_eval = true; /* tlist contains non Vars */
4071
- }
4072
- else
4073
- {
4074
- /*
4075
- * Non-sorting column, so just remember the expression for
4076
- * later call to pull_var_clause. There's no need for
4077
- * pull_var_clause to examine the TargetEntry node itself.
4078
- */
4079
- non_group_cols = lappend (non_group_cols , tle -> expr );
4080
- contains_non_vars |= !(tle -> expr && IsA (tle -> expr , Var ));
4081
- }
4082
- }
4083
-
4084
- if (non_group_cols ) /* there are some columns not used in order by */
4085
- {
4086
- non_group_vars = pull_var_clause ((Node * ) non_group_cols ,
4087
- PVC_RECURSE_AGGREGATES ,
4088
- PVC_INCLUDE_PLACEHOLDERS );
4089
- sub_tlist = add_to_flat_tlist (sub_tlist , non_group_vars );
4090
- /* clean up cruft */
4091
- list_free (non_group_vars );
4092
- list_free (non_group_cols );
4093
-
4094
- if (contains_non_vars )
4095
- {
4096
- /*
4097
- * This optimization makes sense only if target list contains some complex expressions,
4098
- * for example functions calls. May be it is better to check cost of this expressions,
4099
- * but right now just apply this optimization if there are non-vars columns
4100
- */
4101
- return sub_tlist ;
4102
- }
4103
- }
4104
- }
4105
4042
* need_tlist_eval = true;
4106
4043
return tlist ;
4107
4044
}
@@ -4110,6 +4047,8 @@ make_subplanTargetList(PlannerInfo *root,
4110
4047
* Otherwise, we must build a tlist containing all grouping columns, plus
4111
4048
* any other Vars mentioned in the targetlist and HAVING qual.
4112
4049
*/
4050
+ sub_tlist = NIL ;
4051
+ non_group_cols = NIL ;
4113
4052
* need_tlist_eval = false; /* only eval if not flat tlist */
4114
4053
4115
4054
numCols = list_length (parse -> groupClause );
@@ -4231,37 +4170,6 @@ get_grouping_column_index(Query *parse, TargetEntry *tle)
4231
4170
return -1 ;
4232
4171
}
4233
4172
4234
- /*
4235
- * get_sort_column_index
4236
- * Get the ORDER BY column position, if any, of a targetlist entry.
4237
- *
4238
- * Returns the index (counting from 0) of the TLE in the ORDER BY list, or -1
4239
- * if it's not a sorting column. Note: the result is unique because the
4240
- * parser won't make multiple sortClause entries for the same TLE.
4241
- */
4242
- static int
4243
- get_sort_column_index (Query * parse , TargetEntry * tle )
4244
- {
4245
- int colno = 0 ;
4246
- Index ressortgroupref = tle -> ressortgroupref ;
4247
- ListCell * gl ;
4248
-
4249
- /* No need to search groupClause if TLE hasn't got a sortgroupref */
4250
- if (ressortgroupref == 0 )
4251
- return -1 ;
4252
-
4253
- foreach (gl , parse -> sortClause )
4254
- {
4255
- SortGroupClause * sortcl = (SortGroupClause * ) lfirst (gl );
4256
-
4257
- if (sortcl -> tleSortGroupRef == ressortgroupref )
4258
- return colno ;
4259
- colno ++ ;
4260
- }
4261
-
4262
- return -1 ;
4263
- }
4264
-
4265
4173
/*
4266
4174
* locate_grouping_columns
4267
4175
* Locate grouping columns in the tlist chosen by create_plan.
0 commit comments