aboutsummaryrefslogtreecommitdiff
path: root/contrib/bloom/blutils.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2023-08-23 17:21:31 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2023-08-23 17:21:31 +0300
commitccadf73163ca88bdaa74b8223d4dde05d17f550b (patch)
treec62a538b03de3b3e07ed2f904f142e2e4ba7b18d /contrib/bloom/blutils.c
parentee99330a0b39c47a7ac44c6c8fdd74e3da841ba5 (diff)
downloadpostgresql-ccadf73163ca88bdaa74b8223d4dde05d17f550b.tar.gz
postgresql-ccadf73163ca88bdaa74b8223d4dde05d17f550b.zip
Use the buffer cache when initializing an unlogged index.
Some of the ambuildempty functions used smgrwrite() directly, followed by smgrimmedsync(). A few small problems with that: Firstly, one is supposed to use smgrextend() when extending a relation, not smgrwrite(). It doesn't make much difference in production builds. smgrextend() updates the relation size cache, so you miss that, but that's harmless because we never use the cached relation size of an init fork. But if you compile with CHECK_WRITE_VS_EXTEND, you get an assertion failure. Secondly, the smgrwrite() calls were performed before WAL-logging, so the page image written to disk had 0/0 as the LSN, not the LSN of the WAL record. That's also harmless in practice, but seems sloppy. Thirdly, it's better to use the buffer cache, because then you don't need to smgrimmedsync() the relation to disk, which adds latency. Bypassing the cache makes sense for bulk operations like index creation, but not when you're just initializing an empty index. Creation of unlogged tables is hardly performance bottleneck in any real world applications, but nevertheless. Backpatch to v16, but no further. These issues should be harmless in practice, so better to not rock the boat in older branches. Reviewed-by: Robert Haas Discussion: https://www.postgresql.org/message-id/6e5bbc08-cdfc-b2b3-9e23-1a914b9850a9@iki.fi
Diffstat (limited to 'contrib/bloom/blutils.c')
-rw-r--r--contrib/bloom/blutils.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index a017d58bbe4..f23fbb1d9e0 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -443,7 +443,7 @@ BloomFillMetapage(Relation index, Page metaPage)
* Initialize metapage for bloom index.
*/
void
-BloomInitMetapage(Relation index)
+BloomInitMetapage(Relation index, ForkNumber forknum)
{
Buffer metaBuffer;
Page metaPage;
@@ -451,9 +451,11 @@ BloomInitMetapage(Relation index)
/*
* Make a new page; since it is first page it should be associated with
- * block number 0 (BLOOM_METAPAGE_BLKNO).
+ * block number 0 (BLOOM_METAPAGE_BLKNO). No need to hold the extension
+ * lock because there cannot be concurrent inserters yet.
*/
- metaBuffer = BloomNewBuffer(index);
+ metaBuffer = ReadBufferExtended(index, forknum, P_NEW, RBM_NORMAL, NULL);
+ LockBuffer(metaBuffer, BUFFER_LOCK_EXCLUSIVE);
Assert(BufferGetBlockNumber(metaBuffer) == BLOOM_METAPAGE_BLKNO);
/* Initialize contents of meta page */