@@ -28,15 +28,14 @@ SELECT pathman.create_hash_partitions('test.mytbl', 'id1', 8);
28
28
INSERT INTO test.fk VALUES (1, 1);
29
29
INSERT INTO test.mytbl VALUES (1, 1, 5), (1, 1, 6);
30
30
/* gather statistics on test tables to have deterministic plans */
31
- ANALYZE test.fk;
32
- ANALYZE test.mytbl;
31
+ ANALYZE;
33
32
/* run test queries */
34
33
EXPLAIN (COSTS OFF) /* test plan */
35
34
SELECT m.tableoid::regclass, id1, id2, key, start_key, end_key
36
35
FROM test.mytbl m JOIN test.fk USING(id1, id2)
37
36
WHERE NOT key <@ int4range(6, end_key);
38
- QUERY PLAN
39
- ------------------------------------------------------------------------------------
37
+ QUERY PLAN
38
+ -------------------------------------------------------------------------------------------------------
40
39
Nested Loop
41
40
-> Seq Scan on fk
42
41
-> Custom Scan (RuntimeAppend)
@@ -71,17 +70,14 @@ WHERE NOT key <@ int4range(6, end_key);
71
70
Filter: ((fk.id2 = id2) AND (NOT (key <@ int4range(6, fk.end_key))))
72
71
-> Bitmap Index Scan on mytbl_5_pkey
73
72
Index Cond: (id1 = fk.id1)
74
- -> Bitmap Heap Scan on mytbl_6 m
75
- Recheck Cond: (id1 = fk.id1)
76
- Filter: ((fk.id2 = id2) AND (NOT (key <@ int4range(6, fk.end_key))))
77
- -> Bitmap Index Scan on mytbl_6_pkey
78
- Index Cond: (id1 = fk.id1)
73
+ -> Seq Scan on mytbl_6 m
74
+ Filter: ((fk.id1 = id1) AND (fk.id2 = id2) AND (NOT (key <@ int4range(6, fk.end_key))))
79
75
-> Bitmap Heap Scan on mytbl_7 m
80
76
Recheck Cond: (id1 = fk.id1)
81
77
Filter: ((fk.id2 = id2) AND (NOT (key <@ int4range(6, fk.end_key))))
82
78
-> Bitmap Index Scan on mytbl_7_pkey
83
79
Index Cond: (id1 = fk.id1)
84
- (44 rows)
80
+ (41 rows)
85
81
86
82
/* test joint data */
87
83
SELECT m.tableoid::regclass, id1, id2, key, start_key, end_key
@@ -92,7 +88,85 @@ WHERE NOT key <@ int4range(6, end_key);
92
88
test.mytbl_6 | 1 | 1 | 5 | |
93
89
(1 row)
94
90
91
+ /*
92
+ * Test case by @dimarick
93
+ */
94
+ CREATE TABLE test.parent (
95
+ id SERIAL NOT NULL,
96
+ owner_id INTEGER NOT NULL
97
+ );
98
+ CREATE TABLE test.child (
99
+ parent_id INTEGER NOT NULL,
100
+ owner_id INTEGER NOT NULL
101
+ );
102
+ CREATE TABLE test.child_nopart (
103
+ parent_id INTEGER NOT NULL,
104
+ owner_id INTEGER NOT NULL
105
+ );
106
+ INSERT INTO test.parent (owner_id) VALUES (1), (2), (3), (3);
107
+ INSERT INTO test.child (parent_id, owner_id) VALUES (1, 1), (2, 2), (3, 3), (5, 3);
108
+ INSERT INTO test.child_nopart (parent_id, owner_id) VALUES (1, 1), (2, 2), (3, 3), (5, 3);
109
+ SELECT pathman.create_hash_partitions('test.child', 'owner_id', 2);
110
+ create_hash_partitions
111
+ ------------------------
112
+ 2
113
+ (1 row)
114
+
115
+ /* gather statistics on test tables to have deterministic plans */
116
+ ANALYZE;
117
+ /* Query #1 */
118
+ EXPLAIN (COSTS OFF) SELECT * FROM test.parent
119
+ LEFT JOIN test.child ON test.child.parent_id = test.parent.id AND
120
+ test.child.owner_id = test.parent.owner_id
121
+ WHERE test.parent.owner_id = 3 and test.parent.id IN (3, 4);
122
+ QUERY PLAN
123
+ -----------------------------------------------------------------------------------------------------
124
+ Nested Loop Left Join
125
+ -> Seq Scan on parent
126
+ Filter: ((id = ANY ('{3,4}'::integer[])) AND (owner_id = 3))
127
+ -> Custom Scan (RuntimeAppend)
128
+ Prune by: ((child.owner_id = 3) AND (child.owner_id = parent.owner_id))
129
+ -> Seq Scan on child_1 child
130
+ Filter: ((owner_id = 3) AND (owner_id = parent.owner_id) AND (parent_id = parent.id))
131
+ (7 rows)
132
+
133
+ SELECT * FROM test.parent
134
+ LEFT JOIN test.child ON test.child.parent_id = test.parent.id AND
135
+ test.child.owner_id = test.parent.owner_id
136
+ WHERE test.parent.owner_id = 3 and test.parent.id IN (3, 4);
137
+ id | owner_id | parent_id | owner_id
138
+ ----+----------+-----------+----------
139
+ 3 | 3 | 3 | 3
140
+ 4 | 3 | |
141
+ (2 rows)
142
+
143
+ /* Query #2 */
144
+ EXPLAIN (COSTS OFF) SELECT * FROM test.parent
145
+ LEFT JOIN test.child ON test.child.parent_id = test.parent.id AND
146
+ test.child.owner_id = 3
147
+ WHERE test.parent.owner_id = 3 and test.parent.id IN (3, 4);
148
+ QUERY PLAN
149
+ ----------------------------------------------------------------------
150
+ Nested Loop Left Join
151
+ Join Filter: (child_1.parent_id = parent.id)
152
+ -> Seq Scan on parent
153
+ Filter: ((id = ANY ('{3,4}'::integer[])) AND (owner_id = 3))
154
+ -> Append
155
+ -> Seq Scan on child_1
156
+ Filter: (owner_id = 3)
157
+ (7 rows)
158
+
159
+ SELECT * FROM test.parent
160
+ LEFT JOIN test.child ON test.child.parent_id = test.parent.id AND
161
+ test.child.owner_id = 3
162
+ WHERE test.parent.owner_id = 3 and test.parent.id IN (3, 4);
163
+ id | owner_id | parent_id | owner_id
164
+ ----+----------+-----------+----------
165
+ 3 | 3 | 3 | 3
166
+ 4 | 3 | |
167
+ (2 rows)
168
+
95
169
DROP SCHEMA test CASCADE;
96
- NOTICE: drop cascades to 10 other objects
170
+ NOTICE: drop cascades to 15 other objects
97
171
DROP EXTENSION pg_pathman CASCADE;
98
172
DROP SCHEMA pathman CASCADE;
0 commit comments