Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d2aa4d

Browse files
committed
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 operatorstrategy to BTLessStrategyNumber, but could just as easily have gottenit from the SortGroupClause object, if it had such a field, so addone. This reduces the number of places that hardcode the assumptionthat the strategy refers specifically to a btree strategy, rather thansome 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
1 parente7d0cf4 commit0d2aa4d

File tree

8 files changed

+18
-8
lines changed

8 files changed

+18
-8
lines changed

‎src/backend/optimizer/path/pathkeys.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ static PathKey *
256256
make_pathkey_from_sortop(PlannerInfo*root,
257257
Expr*expr,
258258
Oidordering_op,
259+
boolreverse_sort,
259260
boolnulls_first,
260261
Indexsortref,
261262
boolcreate_it)
@@ -279,7 +280,7 @@ make_pathkey_from_sortop(PlannerInfo *root,
279280
opfamily,
280281
opcintype,
281282
collation,
282-
(strategy==BTGreaterStrategyNumber),
283+
reverse_sort,
283284
nulls_first,
284285
sortref,
285286
NULL,
@@ -1411,6 +1412,7 @@ make_pathkeys_for_sortclauses_extended(PlannerInfo *root,
14111412
pathkey=make_pathkey_from_sortop(root,
14121413
sortkey,
14131414
sortcl->sortop,
1415+
sortcl->reverse_sort,
14141416
sortcl->nulls_first,
14151417
sortcl->tleSortGroupRef,
14161418
true);

‎src/backend/optimizer/plan/createplan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
18961896
subplan->targetlist);
18971897
sortcl->eqop = eqop;
18981898
sortcl->sortop = sortop;
1899+
sortcl->reverse_sort = false;
18991900
sortcl->nulls_first = false;
19001901
sortcl->hashable = false;/* no need to make this accurate */
19011902
sortList = lappend(sortList, sortcl);

‎src/backend/optimizer/plan/planagg.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848

4949
staticboolcan_minmax_aggs(PlannerInfo*root,List**context);
5050
staticboolbuild_minmax_path(PlannerInfo*root,MinMaxAggInfo*mminfo,
51-
Oideqop,Oidsortop,boolnulls_first);
51+
Oideqop,Oidsortop,boolreverse_sort,
52+
boolnulls_first);
5253
staticvoidminmax_qp_callback(PlannerInfo*root,void*extra);
5354
staticOidfetch_agg_sort_op(Oidaggfnoid);
5455

@@ -172,9 +173,9 @@ preprocess_minmax_aggregates(PlannerInfo *root)
172173
* FIRST is more likely to be available if the operator is a
173174
* reverse-sort operator, so try that first if reverse.
174175
*/
175-
if (build_minmax_path(root,mminfo,eqop,mminfo->aggsortop,reverse))
176+
if (build_minmax_path(root,mminfo,eqop,mminfo->aggsortop,reverse,reverse))
176177
continue;
177-
if (build_minmax_path(root,mminfo,eqop,mminfo->aggsortop, !reverse))
178+
if (build_minmax_path(root,mminfo,eqop,mminfo->aggsortop,reverse,!reverse))
178179
continue;
179180

180181
/* No indexable path for this aggregate, so fail */
@@ -314,7 +315,7 @@ can_minmax_aggs(PlannerInfo *root, List **context)
314315
*/
315316
staticbool
316317
build_minmax_path(PlannerInfo*root,MinMaxAggInfo*mminfo,
317-
Oideqop,Oidsortop,boolnulls_first)
318+
Oideqop,Oidsortop,boolreverse_sort,boolnulls_first)
318319
{
319320
PlannerInfo*subroot;
320321
Query*parse;
@@ -399,6 +400,7 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo,
399400
sortcl->tleSortGroupRef=assignSortGroupRef(tle,subroot->processed_tlist);
400401
sortcl->eqop=eqop;
401402
sortcl->sortop=sortop;
403+
sortcl->reverse_sort=reverse_sort;
402404
sortcl->nulls_first=nulls_first;
403405
sortcl->hashable= false;/* no need to make this accurate */
404406
parse->sortClause=list_make1(sortcl);

‎src/backend/parser/analyze.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,7 @@ makeSortGroupClauseForSetOp(Oid rescoltype, bool require_hash)
19851985
grpcl->tleSortGroupRef = 0;
19861986
grpcl->eqop = eqop;
19871987
grpcl->sortop = sortop;
1988+
grpcl->reverse_sort = false;/* Sort-op is "less than", or InvalidOid */
19881989
grpcl->nulls_first = false; /* OK with or without sortop */
19891990
grpcl->hashable = hashable;
19901991

‎src/backend/parser/parse_clause.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2933,7 +2933,7 @@ transformWindowDefinitions(ParseState *pstate,
29332933
sortcl->sortop);
29342934
/* Record properties of sort ordering */
29352935
wc->inRangeColl = exprCollation(sortkey);
2936-
wc->inRangeAsc =(rangestrategy == BTLessStrategyNumber);
2936+
wc->inRangeAsc =!sortcl->reverse_sort;
29372937
wc->inRangeNullsFirst = sortcl->nulls_first;
29382938
}
29392939

@@ -3489,6 +3489,7 @@ addTargetToSortList(ParseState *pstate, TargetEntry *tle,
34893489
sortcl->eqop = eqop;
34903490
sortcl->sortop = sortop;
34913491
sortcl->hashable = hashable;
3492+
sortcl->reverse_sort = reverse;
34923493

34933494
switch (sortby->sortby_nulls)
34943495
{
@@ -3571,6 +3572,8 @@ addTargetToGroupList(ParseState *pstate, TargetEntry *tle,
35713572
grpcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist);
35723573
grpcl->eqop = eqop;
35733574
grpcl->sortop = sortop;
3575+
grpcl->reverse_sort = false;/* sortop is "less than", or
3576+
* InvalidOid */
35743577
grpcl->nulls_first = false; /* OK with or without sortop */
35753578
grpcl->hashable = hashable;
35763579

‎src/backend/utils/cache/lsyscache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ get_equality_op_for_ordering_op(Oid opno, bool *reverse)
289289

290290
/*
291291
* get_ordering_op_for_equality_op
292-
*Get the OID of a datatype-specific btree ordering operator
292+
*Get the OID of a datatype-specific btree"less than"ordering operator
293293
*associated with an equality operator. (If there are multiple
294294
*possibilities, assume any one will do.)
295295
*

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/*yyyymmddN */
60-
#define CATALOG_VERSION_NO202410114
60+
#define CATALOG_VERSION_NO202410141
6161

6262
#endif

‎src/include/nodes/parsenodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ typedef struct SortGroupClause
14381438
IndextleSortGroupRef;/* reference into targetlist */
14391439
Oideqop;/* the equality operator ('=' op) */
14401440
Oidsortop;/* the ordering operator ('<' op), or 0 */
1441+
boolreverse_sort;/* is sortop a "greater than" operator? */
14411442
boolnulls_first;/* do NULLs come before normal values? */
14421443
/* can eqop be implemented by hashing? */
14431444
boolhashable pg_node_attr(query_jumble_ignore);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp