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

Commit d603e67

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 50f8611 commit d603e67

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

203203
(1 row)
204204

205+
-- Also check that we compress varlena values, which were previously stored
206+
-- uncompressed in index.
207+
INSERT INTO varlena_bug VALUES (repeat('Test', 250));
208+
ALTER TABLE varlena_bug ALTER COLUMN v SET STORAGE extended;
209+
SELECT bt_index_check('varlena_bug_idx', true);
210+
bt_index_check
211+
----------------
212+
213+
(1 row)
214+
205215
-- cleanup
206216
DROP TABLE bttest_a;
207217
DROP TABLE bttest_b;

contrib/amcheck/sql/check_btree.sql

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

143+
-- Also check that we compress varlena values, which were previously stored
144+
-- uncompressed in index.
145+
INSERT INTO varlena_bug VALUES (repeat('Test', 250));
146+
ALTER TABLE varlena_bug ALTER COLUMN v SET STORAGE extended;
147+
SELECT bt_index_check('varlena_bug_idx', true);
148+
143149
-- cleanup
144150
DROP TABLE bttest_a;
145151
DROP TABLE bttest_b;

contrib/amcheck/verify_nbtree.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "access/table.h"
2929
#include "access/tableam.h"
3030
#include "access/transam.h"
31+
#include "access/tuptoaster.h"
3132
#include "access/xact.h"
3233
#include "catalog/index.h"
3334
#include "catalog/pg_am.h"
@@ -2093,6 +2094,18 @@ bt_normalize_tuple(BtreeCheckState *state, IndexTuple itup)
20932094
ItemPointerGetBlockNumber(&(itup->t_tid)),
20942095
ItemPointerGetOffsetNumber(&(itup->t_tid)),
20952096
RelationGetRelationName(state->rel))));
2097+
else if (!VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])) &&
2098+
VARSIZE(DatumGetPointer(normalized[i])) > TOAST_INDEX_TARGET &&
2099+
(att->attstorage == 'x' ||
2100+
att->attstorage == 'm'))
2101+
{
2102+
/*
2103+
* This value will be compressed by index_form_tuple() with the
2104+
* current storage settings. We may be here because this tuple
2105+
* was formed with different storage settings. So, force forming.
2106+
*/
2107+
formnewtup = true;
2108+
}
20962109
else if (VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])))
20972110
{
20982111
formnewtup = true;

0 commit comments

Comments
 (0)