From 68f97aeadb8e50794addaf5c1f8e9a67f75691b8 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Sat, 29 Mar 2025 16:46:49 +0100 Subject: [PATCH] amcheck: Add a GIN index to the CREATE INDEX CONCURRENTLY tests The existing CREATE INDEX CONCURRENTLY tests checking only B-Tree, but can be cheaply extended to also check GIN. This helps increasing test coverage for GIN amcheck, especially related to handling concurrent page splits and posting list trees. This already helped to identify several issues during development of the GIN amcheck support. Author: Mark Dilger Reviewed-By: Tomas Vondra Reviewed-By: Kirill Reshke Discussion: https://postgr.es/m/BC221A56-977C-418E-A1B8-9EFC881D80C5%40enterprisedb.com --- contrib/amcheck/t/002_cic.pl | 10 +++++--- contrib/amcheck/t/003_cic_2pc.pl | 40 ++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/contrib/amcheck/t/002_cic.pl b/contrib/amcheck/t/002_cic.pl index 0b6a5a9e464..6a0c4f61125 100644 --- a/contrib/amcheck/t/002_cic.pl +++ b/contrib/amcheck/t/002_cic.pl @@ -21,8 +21,9 @@ $node->append_conf('postgresql.conf', 'lock_timeout = ' . (1000 * $PostgreSQL::Test::Utils::timeout_default)); $node->start; $node->safe_psql('postgres', q(CREATE EXTENSION amcheck)); -$node->safe_psql('postgres', q(CREATE TABLE tbl(i int))); +$node->safe_psql('postgres', q(CREATE TABLE tbl(i int, j jsonb))); $node->safe_psql('postgres', q(CREATE INDEX idx ON tbl(i))); +$node->safe_psql('postgres', q(CREATE INDEX ginidx ON tbl USING gin(j))); # # Stress CIC with pgbench. @@ -40,13 +41,13 @@ $node->pgbench( { '002_pgbench_concurrent_transaction' => q( BEGIN; - INSERT INTO tbl VALUES(0); + INSERT INTO tbl VALUES(0, '{"a":[["b",{"x":1}],["b",{"x":2}]],"c":3}'); COMMIT; ), '002_pgbench_concurrent_transaction_savepoints' => q( BEGIN; SAVEPOINT s1; - INSERT INTO tbl VALUES(0); + INSERT INTO tbl VALUES(0, '[[14,2,3]]'); COMMIT; ), '002_pgbench_concurrent_cic' => q( @@ -54,7 +55,10 @@ $node->pgbench( \if :gotlock DROP INDEX CONCURRENTLY idx; CREATE INDEX CONCURRENTLY idx ON tbl(i); + DROP INDEX CONCURRENTLY ginidx; + CREATE INDEX CONCURRENTLY ginidx ON tbl USING gin(j); SELECT bt_index_check('idx',true); + SELECT gin_index_check('ginidx'); SELECT pg_advisory_unlock(42); \endif ) diff --git a/contrib/amcheck/t/003_cic_2pc.pl b/contrib/amcheck/t/003_cic_2pc.pl index 9134487f3b4..00a446a381f 100644 --- a/contrib/amcheck/t/003_cic_2pc.pl +++ b/contrib/amcheck/t/003_cic_2pc.pl @@ -25,7 +25,7 @@ $node->append_conf('postgresql.conf', 'lock_timeout = ' . (1000 * $PostgreSQL::Test::Utils::timeout_default)); $node->start; $node->safe_psql('postgres', q(CREATE EXTENSION amcheck)); -$node->safe_psql('postgres', q(CREATE TABLE tbl(i int))); +$node->safe_psql('postgres', q(CREATE TABLE tbl(i int, j jsonb))); # @@ -41,7 +41,7 @@ my $main_h = $node->background_psql('postgres'); $main_h->query_safe( q( BEGIN; -INSERT INTO tbl VALUES(0); +INSERT INTO tbl VALUES(0, '[[14,2,3]]'); )); my $cic_h = $node->background_psql('postgres'); @@ -50,6 +50,7 @@ $cic_h->query_until( qr/start/, q( \echo start CREATE INDEX CONCURRENTLY idx ON tbl(i); +CREATE INDEX CONCURRENTLY ginidx ON tbl USING gin(j); )); $main_h->query_safe( @@ -60,7 +61,7 @@ PREPARE TRANSACTION 'a'; $main_h->query_safe( q( BEGIN; -INSERT INTO tbl VALUES(0); +INSERT INTO tbl VALUES(0, '[[14,2,3]]'); )); $node->safe_psql('postgres', q(COMMIT PREPARED 'a';)); @@ -69,7 +70,7 @@ $main_h->query_safe( q( PREPARE TRANSACTION 'b'; BEGIN; -INSERT INTO tbl VALUES(0); +INSERT INTO tbl VALUES(0, '"mary had a little lamb"'); )); $node->safe_psql('postgres', q(COMMIT PREPARED 'b';)); @@ -86,6 +87,9 @@ $cic_h->quit; $result = $node->psql('postgres', q(SELECT bt_index_check('idx',true))); is($result, '0', 'bt_index_check after overlapping 2PC'); +$result = $node->psql('postgres', q(SELECT gin_index_check('ginidx'))); +is($result, '0', 'gin_index_check after overlapping 2PC'); + # # Server restart shall not change whether prepared xact blocks CIC @@ -94,7 +98,7 @@ is($result, '0', 'bt_index_check after overlapping 2PC'); $node->safe_psql( 'postgres', q( BEGIN; -INSERT INTO tbl VALUES(0); +INSERT INTO tbl VALUES(0, '{"a":[["b",{"x":1}],["b",{"x":2}]],"c":3}'); PREPARE TRANSACTION 'spans_restart'; BEGIN; CREATE TABLE unused (); @@ -108,12 +112,16 @@ $reindex_h->query_until( \echo start DROP INDEX CONCURRENTLY idx; CREATE INDEX CONCURRENTLY idx ON tbl(i); +DROP INDEX CONCURRENTLY ginidx; +CREATE INDEX CONCURRENTLY ginidx ON tbl USING gin(j); )); $node->safe_psql('postgres', "COMMIT PREPARED 'spans_restart'"); $reindex_h->quit; $result = $node->psql('postgres', q(SELECT bt_index_check('idx',true))); is($result, '0', 'bt_index_check after 2PC and restart'); +$result = $node->psql('postgres', q(SELECT gin_index_check('ginidx'))); +is($result, '0', 'gin_index_check after 2PC and restart'); # @@ -136,14 +144,14 @@ $node->pgbench( { '003_pgbench_concurrent_2pc' => q( BEGIN; - INSERT INTO tbl VALUES(0); + INSERT INTO tbl VALUES(0,'null'); PREPARE TRANSACTION 'c:client_id'; COMMIT PREPARED 'c:client_id'; ), '003_pgbench_concurrent_2pc_savepoint' => q( BEGIN; SAVEPOINT s1; - INSERT INTO tbl VALUES(0); + INSERT INTO tbl VALUES(0,'[false, "jnvaba", -76, 7, {"_": [1]}, 9]'); PREPARE TRANSACTION 'c:client_id'; COMMIT PREPARED 'c:client_id'; ), @@ -163,7 +171,25 @@ $node->pgbench( SELECT bt_index_check('idx',true); SELECT pg_advisory_unlock(42); \endif + ), + '005_pgbench_concurrent_cic' => q( + SELECT pg_try_advisory_lock(42)::integer AS gotginlock \gset + \if :gotginlock + DROP INDEX CONCURRENTLY ginidx; + CREATE INDEX CONCURRENTLY ginidx ON tbl USING gin(j); + SELECT gin_index_check('ginidx'); + SELECT pg_advisory_unlock(42); + \endif + ), + '006_pgbench_concurrent_ric' => q( + SELECT pg_try_advisory_lock(42)::integer AS gotginlock \gset + \if :gotginlock + REINDEX INDEX CONCURRENTLY ginidx; + SELECT gin_index_check('ginidx'); + SELECT pg_advisory_unlock(42); + \endif ) + }); $node->stop; -- 2.39.5