Debian Codegraph @

contrib/pg_overexplain/expected/pg_overexplain.out

raw
1 -- These tests display internal details that would not be stable under
2 -- debug_parallel_query, so make sure that option is disabled.
3 SET debug_parallel_query = off;
4 -- Make sure that we don't print any JIT-related information, as that
5 -- would also make results unstable.
6 SET jit = off;
7 -- These options do not exist, so these queries should all fail.
8 EXPLAIN (DEBUFF) SELECT 1;
9 ERROR: unrecognized EXPLAIN option "debuff"
10 LINE 1: EXPLAIN (DEBUFF) SELECT 1;
11 ^
12 EXPLAIN (DEBUG) SELECT 1;
13 ERROR: unrecognized EXPLAIN option "debug"
14 LINE 1: EXPLAIN (DEBUG) SELECT 1;
15 ^
16 EXPLAIN (RANGE_TABLE) SELECT 1;
17 ERROR: unrecognized EXPLAIN option "range_table"
18 LINE 1: EXPLAIN (RANGE_TABLE) SELECT 1;
19 ^
20 -- Load the module that creates the options.
21 LOAD 'pg_overexplain';
22 -- The first option still does not exist, but the others do.
23 EXPLAIN (DEBUFF) SELECT 1;
24 ERROR: unrecognized EXPLAIN option "debuff"
25 LINE 1: EXPLAIN (DEBUFF) SELECT 1;
26 ^
27 EXPLAIN (DEBUG) SELECT 1;
28 QUERY PLAN
29 ------------------------------------------
30 Result (cost=0.00..0.01 rows=1 width=4)
31 Disabled Nodes: 0
32 Parallel Safe: false
33 Plan Node ID: 0
34 PlannedStmt:
35 Command Type: select
36 Flags: canSetTag
37 Subplans Needing Rewind: none
38 Relation OIDs: none
39 Executor Parameter Types: none
40 Parse Location: 0 to end
41 (11 rows)
42
43 EXPLAIN (RANGE_TABLE) SELECT 1;
44 QUERY PLAN
45 ------------------------------------------
46 Result (cost=0.00..0.01 rows=1 width=4)
47 RTI 1 (result):
48 Eref: "*RESULT*" ()
49 (3 rows)
50
51 -- Create a partitioned table.
52 CREATE TABLE vegetables (id serial, name text, genus text)
53 PARTITION BY LIST (genus);
54 CREATE TABLE daucus PARTITION OF vegetables FOR VALUES IN ('daucus');
55 CREATE TABLE brassica PARTITION OF vegetables FOR VALUES IN ('brassica');
56 INSERT INTO vegetables (name, genus)
57 VALUES ('carrot', 'daucus'), ('bok choy', 'brassica'),
58 ('brocooli', 'brassica'), ('cauliflower', 'brassica'),
59 ('cabbage', 'brassica'), ('kohlrabi', 'brassica'),
60 ('rutabaga', 'brassica'), ('turnip', 'brassica');
61 VACUUM ANALYZE vegetables;
62 -- We filter relation OIDs out of the test output in order to avoid
63 -- test instability. This is currently only needed for EXPLAIN (DEBUG), not
64 -- EXPLAIN (RANGE_TABLE). Also suppress actual row counts, which are not
65 -- stable (e.g. 1/8 is 0.12 on some buildfarm machines and 0.13 on others).
66 CREATE FUNCTION explain_filter(text) RETURNS SETOF text
67 LANGUAGE plpgsql AS
68 $$
69 DECLARE
70 ln text;
71 BEGIN
72 FOR ln IN EXECUTE $1
73 LOOP
74 ln := regexp_replace(ln, 'Relation OIDs:( \m\d+\M)+',
75 'Relation OIDs: NNN...', 'g');
76 ln := regexp_replace(ln, '<Relation-OIDs>( ?\m\d+\M)+</Relation-OIDs>',
77 '<Relation-OIDs>NNN...</Relation-OIDs>', 'g');
78 ln := regexp_replace(ln, 'actual rows=\d+\.\d+',
79 'actual rows=N.NN', 'g');
80 RETURN NEXT ln;
81 END LOOP;
82 END;
83 $$;
84 -- Test with both options together and an aggregate.
85 SELECT explain_filter($$
86 EXPLAIN (DEBUG, RANGE_TABLE, COSTS OFF)
87 SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
88 $$);
89 explain_filter
90 -----------------------------------------------------
91 GroupAggregate
92 Group Key: vegetables.genus
93 Disabled Nodes: 0
94 Parallel Safe: true
95 Plan Node ID: 0
96 -> Sort
97 Sort Key: vegetables.genus, vegetables.name
98 Disabled Nodes: 0
99 Parallel Safe: true
100 Plan Node ID: 1
101 -> Append
102 Disabled Nodes: 0
103 Parallel Safe: true
104 Plan Node ID: 2
105 Append RTIs: 1
106 -> Seq Scan on brassica vegetables_1
107 Disabled Nodes: 0
108 Parallel Safe: true
109 Plan Node ID: 3
110 Scan RTI: 3
111 -> Seq Scan on daucus vegetables_2
112 Disabled Nodes: 0
113 Parallel Safe: true
114 Plan Node ID: 4
115 Scan RTI: 4
116 PlannedStmt:
117 Command Type: select
118 Flags: canSetTag
119 Subplans Needing Rewind: none
120 Relation OIDs: NNN...
121 Executor Parameter Types: none
122 Parse Location: 0 to end
123 RTI 1 (relation, inherited, in-from-clause):
124 Eref: vegetables (id, name, genus)
125 Relation: vegetables
126 Relation Kind: partitioned_table
127 Relation Lock Mode: AccessShareLock
128 Permission Info Index: 1
129 RTI 2 (group):
130 Eref: "*GROUP*" (genus)
131 RTI 3 (relation, in-from-clause):
132 Alias: vegetables (id, name, genus)
133 Eref: vegetables (id, name, genus)
134 Relation: brassica
135 Relation Kind: relation
136 Relation Lock Mode: AccessShareLock
137 RTI 4 (relation, in-from-clause):
138 Alias: vegetables (id, name, genus)
139 Eref: vegetables (id, name, genus)
140 Relation: daucus
141 Relation Kind: relation
142 Relation Lock Mode: AccessShareLock
143 Unprunable RTIs: 1 3 4
144 (53 rows)
145
146 -- Test a different output format.
147 SELECT explain_filter($$
148 EXPLAIN (DEBUG, RANGE_TABLE, FORMAT XML, COSTS OFF)
149 SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
150 $$);
151 explain_filter
152 ---------------------------------------------------------------------
153 <explain xmlns="http://www.postgresql.org/2009/explain"> +
154 <Query> +
155 <Plan> +
156 <Node-Type>Aggregate</Node-Type> +
157 <Strategy>Sorted</Strategy> +
158 <Partial-Mode>Simple</Partial-Mode> +
159 <Parallel-Aware>false</Parallel-Aware> +
160 <Async-Capable>false</Async-Capable> +
161 <Disabled>false</Disabled> +
162 <Group-Key> +
163 <Item>vegetables.genus</Item> +
164 </Group-Key> +
165 <Disabled-Nodes>0</Disabled-Nodes> +
166 <Parallel-Safe>true</Parallel-Safe> +
167 <Plan-Node-ID>0</Plan-Node-ID> +
168 <extParam>none</extParam> +
169 <allParam>none</allParam> +
170 <Plans> +
171 <Plan> +
172 <Node-Type>Sort</Node-Type> +
173 <Parent-Relationship>Outer</Parent-Relationship> +
174 <Parallel-Aware>false</Parallel-Aware> +
175 <Async-Capable>false</Async-Capable> +
176 <Disabled>false</Disabled> +
177 <Sort-Key> +
178 <Item>vegetables.genus</Item> +
179 <Item>vegetables.name</Item> +
180 </Sort-Key> +
181 <Disabled-Nodes>0</Disabled-Nodes> +
182 <Parallel-Safe>true</Parallel-Safe> +
183 <Plan-Node-ID>1</Plan-Node-ID> +
184 <extParam>none</extParam> +
185 <allParam>none</allParam> +
186 <Plans> +
187 <Plan> +
188 <Node-Type>Append</Node-Type> +
189 <Parent-Relationship>Outer</Parent-Relationship> +
190 <Parallel-Aware>false</Parallel-Aware> +
191 <Async-Capable>false</Async-Capable> +
192 <Disabled>false</Disabled> +
193 <Disabled-Nodes>0</Disabled-Nodes> +
194 <Parallel-Safe>true</Parallel-Safe> +
195 <Plan-Node-ID>2</Plan-Node-ID> +
196 <extParam>none</extParam> +
197 <allParam>none</allParam> +
198 <Append-RTIs>1</Append-RTIs> +
199 <Subplans-Removed>0</Subplans-Removed> +
200 <Plans> +
201 <Plan> +
202 <Node-Type>Seq Scan</Node-Type> +
203 <Parent-Relationship>Member</Parent-Relationship>+
204 <Parallel-Aware>false</Parallel-Aware> +
205 <Async-Capable>false</Async-Capable> +
206 <Relation-Name>brassica</Relation-Name> +
207 <Alias>vegetables_1</Alias> +
208 <Disabled>false</Disabled> +
209 <Disabled-Nodes>0</Disabled-Nodes> +
210 <Parallel-Safe>true</Parallel-Safe> +
211 <Plan-Node-ID>3</Plan-Node-ID> +
212 <extParam>none</extParam> +
213 <allParam>none</allParam> +
214 <Scan-RTI>3</Scan-RTI> +
215 </Plan> +
216 <Plan> +
217 <Node-Type>Seq Scan</Node-Type> +
218 <Parent-Relationship>Member</Parent-Relationship>+
219 <Parallel-Aware>false</Parallel-Aware> +
220 <Async-Capable>false</Async-Capable> +
221 <Relation-Name>daucus</Relation-Name> +
222 <Alias>vegetables_2</Alias> +
223 <Disabled>false</Disabled> +
224 <Disabled-Nodes>0</Disabled-Nodes> +
225 <Parallel-Safe>true</Parallel-Safe> +
226 <Plan-Node-ID>4</Plan-Node-ID> +
227 <extParam>none</extParam> +
228 <allParam>none</allParam> +
229 <Scan-RTI>4</Scan-RTI> +
230 </Plan> +
231 </Plans> +
232 </Plan> +
233 </Plans> +
234 </Plan> +
235 </Plans> +
236 </Plan> +
237 <PlannedStmt> +
238 <Command-Type>select</Command-Type> +
239 <Flags>canSetTag</Flags> +
240 <Subplans-Needing-Rewind>none</Subplans-Needing-Rewind> +
241 <Relation-OIDs>NNN...</Relation-OIDs> +
242 <Executor-Parameter-Types>none</Executor-Parameter-Types> +
243 <Parse-Location>0 to end</Parse-Location> +
244 </PlannedStmt> +
245 <Range-Table> +
246 <Range-Table-Entry> +
247 <RTI>1</RTI> +
248 <Kind>relation</Kind> +
249 <Inherited>true</Inherited> +
250 <In-From-Clause>true</In-From-Clause> +
251 <Eref>vegetables (id, name, genus)</Eref> +
252 <Relation>vegetables</Relation> +
253 <Relation-Kind>partitioned_table</Relation-Kind> +
254 <Relation-Lock-Mode>AccessShareLock</Relation-Lock-Mode> +
255 <Permission-Info-Index>1</Permission-Info-Index> +
256 <Security-Barrier>false</Security-Barrier> +
257 <Lateral>false</Lateral> +
258 </Range-Table-Entry> +
259 <Range-Table-Entry> +
260 <RTI>2</RTI> +
261 <Kind>group</Kind> +
262 <Inherited>false</Inherited> +
263 <In-From-Clause>false</In-From-Clause> +
264 <Eref>"*GROUP*" (genus)</Eref> +
265 <Security-Barrier>false</Security-Barrier> +
266 <Lateral>false</Lateral> +
267 </Range-Table-Entry> +
268 <Range-Table-Entry> +
269 <RTI>3</RTI> +
270 <Kind>relation</Kind> +
271 <Inherited>false</Inherited> +
272 <In-From-Clause>true</In-From-Clause> +
273 <Alias>vegetables (id, name, genus)</Alias> +
274 <Eref>vegetables (id, name, genus)</Eref> +
275 <Relation>brassica</Relation> +
276 <Relation-Kind>relation</Relation-Kind> +
277 <Relation-Lock-Mode>AccessShareLock</Relation-Lock-Mode> +
278 <Security-Barrier>false</Security-Barrier> +
279 <Lateral>false</Lateral> +
280 </Range-Table-Entry> +
281 <Range-Table-Entry> +
282 <RTI>4</RTI> +
283 <Kind>relation</Kind> +
284 <Inherited>false</Inherited> +
285 <In-From-Clause>true</In-From-Clause> +
286 <Alias>vegetables (id, name, genus)</Alias> +
287 <Eref>vegetables (id, name, genus)</Eref> +
288 <Relation>daucus</Relation> +
289 <Relation-Kind>relation</Relation-Kind> +
290 <Relation-Lock-Mode>AccessShareLock</Relation-Lock-Mode> +
291 <Security-Barrier>false</Security-Barrier> +
292 <Lateral>false</Lateral> +
293 </Range-Table-Entry> +
294 </Range-Table> +
295 <Unprunable-RTIs>1 3 4</Unprunable-RTIs> +
296 <Result-RTIs>none</Result-RTIs> +
297 </Query> +
298 </explain>
299 (1 row)
300
301 -- Test JSON format with RANGE_TABLE to verify valid JSON structure.
302 SELECT explain_filter($$
303 EXPLAIN (RANGE_TABLE, FORMAT JSON, COSTS OFF)
304 SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
305 $$);
306 explain_filter
307 ----------------------------------------------------------------
308 [ +
309 { +
310 "Plan": { +
311 "Node Type": "Aggregate", +
312 "Strategy": "Sorted", +
313 "Partial Mode": "Simple", +
314 "Parallel Aware": false, +
315 "Async Capable": false, +
316 "Disabled": false, +
317 "Group Key": ["vegetables.genus"], +
318 "Plans": [ +
319 { +
320 "Node Type": "Sort", +
321 "Parent Relationship": "Outer", +
322 "Parallel Aware": false, +
323 "Async Capable": false, +
324 "Disabled": false, +
325 "Sort Key": ["vegetables.genus", "vegetables.name"],+
326 "Plans": [ +
327 { +
328 "Node Type": "Append", +
329 "Parent Relationship": "Outer", +
330 "Parallel Aware": false, +
331 "Async Capable": false, +
332 "Disabled": false, +
333 "Append RTIs": "1", +
334 "Subplans Removed": 0, +
335 "Plans": [ +
336 { +
337 "Node Type": "Seq Scan", +
338 "Parent Relationship": "Member", +
339 "Parallel Aware": false, +
340 "Async Capable": false, +
341 "Relation Name": "brassica", +
342 "Alias": "vegetables_1", +
343 "Disabled": false, +
344 "Scan RTI": 3 +
345 }, +
346 { +
347 "Node Type": "Seq Scan", +
348 "Parent Relationship": "Member", +
349 "Parallel Aware": false, +
350 "Async Capable": false, +
351 "Relation Name": "daucus", +
352 "Alias": "vegetables_2", +
353 "Disabled": false, +
354 "Scan RTI": 4 +
355 } +
356 ] +
357 } +
358 ] +
359 } +
360 ] +
361 }, +
362 "Range Table": [ +
363 { +
364 "RTI": 1, +
365 "Kind": "relation", +
366 "Inherited": true, +
367 "In From Clause": true, +
368 "Eref": "vegetables (id, name, genus)", +
369 "Relation": "vegetables", +
370 "Relation Kind": "partitioned_table", +
371 "Relation Lock Mode": "AccessShareLock", +
372 "Permission Info Index": 1, +
373 "Security Barrier": false, +
374 "Lateral": false +
375 }, +
376 { +
377 "RTI": 2, +
378 "Kind": "group", +
379 "Inherited": false, +
380 "In From Clause": false, +
381 "Eref": "\"*GROUP*\" (genus)", +
382 "Security Barrier": false, +
383 "Lateral": false +
384 }, +
385 { +
386 "RTI": 3, +
387 "Kind": "relation", +
388 "Inherited": false, +
389 "In From Clause": true, +
390 "Alias": "vegetables (id, name, genus)", +
391 "Eref": "vegetables (id, name, genus)", +
392 "Relation": "brassica", +
393 "Relation Kind": "relation", +
394 "Relation Lock Mode": "AccessShareLock", +
395 "Security Barrier": false, +
396 "Lateral": false +
397 }, +
398 { +
399 "RTI": 4, +
400 "Kind": "relation", +
401 "Inherited": false, +
402 "In From Clause": true, +
403 "Alias": "vegetables (id, name, genus)", +
404 "Eref": "vegetables (id, name, genus)", +
405 "Relation": "daucus", +
406 "Relation Kind": "relation", +
407 "Relation Lock Mode": "AccessShareLock", +
408 "Security Barrier": false, +
409 "Lateral": false +
410 } +
411 ], +
412 "Unprunable RTIs": "1 3 4", +
413 "Result RTIs": "none" +
414 } +
415 ]
416 (1 row)
417
418 -- Test just the DEBUG option. Verify that it shows information about
419 -- disabled nodes, parallel safety, and the parallelModeNeeded flag.
420 SET enable_seqscan = false;
421 SET debug_parallel_query = true;
422 SELECT explain_filter($$
423 EXPLAIN (DEBUG, COSTS OFF)
424 SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
425 $$);
426 explain_filter
427 -----------------------------------------------------------
428 Gather
429 Workers Planned: 1
430 Single Copy: true
431 Disabled Nodes: 0
432 Parallel Safe: false
433 Plan Node ID: 0
434 -> GroupAggregate
435 Group Key: vegetables.genus
436 Disabled Nodes: 2
437 Parallel Safe: true
438 Plan Node ID: 1
439 -> Sort
440 Sort Key: vegetables.genus, vegetables.name
441 Disabled Nodes: 2
442 Parallel Safe: true
443 Plan Node ID: 2
444 -> Append
445 Disabled Nodes: 2
446 Parallel Safe: true
447 Plan Node ID: 3
448 -> Seq Scan on brassica vegetables_1
449 Disabled: true
450 Disabled Nodes: 1
451 Parallel Safe: true
452 Plan Node ID: 4
453 -> Seq Scan on daucus vegetables_2
454 Disabled: true
455 Disabled Nodes: 1
456 Parallel Safe: true
457 Plan Node ID: 5
458 PlannedStmt:
459 Command Type: select
460 Flags: canSetTag, parallelModeNeeded
461 Subplans Needing Rewind: none
462 Relation OIDs: NNN...
463 Executor Parameter Types: none
464 Parse Location: 0 to end
465 (37 rows)
466
467 SET debug_parallel_query = false;
468 RESET enable_seqscan;
469 -- Test the DEBUG option with a non-SELECT query, and also verify that the
470 -- hasReturning flag is shown.
471 SELECT explain_filter($$
472 EXPLAIN (DEBUG, COSTS OFF)
473 INSERT INTO vegetables (name, genus)
474 VALUES ('Brotero''s carrot', 'brassica') RETURNING id
475 $$);
476 explain_filter
477 ----------------------------------
478 Insert on vegetables
479 Disabled Nodes: 0
480 Parallel Safe: false
481 Plan Node ID: 0
482 -> Result
483 Disabled Nodes: 0
484 Parallel Safe: false
485 Plan Node ID: 1
486 PlannedStmt:
487 Command Type: insert
488 Flags: hasReturning, canSetTag
489 Subplans Needing Rewind: none
490 Relation OIDs: NNN...
491 Executor Parameter Types: 0
492 Parse Location: 0 to end
493 (15 rows)
494
495 -- Create an index, and then attempt to force a nested loop with inner index
496 -- scan so that we can see parameter-related information. Also, let's try
497 -- actually running the query, but try to suppress potentially variable output.
498 CREATE INDEX ON vegetables (id);
499 ANALYZE vegetables;
500 SET enable_hashjoin = false;
501 SET enable_material = false;
502 SET enable_mergejoin = false;
503 SET enable_seqscan = false;
504 SELECT explain_filter($$
505 EXPLAIN (BUFFERS OFF, COSTS OFF, SUMMARY OFF, TIMING OFF, ANALYZE, DEBUG)
506 SELECT * FROM vegetables v1, vegetables v2 WHERE v1.id = v2.id;
507 $$);
508 explain_filter
509 ------------------------------------------------------------------------------------------
510 Nested Loop (actual rows=N.NN loops=1)
511 Disabled Nodes: 0
512 Parallel Safe: true
513 Plan Node ID: 0
514 -> Append (actual rows=N.NN loops=1)
515 Disabled Nodes: 0
516 Parallel Safe: true
517 Plan Node ID: 1
518 -> Index Scan using brassica_id_idx on brassica v1_1 (actual rows=N.NN loops=1)
519 Index Searches: 1
520 Disabled Nodes: 0
521 Parallel Safe: true
522 Plan Node ID: 2
523 -> Index Scan using daucus_id_idx on daucus v1_2 (actual rows=N.NN loops=1)
524 Index Searches: 1
525 Disabled Nodes: 0
526 Parallel Safe: true
527 Plan Node ID: 3
528 -> Append (actual rows=N.NN loops=8)
529 Disabled Nodes: 0
530 Parallel Safe: true
531 Plan Node ID: 4
532 extParam: 0
533 allParam: 0
534 -> Index Scan using brassica_id_idx on brassica v2_1 (actual rows=N.NN loops=8)
535 Index Cond: (id = v1.id)
536 Index Searches: 8
537 Disabled Nodes: 0
538 Parallel Safe: true
539 Plan Node ID: 5
540 extParam: 0
541 allParam: 0
542 -> Index Scan using daucus_id_idx on daucus v2_2 (actual rows=N.NN loops=8)
543 Index Cond: (id = v1.id)
544 Index Searches: 8
545 Disabled Nodes: 0
546 Parallel Safe: true
547 Plan Node ID: 6
548 extParam: 0
549 allParam: 0
550 PlannedStmt:
551 Command Type: select
552 Flags: canSetTag
553 Subplans Needing Rewind: none
554 Relation OIDs: NNN...
555 Executor Parameter Types: 23
556 Parse Location: 0 to end
557 (47 rows)
558
559 RESET enable_hashjoin;
560 RESET enable_material;
561 RESET enable_mergejoin;
562 RESET enable_seqscan;
563 -- Test the RANGE_TABLE option with a case that allows partition pruning.
564 EXPLAIN (RANGE_TABLE, COSTS OFF)
565 SELECT * FROM vegetables WHERE genus = 'daucus';
566 QUERY PLAN
567 ----------------------------------------------
568 Seq Scan on daucus vegetables
569 Filter: (genus = 'daucus'::text)
570 Scan RTI: 2
571 RTI 1 (relation, inherited, in-from-clause):
572 Eref: vegetables (id, name, genus)
573 Relation: vegetables
574 Relation Kind: partitioned_table
575 Relation Lock Mode: AccessShareLock
576 Permission Info Index: 1
577 RTI 2 (relation, in-from-clause):
578 Alias: vegetables (id, name, genus)
579 Eref: vegetables (id, name, genus)
580 Relation: daucus
581 Relation Kind: relation
582 Relation Lock Mode: AccessShareLock
583 Unprunable RTIs: 1 2
584 (16 rows)
585
586 -- Also test a case that involves a write.
587 EXPLAIN (RANGE_TABLE, COSTS OFF)
588 INSERT INTO vegetables (name, genus) VALUES ('broccoflower', 'brassica');
589 QUERY PLAN
590 ----------------------------------------
591 Insert on vegetables
592 Nominal RTI: 1
593 Exclude Relation RTI: 0
594 -> Result
595 RTI 1 (relation):
596 Eref: vegetables (id, name, genus)
597 Relation: vegetables
598 Relation Kind: partitioned_table
599 Relation Lock Mode: RowExclusiveLock
600 Permission Info Index: 1
601 RTI 2 (result):
602 Eref: "*RESULT*" ()
603 Unprunable RTIs: 1
604 Result RTIs: 1
605 (14 rows)
606