Debian Codegraph @

contrib/postgres_fdw/specs/eval_plan_qual.spec

raw
1 # Tests for the EvalPlanQual mechanism involving foreign tables
2
3 setup
4 {
5 DO $d$
6 BEGIN
7 EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
8 OPTIONS (dbname '$$||current_database()||$$',
9 port '$$||current_setting('port')||$$',
10 use_remote_estimate 'true'
11 )$$;
12 END;
13 $d$;
14 CREATE USER MAPPING FOR PUBLIC SERVER loopback;
15
16 CREATE TABLE l (i int, v text);
17 CREATE TABLE t (i int, v text);
18 CREATE FOREIGN TABLE ft (i int, v text) SERVER loopback OPTIONS (table_name 't');
19
20 INSERT INTO l VALUES (123, 'foo'), (456, 'bar'), (789, 'baz');
21 INSERT INTO t SELECT i, to_char(i, 'FM0000') FROM generate_series(1, 1000) i;
22 CREATE INDEX t_idx ON t (i);
23 ANALYZE l, t;
24
25 CREATE TABLE a (i int);
26 CREATE TABLE b (i int);
27 CREATE TABLE c (i int);
28 CREATE FOREIGN TABLE fb (i int) SERVER loopback OPTIONS (table_name 'b');
29 CREATE FOREIGN TABLE fc (i int) SERVER loopback OPTIONS (table_name 'c');
30
31 INSERT INTO a VALUES (1);
32 INSERT INTO b VALUES (1);
33 INSERT INTO c VALUES (1);
34 ANALYZE a, b, c;
35 }
36
37 teardown
38 {
39 DROP TABLE l;
40 DROP TABLE t;
41 DROP TABLE a;
42 DROP TABLE b;
43 DROP TABLE c;
44 DROP SERVER loopback CASCADE;
45 }
46
47 session s0
48 setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
49 step s0_update_l { UPDATE l SET i = i + 1; }
50 step s0_update_a { UPDATE a SET i = i + 1; }
51 step s0_commit { COMMIT; }
52
53 session s1
54 setup { BEGIN ISOLATION LEVEL READ COMMITTED; }
55
56 # Test for EPQ with a foreign scan pushing down a qual
57 step s1_tuplock_l_0 {
58 EXPLAIN (VERBOSE, COSTS OFF)
59 SELECT l.* FROM l, ft WHERE l.i = ft.i AND l.i = 123 FOR UPDATE OF l;
60 SELECT l.* FROM l, ft WHERE l.i = ft.i AND l.i = 123 FOR UPDATE OF l;
61 }
62
63 # Same test, except that the qual is parameterized
64 step s1_tuplock_l_1 {
65 EXPLAIN (VERBOSE, COSTS OFF)
66 SELECT l.* FROM l, ft WHERE l.i = ft.i AND l.v = 'foo' FOR UPDATE OF l;
67 SELECT l.* FROM l, ft WHERE l.i = ft.i AND l.v = 'foo' FOR UPDATE OF l;
68 }
69
70 # Test for EPQ with a foreign scan pushing down a join
71 step s1_tuplock_a_0 {
72 EXPLAIN (VERBOSE, COSTS OFF)
73 SELECT a.i FROM a, fb, fc WHERE a.i = fb.i AND fb.i = fc.i FOR UPDATE OF a;
74 SELECT a.i FROM a, fb, fc WHERE a.i = fb.i AND fb.i = fc.i FOR UPDATE OF a;
75 }
76
77 # Same test, except that the join is contained in a SubLink sub-select, not
78 # in the main query
79 step s1_tuplock_a_1 {
80 EXPLAIN (VERBOSE, COSTS OFF)
81 SELECT a.i,
82 (SELECT 1 FROM fb, fc WHERE a.i = fb.i AND fb.i = fc.i)
83 FROM a FOR UPDATE;
84 SELECT a.i,
85 (SELECT 1 FROM fb, fc WHERE a.i = fb.i AND fb.i = fc.i)
86 FROM a FOR UPDATE;
87 }
88
89 step s1_commit { COMMIT; }
90
91 # This test checks the case of rechecking a pushed-down qual.
92 permutation s0_update_l s1_tuplock_l_0 s0_commit s1_commit
93
94 # This test checks the same case, except that the qual is parameterized.
95 permutation s0_update_l s1_tuplock_l_1 s0_commit s1_commit
96
97 # This test checks the case of rechecking a pushed-down join.
98 permutation s0_update_a s1_tuplock_a_0 s0_commit s1_commit
99
100 # This test exercises EvalPlanQual with a SubLink sub-select (which should
101 # be unaffected by any EPQ recheck behavior in the outer query).
102 permutation s0_update_a s1_tuplock_a_1 s0_commit s1_commit