summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorMasahiko Sawada2025-11-17 21:22:20 +0000
committerMasahiko Sawada2025-11-17 21:22:20 +0000
commita6eac2273e6e762003e763f45b880261fbd473a4 (patch)
tree80c6858b89ca359da05de3377a9a8732595a9617 /src/backend
parent6d969ca687b4b2d4387d318c3fbcf3fc606ea55b (diff)
Use streaming read I/O in BRIN vacuum scan.HEADmaster
This commit implements streaming read I/O for BRIN vacuum scans. Although BRIN indexes tend to be relatively small by design, performance tests have shown performance improvements. Author: Arseniy Mukhin <[email protected]> Discussion: https://postgr.es/m/CAE7r3ML01aiq9Th_1OSz7U7Aq2pWbhMLoz5T%2BPXcg8J9ZAPFFA%40mail.gmail.com
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/access/brin/brin.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 2f7d1437919..cb3331921cb 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -2171,28 +2171,42 @@ union_tuples(BrinDesc *bdesc, BrinMemTuple *a, BrinTuple *b)
static void
brin_vacuum_scan(Relation idxrel, BufferAccessStrategy strategy)
{
- BlockNumber nblocks;
- BlockNumber blkno;
+ BlockRangeReadStreamPrivate p;
+ ReadStream *stream;
+ Buffer buf;
+
+ p.current_blocknum = 0;
+ p.last_exclusive = RelationGetNumberOfBlocks(idxrel);
+
+ /*
+ * It is safe to use batchmode as block_range_read_stream_cb takes no
+ * locks.
+ */
+ stream = read_stream_begin_relation(READ_STREAM_MAINTENANCE |
+ READ_STREAM_FULL |
+ READ_STREAM_USE_BATCHING,
+ strategy,
+ idxrel,
+ MAIN_FORKNUM,
+ block_range_read_stream_cb,
+ &p,
+ 0);
/*
* Scan the index in physical order, and clean up any possible mess in
* each page.
*/
- nblocks = RelationGetNumberOfBlocks(idxrel);
- for (blkno = 0; blkno < nblocks; blkno++)
+ while ((buf = read_stream_next_buffer(stream, NULL)) != InvalidBuffer)
{
- Buffer buf;
-
CHECK_FOR_INTERRUPTS();
- buf = ReadBufferExtended(idxrel, MAIN_FORKNUM, blkno,
- RBM_NORMAL, strategy);
-
brin_page_cleanup(idxrel, buf);
ReleaseBuffer(buf);
}
+ read_stream_end(stream);
+
/*
* Update all upper pages in the index's FSM, as well. This ensures not
* only that we propagate leaf-page FSM updates made by brin_page_cleanup,