From 0d2aa4d4937bb0500823edfc7d620f4e5fa45b9c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 14 Oct 2024 15:36:02 +0200 Subject: 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 Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com --- src/backend/parser/parse_clause.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/backend/parser/parse_clause.c') 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; -- cgit v1.2.3