OSDN Git Service

リグレッションテストを追加した。
[pghintplan/pg_hint_plan.git] / expected / pg_hint_plan.out
1 CREATE TABLE t1 (val1 int, val2 int);
2 CREATE TABLE t2 (val1 int, val2 int);
3 CREATE TABLE t3 (val1 int, val2 int);
4 CREATE TABLE t4 (val1 int, val2 int);
5 CREATE VIEW v1 AS SELECT val1, val2 FROM t1;
6 CREATE VIEW v2 AS SELECT t1.val1 t1_val1, t1.val2 t1_val2, t2.val1 t2_val1, t2.val2 t2_val2 FROM t1, t2 WHERE t1.val1 = t2.val1;
7 CREATE VIEW v3 AS SELECT t_1.val1 t1_val1, t_1.val2 t1_val2, t_2.val1 t2_val1, t_2.val2 t2_val2 FROM t1 t_1, t2 t_2 WHERE t_1.val1 = t_2.val1;
8 CREATE VIEW v4 AS SELECT v_2.t1_val1, t_3.val1 FROM v2 v_2, t3 t_3 WHERE v_2.t1_val1 = t_3.val1;
9 INSERT INTO t1 SELECT i, i FROM (SELECT generate_series(1, 10000) i) t;
10 INSERT INTO t2 SELECT i, i FROM (SELECT generate_series(1, 1000) i) t;
11 INSERT INTO t3 SELECT i, i FROM (SELECT generate_series(1, 100) i) t;
12 INSERT INTO t4 SELECT i, i FROM (SELECT generate_series(1, 10) i) t;
13 CREATE INDEX t1_val1 ON t1 (val1);
14 CREATE INDEX t2_val1 ON t2 (val1);
15 CREATE INDEX t3_val1 ON t3 (val1);
16 CREATE INDEX t4_val1 ON t4 (val1);
17 ANALYZE t1;
18 ANALYZE t2;
19 ANALYZE t3;
20 ANALYZE t4;
21 \set t1_oid `psql contrib_regression -tA -c "SELECT oid FROM pg_class WHERE relname = 't1'"`
22 \set t2_oid `psql contrib_regression -tA -c "SELECT oid FROM pg_class WHERE relname = 't2'"`
23 \set t3_oid `psql contrib_regression -tA -c "SELECT oid FROM pg_class WHERE relname = 't3'"`
24 \set t4_oid `psql contrib_regression -tA -c "SELECT oid FROM pg_class WHERE relname = 't4'"`
25 --SET enable_bitmapscan TO off;
26 --SET enable_hashagg TO off;
27 --SET enable_tidscan TO off;
28 --SET enable_sort TO off;
29 --SET enable_indexscan TO off;
30 --SET enable_seqscan TO off;
31 --SET enable_material TO off;
32 --SET enable_hashjoin TO off;
33 --SET enable_mergejoin TO off;
34 --SET enable_nestloop TO off;
35 SET join_collapse_limit TO 1;
36 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val1 = t2.val1;
37                                   QUERY PLAN                                  
38 ------------------------------------------------------------------------------
39  Merge Join  (cost=0.00..90.08 rows=1000 width=16)
40    Merge Cond: (t1.val1 = t2.val1)
41    ->  Index Scan using t1_val1 on t1  (cost=0.00..318.26 rows=10000 width=8)
42    ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
43 (4 rows)
44
45 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val2 = t2.val2;
46                             QUERY PLAN                            
47 ------------------------------------------------------------------
48  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
49    Hash Cond: (t1.val2 = t2.val2)
50    ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
51    ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
52          ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
53 (5 rows)
54
55 EXPLAIN SELECT * FROM t1 CROSS JOIN t2 CROSS JOIN t3 CROSS JOIN t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
56                                         QUERY PLAN                                        
57 ------------------------------------------------------------------------------------------
58  Merge Join  (cost=1.27..2.83 rows=1 width=32)
59    Merge Cond: (t1.val1 = t4.val1)
60    ->  Merge Join  (cost=0.00..15.03 rows=10 width=24)
61          Merge Cond: (t1.val1 = t3.val1)
62          ->  Merge Join  (cost=0.00..90.08 rows=1000 width=16)
63                Merge Cond: (t1.val1 = t2.val1)
64                ->  Index Scan using t1_val1 on t1  (cost=0.00..318.26 rows=10000 width=8)
65                ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
66          ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
67    ->  Sort  (cost=1.27..1.29 rows=10 width=8)
68          Sort Key: t4.val1
69          ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
70 (12 rows)
71
72 EXPLAIN SELECT * FROM t4 CROSS JOIN t3 CROSS JOIN t2 CROSS JOIN t1 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
73                                       QUERY PLAN                                       
74 ---------------------------------------------------------------------------------------
75  Nested Loop  (cost=1.27..13.30 rows=10 width=32)
76    ->  Merge Join  (cost=1.27..7.38 rows=10 width=24)
77          Merge Cond: (t3.val1 = t2.val1)
78          ->  Merge Join  (cost=1.27..2.68 rows=10 width=16)
79                Merge Cond: (t3.val1 = t4.val1)
80                ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
81                ->  Sort  (cost=1.27..1.29 rows=10 width=8)
82                      Sort Key: t4.val1
83                      ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
84          ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
85    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
86          Index Cond: (val1 = t2.val1)
87 (12 rows)
88
89 EXPLAIN SELECT * FROM t2 CROSS JOIN t3 CROSS JOIN t4 CROSS JOIN t1 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
90                                        QUERY PLAN                                       
91 ----------------------------------------------------------------------------------------
92  Nested Loop  (cost=1.27..2.12 rows=1 width=32)
93    ->  Merge Join  (cost=1.27..1.52 rows=1 width=24)
94          Merge Cond: (t2.val1 = t4.val1)
95          ->  Merge Join  (cost=0.00..19.58 rows=100 width=16)
96                Merge Cond: (t2.val1 = t3.val1)
97                ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
98                ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
99          ->  Sort  (cost=1.27..1.29 rows=10 width=8)
100                Sort Key: t4.val1
101                ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
102    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
103          Index Cond: (val1 = t2.val1)
104 (12 rows)
105
106 CREATE EXTENSION pg_hint_plan;
107 SELECT pg_add_hint('nest(' || :t1_oid || ',' || :t2_oid || ')');
108  pg_add_hint 
109 -------------
110            1
111 (1 row)
112
113 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val1 = t2.val1;
114                                QUERY PLAN                               
115 ------------------------------------------------------------------------
116  Nested Loop  (cost=0.00..607.00 rows=1000 width=16)
117    ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
118    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
119          Index Cond: (val1 = t2.val1)
120 (4 rows)
121
122 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val2 = t2.val2;
123                             QUERY PLAN                            
124 ------------------------------------------------------------------
125  Nested Loop  (cost=0.00..150162.50 rows=1000 width=16)
126    Join Filter: (t1.val2 = t2.val2)
127    ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
128    ->  Materialize  (cost=0.00..20.00 rows=1000 width=8)
129          ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
130 (5 rows)
131
132 SELECT pg_add_hint('hash(' || :t1_oid || ',' || :t2_oid || ')');
133  pg_add_hint 
134 -------------
135            1
136 (1 row)
137
138 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val1 = t2.val1;
139                             QUERY PLAN                            
140 ------------------------------------------------------------------
141  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
142    Hash Cond: (t1.val1 = t2.val1)
143    ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
144    ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
145          ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
146 (5 rows)
147
148 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val2 = t2.val2;
149                             QUERY PLAN                            
150 ------------------------------------------------------------------
151  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
152    Hash Cond: (t1.val2 = t2.val2)
153    ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
154    ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
155          ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
156 (5 rows)
157
158 SELECT pg_add_hint('merge(' || :t1_oid || ',' || :t2_oid || ')');
159  pg_add_hint 
160 -------------
161            1
162 (1 row)
163
164 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val1 = t2.val1;
165                                   QUERY PLAN                                  
166 ------------------------------------------------------------------------------
167  Merge Join  (cost=0.00..90.08 rows=1000 width=16)
168    Merge Cond: (t1.val1 = t2.val1)
169    ->  Index Scan using t1_val1 on t1  (cost=0.00..318.26 rows=10000 width=8)
170    ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
171 (4 rows)
172
173 EXPLAIN SELECT * FROM t1, t2 WHERE t1.val2 = t2.val2;
174                              QUERY PLAN                             
175 --------------------------------------------------------------------
176  Merge Join  (cost=874.21..894.21 rows=1000 width=16)
177    Merge Cond: (t1.val2 = t2.val2)
178    ->  Sort  (cost=809.39..834.39 rows=10000 width=8)
179          Sort Key: t1.val2
180          ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
181    ->  Sort  (cost=64.83..67.33 rows=1000 width=8)
182          Sort Key: t2.val2
183          ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
184 (8 rows)
185
186 SELECT pg_clear_hint();
187  pg_clear_hint 
188 ---------------
189            201
190 (1 row)
191
192 EXPLAIN SELECT * FROM t1, t2, t3 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1;
193                                      QUERY PLAN                                     
194 ------------------------------------------------------------------------------------
195  Merge Join  (cost=5.32..6.85 rows=10 width=24)
196    Merge Cond: (t1.val1 = t3.val1)
197    ->  Merge Join  (cost=0.00..90.08 rows=1000 width=16)
198          Merge Cond: (t1.val1 = t2.val1)
199          ->  Index Scan using t1_val1 on t1  (cost=0.00..318.26 rows=10000 width=8)
200          ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
201    ->  Sort  (cost=5.32..5.57 rows=100 width=8)
202          Sort Key: t3.val1
203          ->  Seq Scan on t3  (cost=0.00..2.00 rows=100 width=8)
204 (9 rows)
205
206 EXPLAIN SELECT * FROM t1, t2, t3 WHERE t1.val2 = t2.val2 AND t2.val2 = t3.val2;
207                                  QUERY PLAN                                 
208 ----------------------------------------------------------------------------
209  Hash Join  (cost=24.25..207.75 rows=10 width=24)
210    Hash Cond: (t1.val2 = t2.val2)
211    ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
212    ->  Hash  (cost=23.00..23.00 rows=100 width=16)
213          ->  Hash Join  (cost=3.25..23.00 rows=100 width=16)
214                Hash Cond: (t2.val2 = t3.val2)
215                ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
216                ->  Hash  (cost=2.00..2.00 rows=100 width=8)
217                      ->  Seq Scan on t3  (cost=0.00..2.00 rows=100 width=8)
218 (9 rows)
219
220 SELECT pg_add_hint('nest(' || :t1_oid || ',' || :t2_oid ||  ',' || :t3_oid || ')');
221  pg_add_hint 
222 -------------
223            1
224 (1 row)
225
226 SELECT pg_add_hint('nest(' || :t1_oid || ',' || :t3_oid || ')');
227  pg_add_hint 
228 -------------
229            1
230 (1 row)
231
232 --SELECT pg_add_hint('no_merge(' || :t1_oid || ',' || :t3_oid || ')');
233 EXPLAIN SELECT * FROM t1, t2, t3 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1;
234                                     QUERY PLAN                                    
235 ----------------------------------------------------------------------------------
236  Nested Loop  (cost=5.32..70.60 rows=10 width=24)
237    ->  Merge Join  (cost=5.32..11.40 rows=100 width=16)
238          Merge Cond: (t2.val1 = t3.val1)
239          ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
240          ->  Sort  (cost=5.32..5.57 rows=100 width=8)
241                Sort Key: t3.val1
242                ->  Seq Scan on t3  (cost=0.00..2.00 rows=100 width=8)
243    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
244          Index Cond: (val1 = t2.val1)
245 (9 rows)
246
247 EXPLAIN SELECT * FROM t1, t2, t3 WHERE t1.val2 = t2.val2 AND t2.val2 = t3.val2;
248                                QUERY PLAN                               
249 ------------------------------------------------------------------------
250  Nested Loop  (cost=27.50..1722.25 rows=10 width=24)
251    Join Filter: (t1.val2 = t3.val2)
252    ->  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
253          Hash Cond: (t1.val2 = t2.val2)
254          ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
255          ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
256                ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
257    ->  Materialize  (cost=0.00..2.50 rows=100 width=8)
258          ->  Seq Scan on t3  (cost=0.00..2.00 rows=100 width=8)
259 (9 rows)
260
261 SELECT pg_clear_hint();
262  pg_clear_hint 
263 ---------------
264            201
265 (1 row)
266
267 EXPLAIN SELECT * FROM t1, t2, t3, t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
268                                         QUERY PLAN                                        
269 ------------------------------------------------------------------------------------------
270  Nested Loop  (cost=1.27..1.70 rows=1 width=32)
271    ->  Merge Join  (cost=1.27..1.42 rows=1 width=24)
272          Merge Cond: (t1.val1 = t4.val1)
273          ->  Merge Join  (cost=0.00..90.08 rows=1000 width=16)
274                Merge Cond: (t1.val1 = t2.val1)
275                ->  Index Scan using t1_val1 on t1  (cost=0.00..318.26 rows=10000 width=8)
276                ->  Index Scan using t2_val1 on t2  (cost=0.00..43.25 rows=1000 width=8)
277          ->  Sort  (cost=1.27..1.29 rows=10 width=8)
278                Sort Key: t4.val1
279                ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
280    ->  Index Scan using t3_val1 on t3  (cost=0.00..0.27 rows=1 width=8)
281          Index Cond: (val1 = t1.val1)
282 (12 rows)
283
284 SELECT pg_add_hint('no_merge(' || :t1_oid || ',' || :t2_oid || ')');
285  pg_add_hint 
286 -------------
287            1
288 (1 row)
289
290 EXPLAIN SELECT * FROM t1, t2, t3, t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
291                                         QUERY PLAN                                        
292 ------------------------------------------------------------------------------------------
293  Nested Loop  (cost=1.27..1.80 rows=1 width=32)
294    ->  Merge Join  (cost=1.27..1.51 rows=1 width=24)
295          Merge Cond: (t1.val1 = t4.val1)
296          ->  Merge Join  (cost=0.00..18.43 rows=100 width=16)
297                Merge Cond: (t1.val1 = t3.val1)
298                ->  Index Scan using t1_val1 on t1  (cost=0.00..318.26 rows=10000 width=8)
299                ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
300          ->  Sort  (cost=1.27..1.29 rows=10 width=8)
301                Sort Key: t4.val1
302                ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
303    ->  Index Scan using t2_val1 on t2  (cost=0.00..0.27 rows=1 width=8)
304          Index Cond: (val1 = t1.val1)
305 (12 rows)
306
307 SET enable_mergejoin TO off;
308 EXPLAIN SELECT * FROM t1, t2, t3, t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
309                                   QUERY PLAN                                  
310 ------------------------------------------------------------------------------
311  Nested Loop  (cost=1.23..11.11 rows=1 width=32)
312    ->  Nested Loop  (cost=1.23..10.52 rows=1 width=24)
313          ->  Hash Join  (cost=1.23..3.70 rows=10 width=16)
314                Hash Cond: (t3.val1 = t4.val1)
315                ->  Seq Scan on t3  (cost=0.00..2.00 rows=100 width=8)
316                ->  Hash  (cost=1.10..1.10 rows=10 width=8)
317                      ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
318          ->  Index Scan using t2_val1 on t2  (cost=0.00..0.67 rows=1 width=8)
319                Index Cond: (val1 = t3.val1)
320    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
321          Index Cond: (val1 = t2.val1)
322 (11 rows)
323
324 SELECT pg_add_hint('no_hash(' || :t3_oid || ',' || :t4_oid || ')');
325  pg_add_hint 
326 -------------
327            1
328 (1 row)
329
330 EXPLAIN SELECT * FROM t1, t2, t3, t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
331                                       QUERY PLAN                                       
332 ---------------------------------------------------------------------------------------
333  Nested Loop  (cost=1.27..10.09 rows=1 width=32)
334    ->  Nested Loop  (cost=1.27..9.50 rows=1 width=24)
335          ->  Merge Join  (cost=1.27..2.68 rows=10 width=16)
336                Merge Cond: (t3.val1 = t4.val1)
337                ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
338                ->  Sort  (cost=1.27..1.29 rows=10 width=8)
339                      Sort Key: t4.val1
340                      ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
341          ->  Index Scan using t2_val1 on t2  (cost=0.00..0.67 rows=1 width=8)
342                Index Cond: (val1 = t3.val1)
343    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
344          Index Cond: (val1 = t2.val1)
345 (12 rows)
346
347 SELECT pg_add_hint('no_nest(' || :t2_oid || ',' || :t3_oid || ',' || :t4_oid || ')');
348  pg_add_hint 
349 -------------
350            1
351 (1 row)
352
353 EXPLAIN SELECT * FROM t1, t2, t3, t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
354                                       QUERY PLAN                                       
355 ---------------------------------------------------------------------------------------
356  Nested Loop  (cost=1.27..2.74 rows=1 width=32)
357    ->  Merge Join  (cost=1.27..2.15 rows=1 width=24)
358          Merge Cond: (t2.val1 = t4.val1)
359          ->  Nested Loop  (cost=0.00..81.95 rows=100 width=16)
360                ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
361                ->  Index Scan using t2_val1 on t2  (cost=0.00..0.67 rows=1 width=8)
362                      Index Cond: (val1 = t3.val1)
363          ->  Sort  (cost=1.27..1.29 rows=10 width=8)
364                Sort Key: t4.val1
365                ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
366    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
367          Index Cond: (val1 = t2.val1)
368 (12 rows)
369
370 SET join_collapse_limit TO 10;
371 EXPLAIN SELECT * FROM t1 CROSS JOIN t2 CROSS JOIN t3 CROSS JOIN t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
372                                       QUERY PLAN                                       
373 ---------------------------------------------------------------------------------------
374  Nested Loop  (cost=1.27..2.74 rows=1 width=32)
375    ->  Merge Join  (cost=1.27..2.15 rows=1 width=24)
376          Merge Cond: (t2.val1 = t4.val1)
377          ->  Nested Loop  (cost=0.00..81.95 rows=100 width=16)
378                ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
379                ->  Index Scan using t2_val1 on t2  (cost=0.00..0.67 rows=1 width=8)
380                      Index Cond: (val1 = t3.val1)
381          ->  Sort  (cost=1.27..1.29 rows=10 width=8)
382                Sort Key: t4.val1
383                ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
384    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
385          Index Cond: (val1 = t2.val1)
386 (12 rows)
387
388 SET join_collapse_limit TO 1;
389 EXPLAIN SELECT * FROM t1 CROSS JOIN t2 CROSS JOIN t3 CROSS JOIN t4 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
390                                   QUERY PLAN                                  
391 ------------------------------------------------------------------------------
392  Nested Loop  (cost=30.75..229.72 rows=1 width=32)
393    Join Filter: (t1.val1 = t4.val1)
394    ->  Hash Join  (cost=30.75..227.10 rows=10 width=24)
395          Hash Cond: (t1.val1 = t3.val1)
396          ->  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
397                Hash Cond: (t1.val1 = t2.val1)
398                ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
399                ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
400                      ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
401          ->  Hash  (cost=2.00..2.00 rows=100 width=8)
402                ->  Seq Scan on t3  (cost=0.00..2.00 rows=100 width=8)
403    ->  Materialize  (cost=0.00..1.15 rows=10 width=8)
404          ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
405 (13 rows)
406
407 EXPLAIN SELECT * FROM t2 CROSS JOIN t3 CROSS JOIN t4 CROSS JOIN t1 WHERE t1.val1 = t2.val1 AND t2.val1 = t3.val1 AND t3.val1 = t4.val1;
408                                       QUERY PLAN                                       
409 ---------------------------------------------------------------------------------------
410  Nested Loop  (cost=1.27..2.74 rows=1 width=32)
411    ->  Merge Join  (cost=1.27..2.15 rows=1 width=24)
412          Merge Cond: (t2.val1 = t4.val1)
413          ->  Nested Loop  (cost=0.00..81.95 rows=100 width=16)
414                ->  Index Scan using t3_val1 on t3  (cost=0.00..13.75 rows=100 width=8)
415                ->  Index Scan using t2_val1 on t2  (cost=0.00..0.67 rows=1 width=8)
416                      Index Cond: (val1 = t3.val1)
417          ->  Sort  (cost=1.27..1.29 rows=10 width=8)
418                Sort Key: t4.val1
419                ->  Seq Scan on t4  (cost=0.00..1.10 rows=10 width=8)
420    ->  Index Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=8)
421          Index Cond: (val1 = t2.val1)
422 (12 rows)
423
424 EXPLAIN SELECT * FROM v2;
425                             QUERY PLAN                            
426 ------------------------------------------------------------------
427  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
428    Hash Cond: (t1.val1 = t2.val1)
429    ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
430    ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
431          ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
432 (5 rows)
433
434 EXPLAIN SELECT * FROM v3 v_3;
435                               QUERY PLAN                              
436 ----------------------------------------------------------------------
437  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
438    Hash Cond: (t_1.val1 = t_2.val1)
439    ->  Seq Scan on t1 t_1  (cost=0.00..145.00 rows=10000 width=8)
440    ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
441          ->  Seq Scan on t2 t_2  (cost=0.00..15.00 rows=1000 width=8)
442 (5 rows)
443
444 EXPLAIN SELECT * FROM v2 v_2, v3 v_3 WHERE v_2.t1_val1 = v_3.t1_val1;
445                                   QUERY PLAN                                  
446 ------------------------------------------------------------------------------
447  Nested Loop  (cost=55.00..284.45 rows=100 width=32)
448    ->  Hash Join  (cost=55.00..252.25 rows=100 width=24)
449          Hash Cond: (t1.val1 = t_2.val1)
450          ->  Hash Join  (cost=27.50..220.00 rows=1000 width=16)
451                Hash Cond: (t1.val1 = t2.val1)
452                ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=8)
453                ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
454                      ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=8)
455          ->  Hash  (cost=15.00..15.00 rows=1000 width=8)
456                ->  Seq Scan on t2 t_2  (cost=0.00..15.00 rows=1000 width=8)
457    ->  Index Scan using t1_val1 on t1 t_1  (cost=0.00..0.31 rows=1 width=8)
458          Index Cond: (val1 = t1.val1)
459 (12 rows)
460
461 EXPLAIN SELECT * FROM v4 v_4;
462                                  QUERY PLAN                                  
463 -----------------------------------------------------------------------------
464  Nested Loop  (cost=3.25..82.20 rows=10 width=8)
465    ->  Hash Join  (cost=3.25..23.00 rows=100 width=8)
466          Hash Cond: (t2.val1 = t_3.val1)
467          ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=4)
468          ->  Hash  (cost=2.00..2.00 rows=100 width=4)
469                ->  Seq Scan on t3 t_3  (cost=0.00..2.00 rows=100 width=4)
470    ->  Index Only Scan using t1_val1 on t1  (cost=0.00..0.58 rows=1 width=4)
471          Index Cond: (val1 = t2.val1)
472 (8 rows)
473
474 SET from_collapse_limit TO 1;
475 EXPLAIN SELECT * FROM v4 v_4;
476                                QUERY PLAN                               
477 ------------------------------------------------------------------------
478  Hash Join  (cost=30.75..227.10 rows=10 width=8)
479    Hash Cond: (t1.val1 = t_3.val1)
480    ->  Hash Join  (cost=27.50..220.00 rows=1000 width=8)
481          Hash Cond: (t1.val1 = t2.val1)
482          ->  Seq Scan on t1  (cost=0.00..145.00 rows=10000 width=4)
483          ->  Hash  (cost=15.00..15.00 rows=1000 width=4)
484                ->  Seq Scan on t2  (cost=0.00..15.00 rows=1000 width=4)
485    ->  Hash  (cost=2.00..2.00 rows=100 width=4)
486          ->  Seq Scan on t3 t_3  (cost=0.00..2.00 rows=100 width=4)
487 (9 rows)
488
489 SELECT pg_enable_log(true);
490  pg_enable_log 
491 ---------------
492              0
493 (1 row)
494
495 SELECT pg_enable_log(false);
496  pg_enable_log 
497 ---------------
498              0
499 (1 row)
500