From ea5fe022a4cb0319e246aaf7794f61f16144cef7 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Fri, 9 Jul 2021 13:24:27 +0300 Subject: [PATCH] Be more explicit when doing ordered scan on columnar cat. tables (#5026) systable_getnext already uses ForwardScanDirection if relation has any open indexes, but let's be more explicit doing ordered scan on columnar catalog tables. --- src/backend/columnar/columnar_metadata.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/backend/columnar/columnar_metadata.c b/src/backend/columnar/columnar_metadata.c index c87ccd8fb..1150dc1ac 100644 --- a/src/backend/columnar/columnar_metadata.c +++ b/src/backend/columnar/columnar_metadata.c @@ -270,7 +270,7 @@ WriteColumnarOptions(Oid regclass, ColumnarOptions *options, bool overwrite) SysScanDesc scanDescriptor = systable_beginscan_ordered(columnarOptions, index, NULL, 1, scanKey); - HeapTuple heapTuple = systable_getnext(scanDescriptor); + HeapTuple heapTuple = systable_getnext_ordered(scanDescriptor, ForwardScanDirection); if (HeapTupleIsValid(heapTuple)) { if (overwrite) @@ -340,7 +340,7 @@ DeleteColumnarTableOptions(Oid regclass, bool missingOk) SysScanDesc scanDescriptor = systable_beginscan_ordered(columnarOptions, index, NULL, 1, scanKey); - HeapTuple heapTuple = systable_getnext(scanDescriptor); + HeapTuple heapTuple = systable_getnext_ordered(scanDescriptor, ForwardScanDirection); if (HeapTupleIsValid(heapTuple)) { CatalogTupleDelete(columnarOptions, &heapTuple->t_self); @@ -393,7 +393,7 @@ ReadColumnarOptions(Oid regclass, ColumnarOptions *options) SysScanDesc scanDescriptor = systable_beginscan_ordered(columnarOptions, index, NULL, 1, scanKey); - HeapTuple heapTuple = systable_getnext(scanDescriptor); + HeapTuple heapTuple = systable_getnext_ordered(scanDescriptor, ForwardScanDirection); if (HeapTupleIsValid(heapTuple)) { Form_columnar_options tupOptions = (Form_columnar_options) GETSTRUCT(heapTuple); @@ -563,7 +563,8 @@ ReadStripeSkipList(RelFileNode relfilenode, uint64 stripe, TupleDesc tupleDescri palloc0(chunkCount * sizeof(ColumnChunkSkipNode)); } - while (HeapTupleIsValid(heapTuple = systable_getnext(scanDescriptor))) + while (HeapTupleIsValid(heapTuple = systable_getnext_ordered(scanDescriptor, + ForwardScanDirection))) { Datum datumArray[Natts_columnar_chunk]; bool isNullArray[Natts_columnar_chunk]; @@ -821,7 +822,8 @@ ReadChunkGroupRowCounts(uint64 storageId, uint64 stripe, uint32 chunkGroupCount) HeapTuple heapTuple = NULL; uint32 *chunkGroupRowCounts = palloc0(chunkGroupCount * sizeof(uint32)); - while (HeapTupleIsValid(heapTuple = systable_getnext(scanDescriptor))) + while (HeapTupleIsValid(heapTuple = systable_getnext_ordered(scanDescriptor, + ForwardScanDirection))) { Datum datumArray[Natts_columnar_chunkgroup]; bool isNullArray[Natts_columnar_chunkgroup]; @@ -1013,7 +1015,8 @@ ReadDataFileStripeList(uint64 storageId, Snapshot snapshot) snapshot, 1, scanKey); - while (HeapTupleIsValid(heapTuple = systable_getnext(scanDescriptor))) + while (HeapTupleIsValid(heapTuple = systable_getnext_ordered(scanDescriptor, + ForwardScanDirection))) { Datum datumArray[Natts_columnar_stripe]; bool isNullArray[Natts_columnar_stripe]; @@ -1117,11 +1120,11 @@ DeleteStorageFromColumnarMetadataTable(Oid metadataTableId, ModifyState *modifyState = StartModifyRelation(metadataTable); - HeapTuple heapTuple = systable_getnext(scanDescriptor); - while (HeapTupleIsValid(heapTuple)) + HeapTuple heapTuple; + while (HeapTupleIsValid(heapTuple = systable_getnext_ordered(scanDescriptor, + ForwardScanDirection))) { DeleteTupleAndEnforceConstraints(modifyState, heapTuple); - heapTuple = systable_getnext(scanDescriptor); } systable_endscan_ordered(scanDescriptor);