mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Fix asymmetry in setting EquivalenceClass.ec_sortref
0452b461bc made get_eclass_for_sort_expr() always set
EquivalenceClass.ec_sortref if it's not done yet. This leads to an asymmetric
situation when whoever first looks for the EquivalenceClass sets the
ec_sortref. It is also counterintuitive that get_eclass_for_sort_expr()
performs modification of data structures.
This commit makes make_pathkeys_for_sortclauses_extended() responsible for
setting EquivalenceClass.ec_sortref. Now we set the
EquivalenceClass.ec_sortref's needed to explore alternative GROUP BY ordering
specifically during building pathkeys by the list of grouping clauses.
Discussion: https://postgr.es/m/17037754-f187-4138-8285-0e2bfebd0dea%40postgrespro.ru
Reported-by: Tom Lane
Author: Andrei Lepikhov
Reviewed-by: Alexander Korotkov, Pavel Borisov
This commit is contained in:
@@ -3395,12 +3395,17 @@ standard_qp_callback(PlannerInfo *root, void *extra)
|
||||
*/
|
||||
bool sortable;
|
||||
|
||||
/*
|
||||
* Convert group clauses into pathkeys. Set the ec_sortref field of
|
||||
* EquivalenceClass'es if it's not set yet.
|
||||
*/
|
||||
root->group_pathkeys =
|
||||
make_pathkeys_for_sortclauses_extended(root,
|
||||
&root->processed_groupClause,
|
||||
tlist,
|
||||
true,
|
||||
&sortable);
|
||||
&sortable,
|
||||
true);
|
||||
if (!sortable)
|
||||
{
|
||||
/* Can't sort; no point in considering aggregate ordering either */
|
||||
@@ -3450,7 +3455,8 @@ standard_qp_callback(PlannerInfo *root, void *extra)
|
||||
&root->processed_distinctClause,
|
||||
tlist,
|
||||
true,
|
||||
&sortable);
|
||||
&sortable,
|
||||
false);
|
||||
if (!sortable)
|
||||
root->distinct_pathkeys = NIL;
|
||||
}
|
||||
@@ -3476,7 +3482,8 @@ standard_qp_callback(PlannerInfo *root, void *extra)
|
||||
&groupClauses,
|
||||
tlist,
|
||||
false,
|
||||
&sortable);
|
||||
&sortable,
|
||||
false);
|
||||
if (!sortable)
|
||||
root->setop_pathkeys = NIL;
|
||||
}
|
||||
@@ -6061,7 +6068,8 @@ make_pathkeys_for_window(PlannerInfo *root, WindowClause *wc,
|
||||
&wc->partitionClause,
|
||||
tlist,
|
||||
true,
|
||||
&sortable);
|
||||
&sortable,
|
||||
false);
|
||||
|
||||
Assert(sortable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user