v2-0001-Add-TAP-test-for-REINDEX-CONCURRENTLY-with-HOT-up.patch

application/octet-stream

Filename: v2-0001-Add-TAP-test-for-REINDEX-CONCURRENTLY-with-HOT-up.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #17485: Records missing from Primary Key index when doing REINDEX INDEX CONCURRENTLY

Patch

Format: format-patch
Series: patch v2-0001
Subject: Add TAP test for REINDEX CONCURRENTLY with HOT updates Existing amcheck TAP tests failed to find problem in HOT chains in bug 17485.
File+
contrib/amcheck/t/004_rc.pl 69 0
From c27e69a95413549822b0df9e6937063505d7b3ff Mon Sep 17 00:00:00 2001
From: "Andrey M. Borodin" <x4mmm@flight.local>
Date: Sat, 28 May 2022 11:22:32 +0500
Subject: [PATCH v2] Add TAP test for REINDEX CONCURRENTLY with HOT updates
 Existing amcheck TAP tests failed to find problem in HOT chains in bug 17485.

---
 contrib/amcheck/t/004_rc.pl | 69 +++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 contrib/amcheck/t/004_rc.pl

diff --git a/contrib/amcheck/t/004_rc.pl b/contrib/amcheck/t/004_rc.pl
new file mode 100644
index 0000000000..e831aa7f4e
--- /dev/null
+++ b/contrib/amcheck/t/004_rc.pl
@@ -0,0 +1,69 @@
+
+# Copyright (c) 2022, PostgreSQL Global Development Group
+
+# Test REINDEX CONCURRENTLY with concurrent modifications and HOT updates
+use strict;
+use warnings;
+
+use Config;
+
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+
+use Test::More tests => 3;
+
+my ($node, $result);
+
+#
+# Test set-up
+#
+$node = PostgreSQL::Test::Cluster->new('RC_test');
+$node->init;
+$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 primary key,
+								c1 money default 0,c2 money default 0,
+								c3 money default 0, updated_at timestamp)));
+$node->safe_psql('postgres', q(CREATE INDEX idx ON tbl(i)));
+
+#
+# Stress RC with pgbench.
+#
+# pgbench might try to launch more than one instance of the RC
+# transaction concurrently.  That would deadlock, so use an advisory
+# lock to ensure only one RC runs at a time.
+#
+$node->pgbench(
+	'--no-vacuum --client=5 --transactions=35000',
+	0,
+	[qr{actually processed}],
+	[qr{^$}],
+	'concurrent INSERTs, UPDATES and RC',
+	{
+		'002_pgbench_concurrent_transaction_inserts' => q(
+			BEGIN;
+			INSERT INTO tbl VALUES(random()*10000,0,0,0,now())
+				on conflict(i) do update set updated_at = now();
+			COMMIT;
+		  ),
+		# Ensure some HOT updates happen
+		'002_pgbench_concurrent_transaction_updates' => q(
+			BEGIN;
+			INSERT INTO tbl VALUES(random()*1000,0,0,0,now())
+				on conflict(i) do update set updated_at = now();
+			COMMIT;
+		  ),
+		'002_pgbench_concurrent_cic' => q(
+			SELECT pg_try_advisory_lock(42)::integer AS gotlock \gset
+			\if :gotlock
+				REINDEX INDEX CONCURRENTLY idx;
+				SELECT bt_index_check('idx',true);
+				SELECT pg_advisory_unlock(42);
+			\endif
+		  )
+	});
+
+$node->stop;
+done_testing();
-- 
2.32.0 (Apple Git-132)