On 14/8/2024 23:05, Imseih (AWS), Sami wrote:
There are no tests as this requires more discussion in a separate thread(?)
Unfortunately, TAP tests don't allow us to keep a connection and manually permutate the order of queries sent to different connections. But isolation tests are designed to do so. Of course, they aren't the best if you need to compare values produced by various queries but see a clumsy sketch doing that in the attachment. Also, while writing the test, I found out that now, JumbleQuery takes into account constants of the A_Const node, and calls of the same prepared statement with different parameters generate different query_id. Is it a reason to introduce JumbleQuery options and allow different logic of queryid generation?

--
regards, Andrei Lepikhov
From 8019a716714477c9aeeed1f208d76f87722b051a Mon Sep 17 00:00:00 2001
From: "Andrei V. Lepikhov" <lepi...@gmail.com>
Date: Tue, 3 Sep 2024 16:38:29 +0200
Subject: [PATCH] queryid isolation test

---
 src/test/isolation/expected/queryid.out |  1 +
 src/test/isolation/isolation_schedule   |  1 +
 src/test/isolation/specs/queryid.spec   | 48 +++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 src/test/isolation/expected/queryid.out
 create mode 100644 src/test/isolation/specs/queryid.spec

diff --git a/src/test/isolation/expected/queryid.out 
b/src/test/isolation/expected/queryid.out
new file mode 100644
index 0000000000..7ec1dff5ad
--- /dev/null
+++ b/src/test/isolation/expected/queryid.out
@@ -0,0 +1 @@
+Parsed test spec with 2 sessions
diff --git a/src/test/isolation/isolation_schedule 
b/src/test/isolation/isolation_schedule
index 143109aa4d..823720fab5 100644
--- a/src/test/isolation/isolation_schedule
+++ b/src/test/isolation/isolation_schedule
@@ -1,3 +1,4 @@
+test: queryid
 test: read-only-anomaly
 test: read-only-anomaly-2
 test: read-only-anomaly-3
diff --git a/src/test/isolation/specs/queryid.spec 
b/src/test/isolation/specs/queryid.spec
new file mode 100644
index 0000000000..1c806c5eb9
--- /dev/null
+++ b/src/test/isolation/specs/queryid.spec
@@ -0,0 +1,48 @@
+# Test for checking correct update of queryid
+
+setup
+{
+  CREATE TABLE test_queryid(x int);
+  INSERT INTO test_queryid (x) VALUES (2);
+  INSERT INTO test_queryid (x) VALUES (1);
+  ANALYZE test_queryid;
+}
+
+teardown
+{
+    DROP TABLE test_queryid CASCADE;
+    RESET compute_query_id;
+}
+
+session s1
+step s1_begin { SET compute_query_id = 'on'; }
+step s1_trivial { /* queryid test */ SELECT relname FROM pg_class WHERE oid < 
1; }
+step s1_prepare { /* queryid test */ PREPARE probe (int) AS SELECT * FROM 
test_queryid t1 JOIN test_queryid t2 USING (x) WHERE t1.x = $1 AND t2.x = 2; }
+step s1_probe1 { /* queryid test */ EXECUTE probe(1); }
+step s1_probe2 { /* queryid test */ EXECUTE probe(2); }
+
+session s2
+step s2_get_qqid1 { SELECT query_id INTO res1 FROM pg_stat_activity WHERE 
query LIKE '/* queryid test */%'; }
+step s2_get_qqid2 { SELECT query_id INTO res2 FROM pg_stat_activity WHERE 
query LIKE '/* queryid test */%'; }
+step s2_check_res1 { SELECT query_id <> 0 FROM res1;}
+step s2_check_res2 { SELECT query_id <> 0 FROM res2;}
+step s2_cmp_r1r2 { SELECT (SELECT query_id FROM res1) <> (SELECT query_id FROM 
res2);}
+step s2_resdrop { DROP TABLE IF EXISTS res1,res2; }
+
+permutation
+    s1_begin
+       s1_trivial
+    s2_get_qqid1
+    s2_check_res1
+       s1_prepare
+       s2_get_qqid2
+       s2_check_res2
+       s2_cmp_r1r2
+       s2_resdrop
+       s1_probe1
+       s2_get_qqid1
+       s2_check_res1
+       s1_probe2
+       s2_get_qqid2
+       s2_check_res2
+       s2_cmp_r1r2
-- 
2.46.0

Reply via email to