Skip to content

Commit 80634e3

Browse files
Rearrange _bt_insertonpg() "update metapage" code.
Nest the "update metapage as part of insert into root-like page" branch inside the broader "insert into internal page" branch. This improves readability.
1 parent 8128b0c commit 80634e3

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/backend/access/nbtree/nbtinsert.c

+23-19
Original file line numberDiff line numberDiff line change
@@ -1306,38 +1306,42 @@ _bt_insertonpg(Relation rel,
13061306
* Leaf insert with posting list split. Must include
13071307
* postingoff field before newitem/orignewitem.
13081308
*/
1309+
Assert(isleaf);
13091310
xlinfo = XLOG_BTREE_INSERT_POST;
13101311
}
13111312
else
13121313
{
13131314
/* Internal page insert, which finishes a split on cbuf */
13141315
xlinfo = XLOG_BTREE_INSERT_UPPER;
13151316
XLogRegisterBuffer(1, cbuf, REGBUF_STANDARD);
1316-
}
13171317

1318-
if (BufferIsValid(metabuf))
1319-
{
1320-
Assert(metad->btm_version >= BTREE_NOVAC_VERSION);
1321-
xlmeta.version = metad->btm_version;
1322-
xlmeta.root = metad->btm_root;
1323-
xlmeta.level = metad->btm_level;
1324-
xlmeta.fastroot = metad->btm_fastroot;
1325-
xlmeta.fastlevel = metad->btm_fastlevel;
1326-
xlmeta.oldest_btpo_xact = metad->btm_oldest_btpo_xact;
1327-
xlmeta.last_cleanup_num_heap_tuples =
1328-
metad->btm_last_cleanup_num_heap_tuples;
1329-
xlmeta.allequalimage = metad->btm_allequalimage;
1330-
1331-
XLogRegisterBuffer(2, metabuf, REGBUF_WILL_INIT | REGBUF_STANDARD);
1332-
XLogRegisterBufData(2, (char *) &xlmeta, sizeof(xl_btree_metadata));
1333-
1334-
xlinfo = XLOG_BTREE_INSERT_META;
1318+
if (BufferIsValid(metabuf))
1319+
{
1320+
/* Actually, it's an internal page insert + meta update */
1321+
xlinfo = XLOG_BTREE_INSERT_META;
1322+
1323+
Assert(metad->btm_version >= BTREE_NOVAC_VERSION);
1324+
xlmeta.version = metad->btm_version;
1325+
xlmeta.root = metad->btm_root;
1326+
xlmeta.level = metad->btm_level;
1327+
xlmeta.fastroot = metad->btm_fastroot;
1328+
xlmeta.fastlevel = metad->btm_fastlevel;
1329+
xlmeta.oldest_btpo_xact = metad->btm_oldest_btpo_xact;
1330+
xlmeta.last_cleanup_num_heap_tuples =
1331+
metad->btm_last_cleanup_num_heap_tuples;
1332+
xlmeta.allequalimage = metad->btm_allequalimage;
1333+
1334+
XLogRegisterBuffer(2, metabuf,
1335+
REGBUF_WILL_INIT | REGBUF_STANDARD);
1336+
XLogRegisterBufData(2, (char *) &xlmeta,
1337+
sizeof(xl_btree_metadata));
1338+
}
13351339
}
13361340

13371341
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
13381342
if (postingoff == 0)
13391343
{
1340-
/* Simple, common case -- log itup from caller */
1344+
/* Just log itup from caller */
13411345
XLogRegisterBufData(0, (char *) itup, IndexTupleSize(itup));
13421346
}
13431347
else

0 commit comments

Comments
 (0)