Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1fe8ef

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, weneed 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.ruAuthor: Andrey BorodinReviewed-by: Alexander Lakhin, Michael Zhilin, Jian He, Alexander KorotkovBackpatch-through: 12
1 parentab65dfb commitb1fe8ef

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
CREATEINDEXvarlena_bug_idxon 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_bugVALUES (repeat('Test',250));
164+
ALTERTABLE varlena_bug ALTER COLUMN vSET STORAGE extended;
165+
SELECT bt_index_check('varlena_bug_idx', true);
166+
161167
-- cleanup
162168
DROPTABLE bttest_a;
163169
DROPTABLE 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+
elseif (!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
elseif (VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])))
29852998
{
29862999
formnewtup= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp