Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2024-10-14 13:36:02 +0000
committerPeter Eisentraut2024-10-14 13:36:02 +0000
commit0d2aa4d4937bb0500823edfc7d620f4e5fa45b9c (patch)
treeb5165a7924bd11544d649daac2052a649b7e6b3f /src/backend/parser
parente7d0cf42b1acb185edc947a8732843966ea3c160 (diff)
Track sort direction in SortGroupClause
Functions make_pathkey_from_sortop() and transformWindowDefinitions(), which receive a SortGroupClause, were determining the sort order (ascending vs. descending) by comparing that structure's operator strategy to BTLessStrategyNumber, but could just as easily have gotten it from the SortGroupClause object, if it had such a field, so add one. This reduces the number of places that hardcode the assumption that the strategy refers specifically to a btree strategy, rather than some other index AM's operators. Author: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/analyze.c1
-rw-r--r--src/backend/parser/parse_clause.c5
2 files changed, 5 insertions, 1 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index e901203424d..2d3d8fcf769 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -1985,6 +1985,7 @@ makeSortGroupClauseForSetOp(Oid rescoltype, bool require_hash)
grpcl->tleSortGroupRef = 0;
grpcl->eqop = eqop;
grpcl->sortop = sortop;
+ grpcl->reverse_sort = false; /* Sort-op is "less than", or InvalidOid */
grpcl->nulls_first = false; /* OK with or without sortop */
grpcl->hashable = hashable;
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index 8118036495b..4c976909088 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -2933,7 +2933,7 @@ transformWindowDefinitions(ParseState *pstate,
sortcl->sortop);
/* Record properties of sort ordering */
wc->inRangeColl = exprCollation(sortkey);
- wc->inRangeAsc = (rangestrategy == BTLessStrategyNumber);
+ wc->inRangeAsc = !sortcl->reverse_sort;
wc->inRangeNullsFirst = sortcl->nulls_first;
}
@@ -3489,6 +3489,7 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle,
sortcl->eqop = eqop;
sortcl->sortop = sortop;
sortcl->hashable = hashable;
+ sortcl->reverse_sort = reverse;
switch (sortby->sortby_nulls)
{
@@ -3571,6 +3572,8 @@ addTargetToGroupList(ParseState *pstate, TargetEntry *tle,
grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist);
grpcl->eqop = eqop;
grpcl->sortop = sortop;
+ grpcl->reverse_sort = false; /* sortop is "less than", or
+ * InvalidOid */
grpcl->nulls_first = false; /* OK with or without sortop */
grpcl->hashable = hashable;