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

Commita359d37

Browse files
peteremarkdilger
andcommitted
Simplify and generalize PrepareSortSupportFromIndexRel()
PrepareSortSupportFromIndexRel() was accepting btree strategy numberspurely for the purpose of comparing it later against btree strategiesto determine if the sort direction was forward or reverse. Changethat. Instead, pass a bool directly, to indicate the same without anunfortunate assumption that a strategy number refers specifically to abtree strategy. (This is similar in spirit to commits0d2aa4d andc594f1a.)(This could arguably be simplfied further by having the callers fillin ssup_reverse directly. But this way, it preserves consistency byhaving all PrepareSortSupport*() variants be responsible for fillingin ssup_reverse.)Moreover, remove the hardcoded check against BTREE_AM_OID, and checkagainst amcanorder instead, which is the actual requirement.Co-authored-by: Mark Dilger <mark.dilger@enterprisedb.com>Discussion:https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
1 parent1548c3a commita359d37

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
11711171
{
11721172
SortSupportsortKey=sortKeys+i;
11731173
ScanKeyscanKey=wstate->inskey->scankeys+i;
1174-
int16strategy;
1174+
boolreverse;
11751175

11761176
sortKey->ssup_cxt=CurrentMemoryContext;
11771177
sortKey->ssup_collation=scanKey->sk_collation;
@@ -1183,10 +1183,9 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
11831183

11841184
Assert(sortKey->ssup_attno!=0);
11851185

1186-
strategy= (scanKey->sk_flags&SK_BT_DESC)!=0 ?
1187-
BTGreaterStrategyNumber :BTLessStrategyNumber;
1186+
reverse= (scanKey->sk_flags&SK_BT_DESC)!=0;
11881187

1189-
PrepareSortSupportFromIndexRel(wstate->index,strategy,sortKey);
1188+
PrepareSortSupportFromIndexRel(wstate->index,reverse,sortKey);
11901189
}
11911190

11921191
for (;;)

‎src/backend/utils/sort/sortsupport.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,25 @@ PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
150150
}
151151

152152
/*
153-
* Fill in SortSupport given an index relation, attribute,andstrategy.
153+
* Fill in SortSupport given an index relationandattribute.
154154
*
155155
* Caller must previously have zeroed the SortSupportData structure and then
156156
* filled in ssup_cxt, ssup_attno, ssup_collation, and ssup_nulls_first. This
157-
* will fill in ssup_reverse (based on the suppliedstrategy), as well as the
157+
* will fill in ssup_reverse (based on the suppliedargument), as well as the
158158
* comparator function pointer.
159159
*/
160160
void
161-
PrepareSortSupportFromIndexRel(RelationindexRel,int16strategy,
161+
PrepareSortSupportFromIndexRel(RelationindexRel,boolreverse,
162162
SortSupportssup)
163163
{
164164
Oidopfamily=indexRel->rd_opfamily[ssup->ssup_attno-1];
165165
Oidopcintype=indexRel->rd_opcintype[ssup->ssup_attno-1];
166166

167167
Assert(ssup->comparator==NULL);
168168

169-
if (indexRel->rd_rel->relam!=BTREE_AM_OID)
170-
elog(ERROR,"unexpected non-btree AM: %u",indexRel->rd_rel->relam);
171-
if (strategy!=BTGreaterStrategyNumber&&
172-
strategy!=BTLessStrategyNumber)
173-
elog(ERROR,"unexpected sort support strategy: %d",strategy);
174-
ssup->ssup_reverse= (strategy==BTGreaterStrategyNumber);
169+
if (!indexRel->rd_indam->amcanorder)
170+
elog(ERROR,"unexpected non-amcanorder AM: %u",indexRel->rd_rel->relam);
171+
ssup->ssup_reverse=reverse;
175172

176173
FinishSortSupportFunction(opfamily,opcintype,ssup);
177174
}

‎src/backend/utils/sort/tuplesortvariants.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ tuplesort_begin_cluster(TupleDesc tupDesc,
329329
{
330330
SortSupportsortKey=base->sortKeys+i;
331331
ScanKeyscanKey=indexScanKey->scankeys+i;
332-
int16strategy;
332+
boolreverse;
333333

334334
sortKey->ssup_cxt=CurrentMemoryContext;
335335
sortKey->ssup_collation=scanKey->sk_collation;
@@ -341,10 +341,9 @@ tuplesort_begin_cluster(TupleDesc tupDesc,
341341

342342
Assert(sortKey->ssup_attno!=0);
343343

344-
strategy= (scanKey->sk_flags&SK_BT_DESC)!=0 ?
345-
BTGreaterStrategyNumber :BTLessStrategyNumber;
344+
reverse= (scanKey->sk_flags&SK_BT_DESC)!=0;
346345

347-
PrepareSortSupportFromIndexRel(indexRel,strategy,sortKey);
346+
PrepareSortSupportFromIndexRel(indexRel,reverse,sortKey);
348347
}
349348

350349
pfree(indexScanKey);
@@ -412,7 +411,7 @@ tuplesort_begin_index_btree(Relation heapRel,
412411
{
413412
SortSupportsortKey=base->sortKeys+i;
414413
ScanKeyscanKey=indexScanKey->scankeys+i;
415-
int16strategy;
414+
boolreverse;
416415

417416
sortKey->ssup_cxt=CurrentMemoryContext;
418417
sortKey->ssup_collation=scanKey->sk_collation;
@@ -424,10 +423,9 @@ tuplesort_begin_index_btree(Relation heapRel,
424423

425424
Assert(sortKey->ssup_attno!=0);
426425

427-
strategy= (scanKey->sk_flags&SK_BT_DESC)!=0 ?
428-
BTGreaterStrategyNumber :BTLessStrategyNumber;
426+
reverse= (scanKey->sk_flags&SK_BT_DESC)!=0;
429427

430-
PrepareSortSupportFromIndexRel(indexRel,strategy,sortKey);
428+
PrepareSortSupportFromIndexRel(indexRel,reverse,sortKey);
431429
}
432430

433431
pfree(indexScanKey);

‎src/include/utils/sortsupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ extern intssup_datum_int32_cmp(Datum x, Datum y, SortSupport ssup);
384384
/* Other functions in utils/sort/sortsupport.c */
385385
externvoidPrepareSortSupportComparisonShim(OidcmpFunc,SortSupportssup);
386386
externvoidPrepareSortSupportFromOrderingOp(OidorderingOp,SortSupportssup);
387-
externvoidPrepareSortSupportFromIndexRel(RelationindexRel,int16strategy,
387+
externvoidPrepareSortSupportFromIndexRel(RelationindexRel,boolreverse,
388388
SortSupportssup);
389389
externvoidPrepareSortSupportFromGistIndexRel(RelationindexRel,SortSupportssup);
390390

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp