Skip to content

Commit b1fe8ef

Browse files
committed
amcheck: Normalize index tuples containing uncompressed varlena
It might happen that the varlena value wasn't compressed by index_form_tuple() due to current storage parameters. If compression is currently enabled, we need to compress such values to match index tuple coming from the heap. Backpatch to all supported versions. Discussion: https://postgr.es/m/flat/7bdbe559-d61a-4ae4-a6e1-48abdf3024cc%40postgrespro.ru Author: Andrey Borodin Reviewed-by: Alexander Lakhin, Michael Zhilin, Jian He, Alexander Korotkov Backpatch-through: 12
1 parent ab65dfb commit b1fe8ef

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

contrib/amcheck/expected/check_btree.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ SELECT bt_index_check('varlena_bug_idx', true);
252252

253253
(1 row)
254254

255+
-- Also check that we compress varlena values, which were previously stored
256+
-- uncompressed in index.
257+
INSERT INTO varlena_bug VALUES (repeat('Test', 250));
258+
ALTER TABLE varlena_bug ALTER COLUMN v SET STORAGE extended;
259+
SELECT bt_index_check('varlena_bug_idx', true);
260+
bt_index_check
261+
----------------
262+
263+
(1 row)
264+
255265
-- cleanup
256266
DROP TABLE bttest_a;
257267
DROP TABLE bttest_b;

contrib/amcheck/sql/check_btree.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ x
158158
CREATE INDEX varlena_bug_idx on varlena_bug(v);
159159
SELECT bt_index_check('varlena_bug_idx', true);
160160

161+
-- Also check that we compress varlena values, which were previously stored
162+
-- uncompressed in index.
163+
INSERT INTO varlena_bug VALUES (repeat('Test', 250));
164+
ALTER TABLE varlena_bug ALTER COLUMN v SET STORAGE extended;
165+
SELECT bt_index_check('varlena_bug_idx', true);
166+
161167
-- cleanup
162168
DROP TABLE bttest_a;
163169
DROP TABLE bttest_b;

contrib/amcheck/verify_nbtree.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
#include "postgres.h"
2525

26+
#include "access/heaptoast.h"
2627
#include "access/htup_details.h"
2728
#include "access/nbtree.h"
2829
#include "access/table.h"
@@ -2981,6 +2982,18 @@ bt_normalize_tuple(BtreeCheckState *state, IndexTuple itup)
29812982
ItemPointerGetBlockNumber(&(itup->t_tid)),
29822983
ItemPointerGetOffsetNumber(&(itup->t_tid)),
29832984
RelationGetRelationName(state->rel))));
2985+
else if (!VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])) &&
2986+
VARSIZE(DatumGetPointer(normalized[i])) > TOAST_INDEX_TARGET &&
2987+
(att->attstorage == TYPSTORAGE_EXTENDED ||
2988+
att->attstorage == TYPSTORAGE_MAIN))
2989+
{
2990+
/*
2991+
* This value will be compressed by index_form_tuple() with the
2992+
* current storage settings. We may be here because this tuple
2993+
* was formed with different storage settings. So, force forming.
2994+
*/
2995+
formnewtup = true;
2996+
}
29842997
else if (VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])))
29852998
{
29862999
formnewtup = true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy