Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3676b84

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 a6ddb8a commit 3676b84

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
@@ -211,6 +211,16 @@ SELECT bt_index_check('varlena_bug_idx', true);
211211

212212
(1 row)
213213

214+
-- Also check that we compress varlena values, which were previously stored
215+
-- uncompressed in index.
216+
INSERT INTO varlena_bug VALUES (repeat('Test', 250));
217+
ALTER TABLE varlena_bug ALTER COLUMN v SET STORAGE extended;
218+
SELECT bt_index_check('varlena_bug_idx', true);
219+
bt_index_check
220+
----------------
221+
222+
(1 row)
223+
214224
-- cleanup
215225
DROP TABLE bttest_a;
216226
DROP TABLE bttest_b;

contrib/amcheck/sql/check_btree.sql

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

148+
-- Also check that we compress varlena values, which were previously stored
149+
-- uncompressed in index.
150+
INSERT INTO varlena_bug VALUES (repeat('Test', 250));
151+
ALTER TABLE varlena_bug ALTER COLUMN v SET STORAGE extended;
152+
SELECT bt_index_check('varlena_bug_idx', true);
153+
148154
-- cleanup
149155
DROP TABLE bttest_a;
150156
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"
@@ -2680,6 +2681,18 @@ bt_normalize_tuple(BtreeCheckState *state, IndexTuple itup)
26802681
ItemPointerGetBlockNumber(&(itup->t_tid)),
26812682
ItemPointerGetOffsetNumber(&(itup->t_tid)),
26822683
RelationGetRelationName(state->rel))));
2684+
else if (!VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])) &&
2685+
VARSIZE(DatumGetPointer(normalized[i])) > TOAST_INDEX_TARGET &&
2686+
(att->attstorage == TYPSTORAGE_EXTENDED ||
2687+
att->attstorage == TYPSTORAGE_MAIN))
2688+
{
2689+
/*
2690+
* This value will be compressed by index_form_tuple() with the
2691+
* current storage settings. We may be here because this tuple
2692+
* was formed with different storage settings. So, force forming.
2693+
*/
2694+
formnewtup = true;
2695+
}
26832696
else if (VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])))
26842697
{
26852698
formnewtup = true;

0 commit comments

Comments
 (0)