diff --git a/src/common/backend/catalog/index.cpp b/src/common/backend/catalog/index.cpp index e14d9887b..41a8c6ac0 100644 --- a/src/common/backend/catalog/index.cpp +++ b/src/common/backend/catalog/index.cpp @@ -3816,7 +3816,7 @@ static TransactionId GetCatalogOldestXmin(Relation heapRelation) * chain tip. */ double IndexBuildHeapScan(Relation heapRelation, Relation indexRelation, IndexInfo* indexInfo, bool allow_sync, - IndexBuildCallback callback, void* callbackState, TableScanDesc scan) + IndexBuildCallback callback, void* callbackState, TableScanDesc scan, BlockNumber startBlkno, BlockNumber numblocks) { bool is_system_catalog = false; bool checking_uniqueness = false; @@ -3904,6 +3904,22 @@ double IndexBuildHeapScan(Relation heapRelation, Relation indexRelation, IndexIn snapshot = SnapshotAny; OldestXmin = GetOldestXmin(heapRelation); } + + /* set our scan endpoints */ + if (!allow_sync && BlockNumberIsValid(numblocks)) { + Assert(!scan->rs_inited); + Assert(!(scan->rs_flags & SO_ALLOW_SYNC)); + Assert(startBlkno == 0 || startBlkno < scan->rs_nblocks); + + scan->rs_rangeScanInRedis.isRangeScanInRedis = true; + scan->rs_startblock = startBlkno; + scan->rs_nblocks = numblocks; + } else { + /* synscan can only be requested on whole relation */ + Assert(startBlkno == 0); + Assert(numblocks == InvalidBlockNumber); + } + reltuples = 0; /* diff --git a/src/gausskernel/storage/access/table/tableam.cpp b/src/gausskernel/storage/access/table/tableam.cpp index 25b54e8c4..1af1bb152 100644 --- a/src/gausskernel/storage/access/table/tableam.cpp +++ b/src/gausskernel/storage/access/table/tableam.cpp @@ -378,9 +378,11 @@ void HeapamScanInitParallelSeqscan(TableScanDesc sscan, int32 dop, ScanDirection } double HeapamIndexBuildScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool allow_sync, - IndexBuildCallback callback, void *callback_state, TableScanDesc scan) + IndexBuildCallback callback, void *callback_state, TableScanDesc scan, + BlockNumber startBlkno, BlockNumber numblocks) { - return IndexBuildHeapScan(heapRelation, indexRelation, indexInfo, allow_sync, callback, callback_state, scan); + return IndexBuildHeapScan(heapRelation, indexRelation, indexInfo, allow_sync, callback, + callback_state, scan, startBlkno, numblocks); } void HeapamIndexValidateScan (Relation heapRelation, Relation indexRelation, @@ -972,7 +974,8 @@ void UHeapamTslotStoreUHeapTuple(Tuple tuple, TupleTableSlot *slot, Buffer buffe */ double UHeapamIndexBuildScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool allowSync, - IndexBuildCallback callback, void *callback_state, TableScanDesc scan) + IndexBuildCallback callback, void *callback_state, TableScanDesc scan, + BlockNumber startBlkno, BlockNumber numblocks) { return IndexBuildUHeapScan(heapRelation, indexRelation, indexInfo, allowSync, callback, callback_state, scan); } diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index 061a610fb..cd63787dd 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -482,7 +482,8 @@ typedef struct TableAmRoutine { */ double (*index_build_scan)(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool allow_sync, - IndexBuildCallback callback, void *callback_state, TableScanDesc scan); + IndexBuildCallback callback, void *callback_state, TableScanDesc scan, + BlockNumber startBlkno, BlockNumber numblocks); void (*index_validate_scan)(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, Snapshot snapshot, v_i_state *state); @@ -993,10 +994,11 @@ static inline void tableam_scan_init_parallel_seqscan(TableScanDesc sscan, int32 } static inline double tableam_index_build_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, - bool allow_sync, IndexBuildCallback callback, void *callback_state, TableScanDesc scan) + bool allow_sync, IndexBuildCallback callback, void *callback_state, TableScanDesc scan, + BlockNumber startBlkno = 0, BlockNumber numblocks = InvalidBlockNumber) { return heapRelation->rd_tam_ops->index_build_scan(heapRelation, indexRelation, indexInfo, - allow_sync, callback, callback_state, scan); + allow_sync, callback, callback_state, scan, startBlkno, numblocks); } static inline void tableam_index_validate_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index 4e322f6f4..f50127acb 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -169,7 +169,8 @@ extern void index_build(Relation heapRelation, bool isTruncGTT = false); extern double IndexBuildHeapScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, - bool allow_sync, IndexBuildCallback callback, void *callback_state, TableScanDesc scan = NULL); + bool allow_sync, IndexBuildCallback callback, void *callback_state, TableScanDesc scan = NULL, + BlockNumber startBlkno = 0, BlockNumber numblocks = InvalidBlockNumber); extern double IndexBuildUHeapScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo,