0001-WIP-Prevent-overflows-for-BRIN-page-ranges.patch
text/x-patch
Filename: 0001-WIP-Prevent-overflows-for-BRIN-page-ranges.patch
Type: text/x-patch
Part: 0
Patch
Format: format-patch
Series: patch 0001
Subject: WIP: Prevent overflows for BRIN page ranges
| File | + | − |
|---|---|---|
| src/backend/access/brin/brin.c | 15 | 2 |
From cf53c109c73cfa9264df71763e9ec5712f1c1f7f Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@2ndquadrant.com>
Date: Thu, 7 Dec 2023 15:07:04 +0100
Subject: [PATCH] WIP: Prevent overflows for BRIN page ranges
Introduces remove brin_next_range that checks if blkno overflows, and
instead sets it to InvalidBlockNumber.
---
src/backend/access/brin/brin.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 23f081389b2..1952142d050 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -227,6 +227,7 @@ static bool add_values_to_range(Relation idxRel, BrinDesc *bdesc,
static bool check_null_keys(BrinValues *bval, ScanKey *nullkeys, int nnullkeys);
static void brin_fill_empty_ranges(BrinBuildState *state,
BlockNumber prevRange, BlockNumber maxRange);
+static BlockNumber brin_next_range(BrinBuildState *state, BlockNumber blkno);
/* parallel index builds */
static void _brin_begin_parallel(BrinBuildState *buildstate, Relation heap, Relation index,
@@ -2935,7 +2936,7 @@ brin_fill_empty_ranges(BrinBuildState *state,
* If we already summarized some ranges, we need to start with the next
* one. Otherwise start from the first range of the table.
*/
- blkno = (prevRange == InvalidBlockNumber) ? 0 : (prevRange + state->bs_pagesPerRange);
+ blkno = (prevRange == InvalidBlockNumber) ? 0 : brin_next_range(state, prevRange);
/* Generate empty ranges until we hit the next non-empty range. */
while (blkno < nextRange)
@@ -2948,6 +2949,18 @@ brin_fill_empty_ranges(BrinBuildState *state,
blkno, state->bs_emptyTuple, state->bs_emptyTupleLen);
/* try next page range */
- blkno += state->bs_pagesPerRange;
+ blkno = brin_next_range(state, blkno);
}
}
+
+static BlockNumber
+brin_next_range(BrinBuildState *state, BlockNumber blkno)
+{
+ BlockNumber ret = (blkno + state->bs_pagesPerRange);
+
+ /* overflow */
+ if (ret < blkno)
+ ret = InvalidBlockNumber;
+
+ return ret;
+}
--
2.41.0