From 826ee1a019127d611bb0fd22ca878142bfb077ac Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Mon, 13 Apr 2020 19:26:41 -0700 Subject: [PATCH] Make _bt_insertonpg() more like _bt_split(). It seems like a good idea for nbtree's retail insert code to be absolutely consistent with nbtree's page split code for anything that naturally requires equivalent handling. Anything that concerns inserting newitem (which is handled as part of the page split atomic action when a page split is required) should work in exactly the same way. With that in mind, make _bt_insertonpg() handle 'cbuf' in a way that matches _bt_split(). --- src/backend/access/nbtree/nbtinsert.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index fd518d3ea5..4fa2e85877 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -1266,8 +1266,11 @@ _bt_insertonpg(Relation rel, MarkBufferDirty(metabuf); } - /* clear INCOMPLETE_SPLIT flag on child if inserting a downlink */ - if (BufferIsValid(cbuf)) + /* + * Clear INCOMPLETE_SPLIT flag on child if inserting the new item + * finishes a split + */ + if (!isleaf) { Page cpage = BufferGetPage(cbuf); BTPageOpaque cpageop = (BTPageOpaque) PageGetSpecialPointer(cpage); @@ -1305,13 +1308,9 @@ _bt_insertonpg(Relation rel, } else { - /* - * Register the left child whose INCOMPLETE_SPLIT flag was - * cleared. - */ - XLogRegisterBuffer(1, cbuf, REGBUF_STANDARD); - + /* Internal page insert, which finishes a split on cbuf */ xlinfo = XLOG_BTREE_INSERT_UPPER; + XLogRegisterBuffer(1, cbuf, REGBUF_STANDARD); } if (BufferIsValid(metabuf)) @@ -1360,7 +1359,7 @@ _bt_insertonpg(Relation rel, if (BufferIsValid(metabuf)) PageSetLSN(metapg, recptr); - if (BufferIsValid(cbuf)) + if (!isleaf) PageSetLSN(BufferGetPage(cbuf), recptr); PageSetLSN(page, recptr); @@ -1371,7 +1370,7 @@ _bt_insertonpg(Relation rel, /* Release subsidiary buffers */ if (BufferIsValid(metabuf)) _bt_relbuf(rel, metabuf); - if (BufferIsValid(cbuf)) + if (!isleaf) _bt_relbuf(rel, cbuf); /* @@ -1928,7 +1927,7 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf, /* * Clear INCOMPLETE_SPLIT flag on child if inserting the new item finishes - * a split. + * a split */ if (!isleaf) {