From fb535d14e944d99819cd590612d20dab6094b6bd Mon Sep 17 00:00:00 2001 From: ab2020c Date: Fri, 26 May 2023 12:10:57 +0800 Subject: [PATCH] =?UTF-8?q?bitmapscan=E4=BC=98=E5=8C=96=201.bitmapand?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=80=89=E6=8B=A9=E6=97=B6=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=B4=A2=E5=BC=95=E6=89=AB=E6=8F=8F=E4=BB=A3?= =?UTF-8?q?=E4=BB=B7=E8=BF=9B=E8=A1=8C=E6=8E=92=E5=BA=8F=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=202.BitmapHeapPrefetchNext=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/optimizer/path/indxpath.cpp | 4 +- .../runtime/executor/nodeBitmapHeapscan.cpp | 86 +++++++++++-------- src/test/regress/expected/gpi_bitmapscan.out | 8 +- 3 files changed, 57 insertions(+), 41 deletions(-) diff --git a/src/gausskernel/optimizer/path/indxpath.cpp b/src/gausskernel/optimizer/path/indxpath.cpp index d166164d3..4cf54ba0a 100755 --- a/src/gausskernel/optimizer/path/indxpath.cpp +++ b/src/gausskernel/optimizer/path/indxpath.cpp @@ -1664,9 +1664,7 @@ static Path* choose_bitmap_and(PlannerInfo* root, RelOptInfo* rel, List* paths, return pathinfoarray[0]->path; /* Sort the surviving paths by index access cost */ - if (globalPartPaths > 1) { - qsort(pathinfoarray, npaths, sizeof(PathClauseUsage*), path_usage_comparator); - } + qsort(pathinfoarray, npaths, sizeof(PathClauseUsage*), path_usage_comparator); /* * For each surviving index, consider it as an "AND group leader", and see * whether adding on any of the later indexes results in an AND path with diff --git a/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp b/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp index e8c47498f..d0df2e7df 100644 --- a/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp +++ b/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp @@ -1304,49 +1304,67 @@ void BitmapHeapPrefetchNext( ADIO_ELSE() { /* prefetch next synchronously */ - HBktTblScanDesc hpscan = NULL; - Oid oldOid = GPIGetCurrPartOid(node->gpi_scan); - int2 oldBktId = cbi_get_current_bucketid(node->cbi_scan); - Relation oldheap = NULL; - - while (node->prefetch_pages < node->prefetch_target) { - TBMIterateResult* tbmpre = tbm_iterate(*prefetch_iterator); - Relation prefetchRel = scan->rs_rd; - hpscan = (tbm_is_crossbucket(node->tbm) ? (HBktTblScanDesc)node->ss.ss_currentScanDesc : NULL); + if (unlikely(tbm_is_crossbucket(tbm) || tbm_is_global(tbm))) { + HBktTblScanDesc hpscan = NULL; + Oid oldOid = GPIGetCurrPartOid(node->gpi_scan); + int2 oldBktId = cbi_get_current_bucketid(node->cbi_scan); + Relation oldheap = NULL; + + while (node->prefetch_pages < node->prefetch_target) { + TBMIterateResult* tbmpre = tbm_iterate(*prefetch_iterator); + Relation prefetchRel = scan->rs_rd; + hpscan = (tbm_is_crossbucket(node->tbm) ? (HBktTblScanDesc)node->ss.ss_currentScanDesc : NULL); - if (tbmpre == NULL) { - /* No more pages to prefetch */ - tbm_end_iterate(*prefetch_iterator); - node->prefetch_iterator = *prefetch_iterator = NULL; - break; - } - node->prefetch_pages++; + if (tbmpre == NULL) { + /* No more pages to prefetch */ + tbm_end_iterate(*prefetch_iterator); + node->prefetch_iterator = *prefetch_iterator = NULL; + break; + } + node->prefetch_pages++; - prefetchRel = BitmapHeapPrefetchNextTargetHeap(node, tbmpre, prefetchRel); - if (prefetchRel == NULL) { - tbmpre = NULL; - continue; + prefetchRel = BitmapHeapPrefetchNextTargetHeap(node, tbmpre, prefetchRel); + if (prefetchRel == NULL) { + tbmpre = NULL; + continue; + } + + /* For posix_fadvise() we just send the one request */ + PrefetchBuffer(prefetchRel, MAIN_FORKNUM, tbmpre->blockno); + if (RelationIsValid(oldheap) && oldheap != prefetchRel && PointerIsValid(hpscan) && + oldheap != hpscan->currBktRel) { + /* release previous bucket fake relation except the current scanning one */ + bucketCloseRelation(oldheap); + /* now oldheap is NULL */ + } + oldheap = prefetchRel; } - /* For posix_fadvise() we just send the one request */ - PrefetchBuffer(prefetchRel, MAIN_FORKNUM, tbmpre->blockno); - if (RelationIsValid(oldheap) && oldheap != prefetchRel && PointerIsValid(hpscan) && - oldheap != hpscan->currBktRel) { + if (RelationIsValid(oldheap) && PointerIsValid(hpscan) && oldheap != hpscan->currBktRel) { /* release previous bucket fake relation except the current scanning one */ bucketCloseRelation(oldheap); - /* now oldheap is NULL */ } - oldheap = prefetchRel; - } - if (RelationIsValid(oldheap) && PointerIsValid(hpscan) && oldheap != hpscan->currBktRel) { - /* release previous bucket fake relation except the current scanning one */ - bucketCloseRelation(oldheap); - } + /* recover old oid after prefetch switch */ + GPISetCurrPartOid(node->gpi_scan, oldOid); + cbi_set_bucketid(node->cbi_scan, oldBktId); + } else { + while (node->prefetch_pages < node->prefetch_target) { + TBMIterateResult* tbmpre = tbm_iterate(*prefetch_iterator); + Relation prefetchRel = scan->rs_rd; - /* recover old oid after prefetch switch */ - GPISetCurrPartOid(node->gpi_scan, oldOid); - cbi_set_bucketid(node->cbi_scan, oldBktId); + if (tbmpre == NULL) { + /* No more pages to prefetch */ + tbm_end_iterate(*prefetch_iterator); + node->prefetch_iterator = *prefetch_iterator = NULL; + break; + } + node->prefetch_pages++; + + /* For posix_fadvise() we just send the one request */ + PrefetchBuffer(prefetchRel, MAIN_FORKNUM, tbmpre->blockno); + } + } } ADIO_END(); } diff --git a/src/test/regress/expected/gpi_bitmapscan.out b/src/test/regress/expected/gpi_bitmapscan.out index 661ee901b..0dee3501a 100644 --- a/src/test/regress/expected/gpi_bitmapscan.out +++ b/src/test/regress/expected/gpi_bitmapscan.out @@ -294,15 +294,15 @@ explain (costs off) SELECT keyword FROM test_part_bitmapand_ginst_btree WHERE ke QUERY PLAN ------------------------------------------------------------------------------------ Partitioned Bitmap Heap Scan on test_part_bitmapand_ginst_btree - Recheck Cond: ((a = 10) AND (keyword @> '''new'''::tsquery)) + Recheck Cond: ((keyword @> '''new'''::tsquery) AND (a = 10)) Selected Partitions: 1 -> BitmapAnd - -> Partitioned Bitmap Index Scan on test_part_bitmapand_ginst_btree_a_idx - Index Cond: (a = 10) - Selected Partitions: 1 -> Partitioned Bitmap Index Scan on qq Index Cond: (keyword @> '''new'''::tsquery) Selected Partitions: 1 + -> Partitioned Bitmap Index Scan on test_part_bitmapand_ginst_btree_a_idx + Index Cond: (a = 10) + Selected Partitions: 1 (10 rows) SELECT keyword FROM test_part_bitmapand_ginst_btree WHERE keyword @> 'new' and a = 10;