@@ -10,9 +10,16 @@ CREATE EXTENSION pg_pathman SCHEMA pathman;
10
10
CREATE SCHEMA test;
11
11
SET enable_indexscan = ON;
12
12
SET enable_seqscan = OFF;
13
- /* Temporary table for JOINs */
13
+ /* Temporary tables for JOINs */
14
14
CREATE TABLE test.tmp (id INTEGER NOT NULL, value INTEGER NOT NULL);
15
15
INSERT INTO test.tmp VALUES (1, 1), (2, 2);
16
+ CREATE TABLE test.tmp2 (id INTEGER NOT NULL, value INTEGER NOT NULL);
17
+ SELECT pathman.create_range_partitions('test.tmp2', 'id', 1, 1, 10);
18
+ create_range_partitions
19
+ -------------------------
20
+ 10
21
+ (1 row)
22
+
16
23
/* Partition table by RANGE */
17
24
CREATE TABLE test.range_rel (
18
25
id SERIAL PRIMARY KEY,
@@ -28,6 +35,7 @@ SELECT pathman.create_range_partitions('test.range_rel', 'dt',
28
35
12
29
36
(1 row)
30
37
38
+ VACUUM ANALYZE;
31
39
/*
32
40
* Test UPDATE and DELETE
33
41
*/
@@ -104,16 +112,15 @@ ROLLBACK;
104
112
EXPLAIN (COSTS OFF)
105
113
UPDATE test.range_rel r SET value = t.value
106
114
FROM test.tmp t WHERE r.dt = '2010-01-01' AND r.id = t.id;
107
- QUERY PLAN
108
- --------------------------------------------------------------------------------------------
115
+ QUERY PLAN
116
+ --------------------------------------------------------------------------------------
109
117
Update on range_rel_1 r
110
- -> Hash Join
111
- Hash Cond: (t.id = r.id)
118
+ -> Nested Loop
119
+ Join Filter: (r.id = t.id)
120
+ -> Index Scan using range_rel_1_pkey on range_rel_1 r
121
+ Filter: (dt = 'Fri Jan 01 00:00:00 2010'::timestamp without time zone)
112
122
-> Seq Scan on tmp t
113
- -> Hash
114
- -> Index Scan using range_rel_1_pkey on range_rel_1 r
115
- Filter: (dt = 'Fri Jan 01 00:00:00 2010'::timestamp without time zone)
116
- (7 rows)
123
+ (6 rows)
117
124
118
125
BEGIN;
119
126
UPDATE test.range_rel r SET value = t.value
@@ -123,17 +130,16 @@ ROLLBACK;
123
130
EXPLAIN (COSTS OFF)
124
131
UPDATE test.tmp t SET value = r.value
125
132
FROM test.range_rel r WHERE r.dt = '2010-01-01' AND r.id = t.id;
126
- QUERY PLAN
127
- --------------------------------------------------------------------------------------------------
133
+ QUERY PLAN
134
+ --------------------------------------------------------------------------------------------
128
135
Update on tmp t
129
- -> Hash Join
130
- Hash Cond: (t.id = r.id)
136
+ -> Nested Loop
131
137
-> Seq Scan on tmp t
132
- -> Hash
133
- -> Append
134
- -> Index Scan using range_rel_1_pkey on range_rel_1 r
135
- Filter: (dt = 'Fri Jan 01 00:00:00 2010'::timestamp without time zone)
136
- (8 rows)
138
+ -> Append
139
+ -> Index Scan using range_rel_1_pkey on range_rel_1 r
140
+ Index Cond: (id = t.id)
141
+ Filter: (dt = 'Fri Jan 01 00:00:00 2010'::timestamp without time zone)
142
+ (7 rows)
137
143
138
144
BEGIN;
139
145
UPDATE test.tmp t SET value = r.value
@@ -143,16 +149,15 @@ ROLLBACK;
143
149
EXPLAIN (COSTS OFF)
144
150
DELETE FROM test.range_rel r USING test.tmp t
145
151
WHERE r.dt = '2010-01-02' AND r.id = t.id;
146
- QUERY PLAN
147
- --------------------------------------------------------------------------------------------
152
+ QUERY PLAN
153
+ --------------------------------------------------------------------------------------
148
154
Delete on range_rel_1 r
149
- -> Hash Join
150
- Hash Cond: (t.id = r.id)
155
+ -> Nested Loop
156
+ Join Filter: (r.id = t.id)
157
+ -> Index Scan using range_rel_1_pkey on range_rel_1 r
158
+ Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
151
159
-> Seq Scan on tmp t
152
- -> Hash
153
- -> Index Scan using range_rel_1_pkey on range_rel_1 r
154
- Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
155
- (7 rows)
160
+ (6 rows)
156
161
157
162
BEGIN;
158
163
DELETE FROM test.range_rel r USING test.tmp t
@@ -162,22 +167,118 @@ ROLLBACK;
162
167
EXPLAIN (COSTS OFF)
163
168
DELETE FROM test.tmp t USING test.range_rel r
164
169
WHERE r.dt = '2010-01-02' AND r.id = t.id;
165
- QUERY PLAN
166
- --------------------------------------------------------------------------------------------------
170
+ QUERY PLAN
171
+ --------------------------------------------------------------------------------------------
167
172
Delete on tmp t
168
- -> Hash Join
169
- Hash Cond: (t.id = r.id)
173
+ -> Nested Loop
170
174
-> Seq Scan on tmp t
171
- -> Hash
172
- -> Append
173
- -> Index Scan using range_rel_1_pkey on range_rel_1 r
174
- Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
175
- (8 rows)
175
+ -> Append
176
+ -> Index Scan using range_rel_1_pkey on range_rel_1 r
177
+ Index Cond: (id = t.id)
178
+ Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
179
+ (7 rows)
176
180
177
181
BEGIN;
178
182
DELETE FROM test.tmp t USING test.range_rel r
179
183
WHERE r.dt = '2010-01-02' AND r.id = t.id;
180
184
ROLLBACK;
185
+ /* DELETE + USING, two partitioned tables */
186
+ EXPLAIN (COSTS OFF)
187
+ DELETE FROM test.range_rel r USING test.tmp2 t
188
+ WHERE t.id = r.id;
189
+ ERROR: DELETE and UPDATE queries with a join of partitioned tables are not supported
190
+ BEGIN;
191
+ DELETE FROM test.range_rel r USING test.tmp2 t
192
+ WHERE t.id = r.id;
193
+ ERROR: DELETE and UPDATE queries with a join of partitioned tables are not supported
194
+ ROLLBACK;
195
+ /* DELETE + USING, partitioned table + two partitioned tables in subselect */
196
+ EXPLAIN (COSTS OFF)
197
+ DELETE FROM test.range_rel r
198
+ USING (SELECT *
199
+ FROM test.tmp2 a1
200
+ JOIN test.tmp2 a2
201
+ USING(id)) t
202
+ WHERE t.id = r.id;
203
+ ERROR: DELETE and UPDATE queries with a join of partitioned tables are not supported
204
+ BEGIN;
205
+ DELETE FROM test.range_rel r
206
+ USING (SELECT *
207
+ FROM test.tmp2 a1
208
+ JOIN test.tmp2 a2
209
+ USING(id)) t
210
+ WHERE t.id = r.id;
211
+ ERROR: DELETE and UPDATE queries with a join of partitioned tables are not supported
212
+ ROLLBACK;
213
+ /* DELETE + USING, single table + two partitioned tables in subselect */
214
+ EXPLAIN (COSTS OFF)
215
+ DELETE FROM test.tmp r
216
+ USING (SELECT *
217
+ FROM test.tmp2 a1
218
+ JOIN test.tmp2 a2
219
+ USING(id)) t
220
+ WHERE t.id = r.id;
221
+ QUERY PLAN
222
+ ------------------------------------------------------
223
+ Delete on tmp r
224
+ -> Nested Loop
225
+ Join Filter: (a1.id = a2.id)
226
+ -> Append
227
+ -> Seq Scan on tmp2_1 a2
228
+ -> Seq Scan on tmp2_2 a2_1
229
+ -> Seq Scan on tmp2_3 a2_2
230
+ -> Seq Scan on tmp2_4 a2_3
231
+ -> Seq Scan on tmp2_5 a2_4
232
+ -> Seq Scan on tmp2_6 a2_5
233
+ -> Seq Scan on tmp2_7 a2_6
234
+ -> Seq Scan on tmp2_8 a2_7
235
+ -> Seq Scan on tmp2_9 a2_8
236
+ -> Seq Scan on tmp2_10 a2_9
237
+ -> Materialize
238
+ -> Nested Loop
239
+ -> Seq Scan on tmp r
240
+ -> Custom Scan (RuntimeAppend)
241
+ Prune by: (r.id = a1.id)
242
+ -> Seq Scan on tmp2_1 a1
243
+ Filter: (r.id = id)
244
+ -> Seq Scan on tmp2_2 a1
245
+ Filter: (r.id = id)
246
+ -> Seq Scan on tmp2_3 a1
247
+ Filter: (r.id = id)
248
+ -> Seq Scan on tmp2_4 a1
249
+ Filter: (r.id = id)
250
+ -> Seq Scan on tmp2_5 a1
251
+ Filter: (r.id = id)
252
+ -> Seq Scan on tmp2_6 a1
253
+ Filter: (r.id = id)
254
+ -> Seq Scan on tmp2_7 a1
255
+ Filter: (r.id = id)
256
+ -> Seq Scan on tmp2_8 a1
257
+ Filter: (r.id = id)
258
+ -> Seq Scan on tmp2_9 a1
259
+ Filter: (r.id = id)
260
+ -> Seq Scan on tmp2_10 a1
261
+ Filter: (r.id = id)
262
+ (39 rows)
263
+
264
+ BEGIN;
265
+ DELETE FROM test.tmp r
266
+ USING (SELECT *
267
+ FROM test.tmp2 a1
268
+ JOIN test.tmp2 a2
269
+ USING(id)) t
270
+ WHERE t.id = r.id;
271
+ ROLLBACK;
272
+ /* UPDATE + FROM, two partitioned tables */
273
+ EXPLAIN (COSTS OFF)
274
+ UPDATE test.range_rel r SET value = 1 FROM test.tmp2 t
275
+ WHERE t.id = r.id;
276
+ ERROR: DELETE and UPDATE queries with a join of partitioned tables are not supported
277
+ BEGIN;
278
+ UPDATE test.range_rel r SET value = 1 FROM test.tmp2 t
279
+ WHERE t.id = r.id;
280
+ ERROR: DELETE and UPDATE queries with a join of partitioned tables are not supported
281
+ ROLLBACK;
181
282
/* Test special rule for CTE; SELECT (PostgreSQL 9.5) */
182
283
EXPLAIN (COSTS OFF)
183
284
WITH q AS (SELECT * FROM test.range_rel r
@@ -191,10 +292,9 @@ DELETE FROM test.tmp USING q;
191
292
-> Seq Scan on range_rel_1 r
192
293
Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
193
294
-> Nested Loop
295
+ -> Seq Scan on tmp
194
296
-> CTE Scan on q
195
- -> Materialize
196
- -> Seq Scan on tmp
197
- (9 rows)
297
+ (8 rows)
198
298
199
299
BEGIN;
200
300
WITH q AS (SELECT * FROM test.range_rel r
@@ -215,10 +315,9 @@ DELETE FROM test.tmp USING q;
215
315
-> Seq Scan on range_rel_1 r
216
316
Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
217
317
-> Nested Loop
318
+ -> Seq Scan on tmp
218
319
-> CTE Scan on q
219
- -> Materialize
220
- -> Seq Scan on tmp
221
- (9 rows)
320
+ (8 rows)
222
321
223
322
BEGIN;
224
323
WITH q AS (DELETE FROM test.range_rel r
@@ -233,23 +332,21 @@ WITH q AS (DELETE FROM test.tmp t
233
332
WHERE r.dt = '2010-01-02' AND r.id = t.id
234
333
RETURNING *)
235
334
DELETE FROM test.tmp USING q;
236
- QUERY PLAN
237
- ----------------------------------------------------------------------------------------------------------
335
+ QUERY PLAN
336
+ ----------------------------------------------------------------------------------------------------
238
337
Delete on tmp
239
338
CTE q
240
339
-> Delete on tmp t
241
- -> Hash Join
242
- Hash Cond: (t.id = r.id)
340
+ -> Nested Loop
243
341
-> Seq Scan on tmp t
244
- -> Hash
245
- -> Append
246
- -> Index Scan using range_rel_1_pkey on range_rel_1 r
247
- Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
342
+ -> Append
343
+ -> Index Scan using range_rel_1_pkey on range_rel_1 r
344
+ Index Cond: (id = t.id)
345
+ Filter: (dt = 'Sat Jan 02 00:00:00 2010'::timestamp without time zone)
248
346
-> Nested Loop
347
+ -> Seq Scan on tmp
249
348
-> CTE Scan on q
250
- -> Materialize
251
- -> Seq Scan on tmp
252
- (14 rows)
349
+ (12 rows)
253
350
254
351
BEGIN;
255
352
WITH q AS (DELETE FROM test.tmp t
@@ -259,6 +356,6 @@ WITH q AS (DELETE FROM test.tmp t
259
356
DELETE FROM test.tmp USING q;
260
357
ROLLBACK;
261
358
DROP SCHEMA test CASCADE;
262
- NOTICE: drop cascades to 15 other objects
359
+ NOTICE: drop cascades to 27 other objects
263
360
DROP EXTENSION pg_pathman CASCADE;
264
361
DROP SCHEMA pathman CASCADE;
0 commit comments