mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
Fix PageAddItem BRIN bug
BRIN was relying on the ability to remove a tuple from an index page, then putting another tuple in the same line pointer. But PageAddItem refuses to add a tuple beyond the first free item past the last used item, and in particular, it rejects an attempt to add an item to an empty page anywhere other than the first line pointer. PageAddItem issues a WARNING and indicates to the caller that it failed, which in turn causes the BRIN calling code to issue a PANIC, so the whole sequence looks like this: WARNING: specified item offset is too large PANIC: failed to add BRIN tuple To fix, create a new function PageAddItemExtended which is like PageAddItem except that the two boolean arguments become a flags bitmap; the "overwrite" and "is_heap" boolean flags in PageAddItem become PAI_OVERWITE and PAI_IS_HEAP flags in the new function, and a new flag PAI_ALLOW_FAR_OFFSET enables the behavior required by BRIN. PageAddItem() retains its original signature, for compatibility with third-party modules (other callers in core code are not modified, either). Also, in the belt-and-suspenders spirit, I added a new sanity check in brinGetTupleForHeapBlock to raise an error if an TID found in the revmap is not marked as live by the page header. This causes it to react with "ERROR: corrupted BRIN index" to the bug at hand, rather than a hard crash. Backpatch to 9.5. Bug reported by Andreas Seltenreich as detected by his handy sqlsmith fuzzer. Discussion: https://www.postgresql.org/message-id/87mvni77jh.fsf@elite.ansel.ydns.eu
This commit is contained in:
@@ -407,11 +407,16 @@ do { \
|
||||
* extern declarations
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
#define PAI_OVERWRITE (1 << 0)
|
||||
#define PAI_IS_HEAP (1 << 1)
|
||||
#define PAI_ALLOW_FAR_OFFSET (1 << 2)
|
||||
|
||||
extern void PageInit(Page page, Size pageSize, Size specialSize);
|
||||
extern bool PageIsVerified(Page page, BlockNumber blkno);
|
||||
extern OffsetNumber PageAddItem(Page page, Item item, Size size,
|
||||
OffsetNumber offsetNumber, bool overwrite, bool is_heap);
|
||||
extern OffsetNumber PageAddItemExtended(Page page, Item item, Size size,
|
||||
OffsetNumber offsetNumber, int flags);
|
||||
extern Page PageGetTempPage(Page page);
|
||||
extern Page PageGetTempPageCopy(Page page);
|
||||
extern Page PageGetTempPageCopySpecial(Page page);
|
||||
|
||||
Reference in New Issue
Block a user