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

Commitf0ad417

Browse files
committed
BRIN autosummarization may need a snapshot
It's possible to define BRIN indexes on functions that require asnapshot to run, but the autosummarization feature introduced by commit7526e10 fails to provide one. This causes autovacuum to leave aBRIN placeholder tuple behind after a failed work-item execution, makingsuch indexes less efficient. Repair by obtaining a snapshot prior torunning the task, and add a test to verify this behavior.Author: Álvaro Herrera <alvherre@kurilemu.de>Reported-by: Giovanni Fabris <giovanni.fabris@icon.it>Reported-by: Arthur Nascimento <tureba@gmail.com>Backpatch-through: 13Discussion:https://postgr.es/m/202511031106.h4fwyuyui6fz@alvherre.pgsql
1 parenta1b8b3b commitf0ad417

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

‎src/backend/postmaster/autovacuum.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,9 @@ do_autovacuum(void)
26232623
workitem->avw_active= true;
26242624
LWLockRelease(AutovacuumLock);
26252625

2626+
PushActiveSnapshot(GetTransactionSnapshot());
26262627
perform_work_item(workitem);
2628+
PopActiveSnapshot();
26272629

26282630
/*
26292631
* Check for config changes before acquiring lock for further jobs.

‎src/test/modules/brin/t/01_workitems.pl‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use warnings;
88

99
use TestLib;
10-
use Test::Moretests=>2;
10+
use Test::Moretests=>4;
1111
use PostgresNode;
1212

1313
my$node = get_new_node('tango');
@@ -24,21 +24,52 @@
2424
create index brin_wi_idx on brin_wi using brin (a) with (pages_per_range=1, autosummarize=on);
2525
'
2626
);
27+
# Another table with an index that requires a snapshot to run
28+
$node->safe_psql(
29+
'postgres',
30+
'create table journal (d timestamp) with (fillfactor = 10);
31+
create function packdate(d timestamp) returns text language plpgsql
32+
as $$ begin return to_char(d,\'yyyymm\'); end; $$
33+
returns null on null input immutable;
34+
create index brin_packdate_idx on journal using brin (packdate(d))
35+
with (autosummarize = on, pages_per_range = 1);
36+
'
37+
);
38+
2739
my$count =$node->safe_psql('postgres',
2840
"select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)"
2941
);
30-
is($count,'1',"initial index state is correct");
42+
is($count,'1',"initial brin_wi_index index state is correct");
43+
$count =$node->safe_psql('postgres',
44+
"select count(*) from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)"
45+
);
46+
is($count,'1',"initial brin_packdate_idx index state is correct");
3147

3248
$node->safe_psql('postgres',
3349
'insert into brin_wi select * from generate_series(1, 100)');
50+
$node->safe_psql('postgres',
51+
"insert into journal select * from generate_series(timestamp '1976-08-01', '1976-10-28', '1 day')");
3452

3553
$node->poll_query_until(
3654
'postgres',
3755
"select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)",
3856
't');
3957

4058
$count =$node->safe_psql('postgres',
41-
"select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)"
59+
"select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)
60+
where not placeholder;"
4261
);
43-
is($count,'t',"index got summarized");
62+
cmp_ok($count,'>','1',"$count brin_wi_idx ranges got summarized");
63+
64+
$node->poll_query_until(
65+
'postgres',
66+
"select count(*) > 1 from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)",
67+
't');
68+
69+
$count =$node->safe_psql('postgres',
70+
"select count(*) from brin_page_items(get_raw_page('brin_packdate_idx', 2), 'brin_packdate_idx'::regclass)
71+
where not placeholder;"
72+
);
73+
cmp_ok($count,'>','1',"$count brin_packdate_idx ranges got summarized");
74+
4475
$node->stop;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp