public inbox for [email protected]help / color / mirror / Atom feed
[PATCH 8/8] Consider selectivity in choose_bitmap_and 2+ messages / 2 participants [nested] [flat]
* [PATCH 8/8] Consider selectivity in choose_bitmap_and @ 2021-03-11 11:57 Tomas Vondra <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Tomas Vondra @ 2021-03-11 11:57 UTC (permalink / raw) --- src/backend/optimizer/path/indxpath.c | 38 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index ff536e6b24..36b29c6c7b 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -1437,6 +1437,7 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths) foreach(l, paths) { Path *ipath = (Path *) lfirst(l); + bool duplicate = false; pathinfo = classify_index_clause_usage(ipath, &clauselist); @@ -1451,22 +1452,29 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths) { if (!pathinfoarray[i]->unclassifiable && bms_equal(pathinfo->clauseids, pathinfoarray[i]->clauseids)) - break; - } - if (i < npaths) - { - /* duplicate clauseids, keep the cheaper one */ - Cost ncost; - Cost ocost; - Selectivity nselec; - Selectivity oselec; - - cost_bitmap_tree_node(pathinfo->path, &ncost, &nselec); - cost_bitmap_tree_node(pathinfoarray[i]->path, &ocost, &oselec); - if (ncost < ocost) - pathinfoarray[i] = pathinfo; + { + /* duplicate clauseids, keep the cheaper one + * + * XXX maybe this should just use path_usage_comparator? + */ + Cost ncost; + Cost ocost; + Selectivity nselec; + Selectivity oselec; + + cost_bitmap_tree_node(pathinfo->path, &ncost, &nselec); + cost_bitmap_tree_node(pathinfoarray[i]->path, &ocost, &oselec); + + if ((ncost < ocost) && (nselec < oselec)) + { + pathinfoarray[i] = pathinfo; + duplicate = true; + break; + } + } } - else + + if (!duplicate) { /* not duplicate clauseids, add to array */ pathinfoarray[npaths++] = pathinfo; -- 2.26.2 --------------D524CD37E77B36A2883A7617 Content-Type: application/sql; name="reproduce2.sql" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="reproduce2.sql" ZHJvcCB0YWJsZSBpZiBleGlzdHMgdDsKCnNldCBtYXhfcGFyYWxsZWxfd29ya2Vyc19wZXJf Z2F0aGVyID0gMDsKCmNyZWF0ZSB0YWJsZSB0KGEgYmlnaW50KSB3aXRoIChmaWxsZmFjdG9y ID0gMjUpOwoKaW5zZXJ0IGludG8gdCBzZWxlY3QgaSBmcm9tIGdlbmVyYXRlX3Nlcmllcygx LDEwMDAwMDAwKSBzKGkpOwoKY3JlYXRlIGluZGV4IGlkeF8xIG9uIHQgdXNpbmcgYnJpbiAo YSkgd2l0aCAocGFnZXNfcGVyX3JhbmdlID0gNCk7CgpjcmVhdGUgaW5kZXggaWR4XzIgb24g dCB1c2luZyBicmluIChhKTsKCmFuYWx5emUgdDsKClxkKwpcZGkrCgpleHBsYWluIGFuYWx5 emUgc2VsZWN0ICogZnJvbSB0IHdoZXJlIGEgPSAxMDAwOwoKZHJvcCBpbmRleCBpZHhfMjsK CmV4cGxhaW4gYW5hbHl6ZSBzZWxlY3QgKiBmcm9tIHQgd2hlcmUgYSA9IDEwMDA7Cg== --------------D524CD37E77B36A2883A7617 Content-Type: application/sql; name="reproducer.sql" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="reproducer.sql" ZHJvcCB0YWJsZSBpZiBleGlzdHMgdDsKCnNldCBtYXhfcGFyYWxsZWxfd29ya2Vyc19wZXJf Z2F0aGVyID0gMDsKCmNyZWF0ZSB0YWJsZSB0IChhIGludCwgYiBiaWdpbnQsIGMgdGV4dCkg d2l0aCAoZmlsbGZhY3RvciA9IDUwKTsKCmluc2VydCBpbnRvIHQgc2VsZWN0IDEwMDAwMDAg KiByYW5kb20oKSwgMTAwMDAwMCAqIHJhbmRvbSgpLCBtZDUoKDEwMDAwMDAgKiByYW5kb20o KSk6OmludDo6dGV4dCkgZnJvbSBnZW5lcmF0ZV9zZXJpZXMoMSwxMDAwMDAwKSBzKGkpOwoK c2VsZWN0IGNvdW50KCopIGZyb20gKHNlbGVjdCBkaXN0aW5jdCBiIGZyb20gdCB3aGVyZSBj dGlkIDwgJygxMjgsMCknOjp0aWQpIGZvbzsKCmNyZWF0ZSBpbmRleCBibG9vbV9hX2lkeCBv biB0IHVzaW5nIGJyaW4gKGEgaW50NF9ibG9vbV9vcHMobl9kaXN0aW5jdF9wZXJfcmFuZ2U9 NjAwMCkpOyAKCmFuYWx5emUgdDsKCmV4cGxhaW4gc2VsZWN0ICogZnJvbSB0IHdoZXJlIGEg PSAxMDAwOwoKY3JlYXRlIGluZGV4IGJyaW5faWR4IG9uIHQgdXNpbmcgYnJpbiAoYSk7CmFu YWx5emUgdDsKCmV4cGxhaW4gc2VsZWN0ICogZnJvbSB0IHdoZXJlIGEgPSAxMDAwOwoKZHJv cCBpbmRleCBicmluX2lkeDsKCmV4cGxhaW4gc2VsZWN0ICogZnJvbSB0IHdoZXJlIGEgPSAx MDAwOwo= --------------D524CD37E77B36A2883A7617-- ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Release and unpin buffers after leaving CRIT section in GIN. @ 2026-02-17 10:14 Kirill Reshke <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Kirill Reshke @ 2026-02-17 10:14 UTC (permalink / raw) To: Michael Paquier <[email protected]>; +Cc: pgsql-hackers On Tue, 17 Feb 2026 at 15:07, Michael Paquier <[email protected]> wrote: > > On Tue, Feb 17, 2026 at 02:58:24PM +0500, Kirill Reshke wrote: > > Few places in GIN code does not follow that. v1 fixes it. > > Yep. That sounds pretty much right. Thanks for the report. > -- > Michael Looks like there are two more instances of this on HEAD: in gistbuild and log_newpage_range. Is it? ``` reshke@yezzey-cbdb-bench:~/cpg$ git diff src/backend/access/gist/gistbuild.c src/backend/access/transam/xloginsert.c diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c index 7f57c787f4c..8e0c083ffa7 100644 --- a/src/backend/access/gist/gistbuild.c +++ b/src/backend/access/gist/gistbuild.c @@ -305,10 +305,10 @@ gistbuild(Relation heap, Relation index, IndexInfo *indexInfo) MarkBufferDirty(buffer); PageSetLSN(page, GistBuildLSN); - UnlockReleaseBuffer(buffer); - END_CRIT_SECTION(); + UnlockReleaseBuffer(buffer); + /* Scan the table, inserting all the tuples to the index. */ reltuples = table_index_build_scan(heap, index, indexInfo, true, true, gistBuildCallback, diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index d3acaa636c3..a9a1678acc9 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -1355,11 +1355,12 @@ log_newpage_range(Relation rel, ForkNumber forknum, recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI); for (i = 0; i < nbufs; i++) - { PageSetLSN(BufferGetPage(bufpack[i]), recptr); - UnlockReleaseBuffer(bufpack[i]); - } + END_CRIT_SECTION(); + + for (i = 0; i < nbufs; i++) + UnlockReleaseBuffer(bufpack[i]); } } ``` -- Best regards, Kirill Reshke ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-02-17 10:14 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-03-11 11:57 [PATCH 8/8] Consider selectivity in choose_bitmap_and Tomas Vondra <[email protected]> 2026-02-17 10:14 Re: Release and unpin buffers after leaving CRIT section in GIN. Kirill Reshke <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox