aboutsummaryrefslogtreecommitdiff
path: root/contrib/pg_overexplain/expected/pg_overexplain.out
blob: 6de02323d7cfc6eef94aaa1a21f65b5c0290e44d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
-- These tests display internal details that would not be stable under
-- debug_parallel_query, so make sure that option is disabled.
SET debug_parallel_query = off;
-- Make sure that we don't print any JIT-related information, as that
-- would also make results unstable.
SET jit = off;
-- These options do not exist, so these queries should all fail.
EXPLAIN (DEBUFF) SELECT 1;
ERROR:  unrecognized EXPLAIN option "debuff"
LINE 1: EXPLAIN (DEBUFF) SELECT 1;
                 ^
EXPLAIN (DEBUG) SELECT 1;
ERROR:  unrecognized EXPLAIN option "debug"
LINE 1: EXPLAIN (DEBUG) SELECT 1;
                 ^
EXPLAIN (RANGE_TABLE) SELECT 1;
ERROR:  unrecognized EXPLAIN option "range_table"
LINE 1: EXPLAIN (RANGE_TABLE) SELECT 1;
                 ^
-- Load the module that creates the options.
LOAD 'pg_overexplain';
-- The first option still does not exist, but the others do.
EXPLAIN (DEBUFF) SELECT 1;
ERROR:  unrecognized EXPLAIN option "debuff"
LINE 1: EXPLAIN (DEBUFF) SELECT 1;
                 ^
EXPLAIN (DEBUG) SELECT 1;
                QUERY PLAN                
------------------------------------------
 Result  (cost=0.00..0.01 rows=1 width=4)
   Disabled Nodes: 0
   Parallel Safe: false
   Plan Node ID: 0
 PlannedStmt:
   Command Type: select
   Flags: canSetTag
   Subplans Needing Rewind: none
   Relation OIDs: none
   Executor Parameter Types: none
   Parse Location: 0 to end
(11 rows)

EXPLAIN (RANGE_TABLE) SELECT 1;
                QUERY PLAN                
------------------------------------------
 Result  (cost=0.00..0.01 rows=1 width=4)
 RTI 1 (result):
   Eref: "*RESULT*" ()
(3 rows)

-- Create a partitioned table.
CREATE TABLE vegetables (id serial, name text, genus text)
PARTITION BY LIST (genus);
CREATE TABLE daucus PARTITION OF vegetables FOR VALUES IN ('daucus');
CREATE TABLE brassica PARTITION OF vegetables FOR VALUES IN ('brassica');
INSERT INTO vegetables (name, genus)
	VALUES ('carrot', 'daucus'), ('bok choy', 'brassica'),
		   ('brocooli', 'brassica'), ('cauliflower', 'brassica'),
		   ('cabbage', 'brassica'), ('kohlrabi', 'brassica'),
		   ('rutabaga', 'brassica'), ('turnip', 'brassica');
VACUUM ANALYZE vegetables;
-- We filter relation OIDs out of the test output in order to avoid
-- test instability. This is currently only needed for EXPLAIN (DEBUG), not
-- EXPLAIN (RANGE_TABLE). Also suppress actual row counts, which are not
-- stable (e.g. 1/8 is 0.12 on some buildfarm machines and 0.13 on others).
CREATE FUNCTION explain_filter(text) RETURNS SETOF text
LANGUAGE plpgsql AS
$$
DECLARE
    ln text;
BEGIN
    FOR ln IN EXECUTE $1
	LOOP
		ln := regexp_replace(ln, 'Relation OIDs:( \m\d+\M)+',
								 'Relation OIDs: NNN...', 'g');
		ln := regexp_replace(ln, '<Relation-OIDs>( ?\m\d+\M)+</Relation-OIDs>',
								 '<Relation-OIDs>NNN...</Relation-OIDs>', 'g');
		ln := regexp_replace(ln, 'actual rows=\d+\.\d+',
								 'actual rows=N.NN', 'g');
		RETURN NEXT ln;
	END LOOP;
END;
$$;
-- Test with both options together and an aggregate.
SELECT explain_filter($$
EXPLAIN (DEBUG, RANGE_TABLE, COSTS OFF)
SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
$$);
                   explain_filter                    
-----------------------------------------------------
 GroupAggregate
   Group Key: vegetables.genus
   Disabled Nodes: 0
   Parallel Safe: true
   Plan Node ID: 0
   ->  Sort
         Sort Key: vegetables.genus, vegetables.name
         Disabled Nodes: 0
         Parallel Safe: true
         Plan Node ID: 1
         ->  Append
               Disabled Nodes: 0
               Parallel Safe: true
               Plan Node ID: 2
               Append RTIs: 1
               ->  Seq Scan on brassica vegetables_1
                     Disabled Nodes: 0
                     Parallel Safe: true
                     Plan Node ID: 3
                     Scan RTI: 3
               ->  Seq Scan on daucus vegetables_2
                     Disabled Nodes: 0
                     Parallel Safe: true
                     Plan Node ID: 4
                     Scan RTI: 4
 PlannedStmt:
   Command Type: select
   Flags: canSetTag
   Subplans Needing Rewind: none
   Relation OIDs: NNN...
   Executor Parameter Types: none
   Parse Location: 0 to end
 RTI 1 (relation, inherited, in-from-clause):
   Eref: vegetables (id, name, genus)
   Relation: vegetables
   Relation Kind: partitioned_table
   Relation Lock Mode: AccessShareLock
   Permission Info Index: 1
 RTI 2 (group):
   Eref: "*GROUP*" (genus)
 RTI 3 (relation, in-from-clause):
   Alias: vegetables (id, name, genus)
   Eref: vegetables (id, name, genus)
   Relation: brassica
   Relation Kind: relation
   Relation Lock Mode: AccessShareLock
 RTI 4 (relation, in-from-clause):
   Alias: vegetables (id, name, genus)
   Eref: vegetables (id, name, genus)
   Relation: daucus
   Relation Kind: relation
   Relation Lock Mode: AccessShareLock
 Unprunable RTIs: 1 3 4
(53 rows)

-- Test a different output format.
SELECT explain_filter($$
EXPLAIN (DEBUG, RANGE_TABLE, FORMAT XML, COSTS OFF)
SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
$$);
                           explain_filter                            
---------------------------------------------------------------------
 <explain xmlns="http://www.postgresql.org/2009/explain">           +
   <Query>                                                          +
     <Plan>                                                         +
       <Node-Type>Aggregate</Node-Type>                             +
       <Strategy>Sorted</Strategy>                                  +
       <Partial-Mode>Simple</Partial-Mode>                          +
       <Parallel-Aware>false</Parallel-Aware>                       +
       <Async-Capable>false</Async-Capable>                         +
       <Disabled>false</Disabled>                                   +
       <Group-Key>                                                  +
         <Item>vegetables.genus</Item>                              +
       </Group-Key>                                                 +
       <Disabled-Nodes>0</Disabled-Nodes>                           +
       <Parallel-Safe>true</Parallel-Safe>                          +
       <Plan-Node-ID>0</Plan-Node-ID>                               +
       <extParam>none</extParam>                                    +
       <allParam>none</allParam>                                    +
       <Plans>                                                      +
         <Plan>                                                     +
           <Node-Type>Sort</Node-Type>                              +
           <Parent-Relationship>Outer</Parent-Relationship>         +
           <Parallel-Aware>false</Parallel-Aware>                   +
           <Async-Capable>false</Async-Capable>                     +
           <Disabled>false</Disabled>                               +
           <Sort-Key>                                               +
             <Item>vegetables.genus</Item>                          +
             <Item>vegetables.name</Item>                           +
           </Sort-Key>                                              +
           <Disabled-Nodes>0</Disabled-Nodes>                       +
           <Parallel-Safe>true</Parallel-Safe>                      +
           <Plan-Node-ID>1</Plan-Node-ID>                           +
           <extParam>none</extParam>                                +
           <allParam>none</allParam>                                +
           <Plans>                                                  +
             <Plan>                                                 +
               <Node-Type>Append</Node-Type>                        +
               <Parent-Relationship>Outer</Parent-Relationship>     +
               <Parallel-Aware>false</Parallel-Aware>               +
               <Async-Capable>false</Async-Capable>                 +
               <Disabled>false</Disabled>                           +
               <Disabled-Nodes>0</Disabled-Nodes>                   +
               <Parallel-Safe>true</Parallel-Safe>                  +
               <Plan-Node-ID>2</Plan-Node-ID>                       +
               <extParam>none</extParam>                            +
               <allParam>none</allParam>                            +
               <Append-RTIs>1</Append-RTIs>                         +
               <Subplans-Removed>0</Subplans-Removed>               +
               <Plans>                                              +
                 <Plan>                                             +
                   <Node-Type>Seq Scan</Node-Type>                  +
                   <Parent-Relationship>Member</Parent-Relationship>+
                   <Parallel-Aware>false</Parallel-Aware>           +
                   <Async-Capable>false</Async-Capable>             +
                   <Relation-Name>brassica</Relation-Name>          +
                   <Alias>vegetables_1</Alias>                      +
                   <Disabled>false</Disabled>                       +
                   <Disabled-Nodes>0</Disabled-Nodes>               +
                   <Parallel-Safe>true</Parallel-Safe>              +
                   <Plan-Node-ID>3</Plan-Node-ID>                   +
                   <extParam>none</extParam>                        +
                   <allParam>none</allParam>                        +
                   <Scan-RTI>3</Scan-RTI>                           +
                 </Plan>                                            +
                 <Plan>                                             +
                   <Node-Type>Seq Scan</Node-Type>                  +
                   <Parent-Relationship>Member</Parent-Relationship>+
                   <Parallel-Aware>false</Parallel-Aware>           +
                   <Async-Capable>false</Async-Capable>             +
                   <Relation-Name>daucus</Relation-Name>            +
                   <Alias>vegetables_2</Alias>                      +
                   <Disabled>false</Disabled>                       +
                   <Disabled-Nodes>0</Disabled-Nodes>               +
                   <Parallel-Safe>true</Parallel-Safe>              +
                   <Plan-Node-ID>4</Plan-Node-ID>                   +
                   <extParam>none</extParam>                        +
                   <allParam>none</allParam>                        +
                   <Scan-RTI>4</Scan-RTI>                           +
                 </Plan>                                            +
               </Plans>                                             +
             </Plan>                                                +
           </Plans>                                                 +
         </Plan>                                                    +
       </Plans>                                                     +
     </Plan>                                                        +
     <PlannedStmt>                                                  +
       <Command-Type>select</Command-Type>                          +
       <Flags>canSetTag</Flags>                                     +
       <Subplans-Needing-Rewind>none</Subplans-Needing-Rewind>      +
       <Relation-OIDs>NNN...</Relation-OIDs>                        +
       <Executor-Parameter-Types>none</Executor-Parameter-Types>    +
       <Parse-Location>0 to end</Parse-Location>                    +
     </PlannedStmt>                                                 +
     <Range-Table>                                                  +
       <Range-Table-Entry>                                          +
         <RTI>1</RTI>                                               +
         <Kind>relation</Kind>                                      +
         <Inherited>true</Inherited>                                +
         <In-From-Clause>true</In-From-Clause>                      +
         <Eref>vegetables (id, name, genus)</Eref>                  +
         <Relation>vegetables</Relation>                            +
         <Relation-Kind>partitioned_table</Relation-Kind>           +
         <Relation-Lock-Mode>AccessShareLock</Relation-Lock-Mode>   +
         <Permission-Info-Index>1</Permission-Info-Index>           +
         <Security-Barrier>false</Security-Barrier>                 +
         <Lateral>false</Lateral>                                   +
       </Range-Table-Entry>                                         +
       <Range-Table-Entry>                                          +
         <RTI>2</RTI>                                               +
         <Kind>group</Kind>                                         +
         <Inherited>false</Inherited>                               +
         <In-From-Clause>false</In-From-Clause>                     +
         <Eref>"*GROUP*" (genus)</Eref>                             +
         <Security-Barrier>false</Security-Barrier>                 +
         <Lateral>false</Lateral>                                   +
       </Range-Table-Entry>                                         +
       <Range-Table-Entry>                                          +
         <RTI>3</RTI>                                               +
         <Kind>relation</Kind>                                      +
         <Inherited>false</Inherited>                               +
         <In-From-Clause>true</In-From-Clause>                      +
         <Alias>vegetables (id, name, genus)</Alias>                +
         <Eref>vegetables (id, name, genus)</Eref>                  +
         <Relation>brassica</Relation>                              +
         <Relation-Kind>relation</Relation-Kind>                    +
         <Relation-Lock-Mode>AccessShareLock</Relation-Lock-Mode>   +
         <Security-Barrier>false</Security-Barrier>                 +
         <Lateral>false</Lateral>                                   +
       </Range-Table-Entry>                                         +
       <Range-Table-Entry>                                          +
         <RTI>4</RTI>                                               +
         <Kind>relation</Kind>                                      +
         <Inherited>false</Inherited>                               +
         <In-From-Clause>true</In-From-Clause>                      +
         <Alias>vegetables (id, name, genus)</Alias>                +
         <Eref>vegetables (id, name, genus)</Eref>                  +
         <Relation>daucus</Relation>                                +
         <Relation-Kind>relation</Relation-Kind>                    +
         <Relation-Lock-Mode>AccessShareLock</Relation-Lock-Mode>   +
         <Security-Barrier>false</Security-Barrier>                 +
         <Lateral>false</Lateral>                                   +
       </Range-Table-Entry>                                         +
       <Unprunable-RTIs>1 3 4</Unprunable-RTIs>                     +
       <Result-RTIs>none</Result-RTIs>                              +
     </Range-Table>                                                 +
   </Query>                                                         +
 </explain>
(1 row)

-- Test just the DEBUG option. Verify that it shows information about
-- disabled nodes, parallel safety, and the parallelModeNeeded flag.
SET enable_seqscan = false;
SET debug_parallel_query = true;
SELECT explain_filter($$
EXPLAIN (DEBUG, COSTS OFF)
SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
$$);
                      explain_filter                       
-----------------------------------------------------------
 Gather
   Workers Planned: 1
   Single Copy: true
   Disabled Nodes: 0
   Parallel Safe: false
   Plan Node ID: 0
   ->  GroupAggregate
         Group Key: vegetables.genus
         Disabled Nodes: 2
         Parallel Safe: true
         Plan Node ID: 1
         ->  Sort
               Sort Key: vegetables.genus, vegetables.name
               Disabled Nodes: 2
               Parallel Safe: true
               Plan Node ID: 2
               ->  Append
                     Disabled Nodes: 2
                     Parallel Safe: true
                     Plan Node ID: 3
                     ->  Seq Scan on brassica vegetables_1
                           Disabled: true
                           Disabled Nodes: 1
                           Parallel Safe: true
                           Plan Node ID: 4
                     ->  Seq Scan on daucus vegetables_2
                           Disabled: true
                           Disabled Nodes: 1
                           Parallel Safe: true
                           Plan Node ID: 5
 PlannedStmt:
   Command Type: select
   Flags: canSetTag, parallelModeNeeded
   Subplans Needing Rewind: none
   Relation OIDs: NNN...
   Executor Parameter Types: none
   Parse Location: 0 to end
(37 rows)

SET debug_parallel_query = false;
RESET enable_seqscan;
-- Test the DEBUG option with a non-SELECT query, and also verify that the
-- hasReturning flag is shown.
SELECT explain_filter($$
EXPLAIN (DEBUG, COSTS OFF)
INSERT INTO vegetables (name, genus)
	VALUES ('Brotero''s carrot', 'brassica') RETURNING id
$$);
          explain_filter          
----------------------------------
 Insert on vegetables
   Disabled Nodes: 0
   Parallel Safe: false
   Plan Node ID: 0
   ->  Result
         Disabled Nodes: 0
         Parallel Safe: false
         Plan Node ID: 1
 PlannedStmt:
   Command Type: insert
   Flags: hasReturning, canSetTag
   Subplans Needing Rewind: none
   Relation OIDs: NNN...
   Executor Parameter Types: 0
   Parse Location: 0 to end
(15 rows)

-- Create an index, and then attempt to force a nested loop with inner index
-- scan so that we can see parameter-related information. Also, let's try
-- actually running the query, but try to suppress potentially variable output.
CREATE INDEX ON vegetables (id);
ANALYZE vegetables;
SET enable_hashjoin = false;
SET enable_material = false;
SET enable_mergejoin = false;
SET enable_seqscan = false;
SELECT explain_filter($$
EXPLAIN (BUFFERS OFF, COSTS OFF, SUMMARY OFF, TIMING OFF, ANALYZE, DEBUG)
SELECT * FROM vegetables v1, vegetables v2 WHERE v1.id = v2.id;
$$);
                                      explain_filter                                      
------------------------------------------------------------------------------------------
 Nested Loop (actual rows=N.NN loops=1)
   Disabled Nodes: 0
   Parallel Safe: true
   Plan Node ID: 0
   ->  Append (actual rows=N.NN loops=1)
         Disabled Nodes: 0
         Parallel Safe: true
         Plan Node ID: 1
         ->  Index Scan using brassica_id_idx on brassica v1_1 (actual rows=N.NN loops=1)
               Index Searches: 1
               Disabled Nodes: 0
               Parallel Safe: true
               Plan Node ID: 2
         ->  Index Scan using daucus_id_idx on daucus v1_2 (actual rows=N.NN loops=1)
               Index Searches: 1
               Disabled Nodes: 0
               Parallel Safe: true
               Plan Node ID: 3
   ->  Append (actual rows=N.NN loops=8)
         Disabled Nodes: 0
         Parallel Safe: true
         Plan Node ID: 4
         extParam: 0
         allParam: 0
         ->  Index Scan using brassica_id_idx on brassica v2_1 (actual rows=N.NN loops=8)
               Index Cond: (id = v1.id)
               Index Searches: 8
               Disabled Nodes: 0
               Parallel Safe: true
               Plan Node ID: 5
               extParam: 0
               allParam: 0
         ->  Index Scan using daucus_id_idx on daucus v2_2 (actual rows=N.NN loops=8)
               Index Cond: (id = v1.id)
               Index Searches: 8
               Disabled Nodes: 0
               Parallel Safe: true
               Plan Node ID: 6
               extParam: 0
               allParam: 0
 PlannedStmt:
   Command Type: select
   Flags: canSetTag
   Subplans Needing Rewind: none
   Relation OIDs: NNN...
   Executor Parameter Types: 23
   Parse Location: 0 to end
(47 rows)

RESET enable_hashjoin;
RESET enable_material;
RESET enable_mergejoin;
RESET enable_seqscan;
-- Test the RANGE_TABLE option with a case that allows partition pruning.
EXPLAIN (RANGE_TABLE, COSTS OFF)
SELECT * FROM vegetables WHERE genus = 'daucus';
                  QUERY PLAN                  
----------------------------------------------
 Seq Scan on daucus vegetables
   Filter: (genus = 'daucus'::text)
   Scan RTI: 2
 RTI 1 (relation, inherited, in-from-clause):
   Eref: vegetables (id, name, genus)
   Relation: vegetables
   Relation Kind: partitioned_table
   Relation Lock Mode: AccessShareLock
   Permission Info Index: 1
 RTI 2 (relation, in-from-clause):
   Alias: vegetables (id, name, genus)
   Eref: vegetables (id, name, genus)
   Relation: daucus
   Relation Kind: relation
   Relation Lock Mode: AccessShareLock
 Unprunable RTIs: 1 2
(16 rows)

-- Also test a case that involves a write.
EXPLAIN (RANGE_TABLE, COSTS OFF)
INSERT INTO vegetables (name, genus) VALUES ('broccoflower', 'brassica');
               QUERY PLAN               
----------------------------------------
 Insert on vegetables
   Nominal RTI: 1
   Exclude Relation RTI: 0
   ->  Result
 RTI 1 (relation):
   Eref: vegetables (id, name, genus)
   Relation: vegetables
   Relation Kind: partitioned_table
   Relation Lock Mode: RowExclusiveLock
   Permission Info Index: 1
 RTI 2 (result):
   Eref: "*RESULT*" ()
 Unprunable RTIs: 1
 Result RTIs: 1
(14 rows)