OSDN Git Service

New tool to generate source files for copied functions
[pghintplan/pg_hint_plan.git] / sql / ut-A.sql
1 LOAD 'pg_hint_plan';
2 SET pg_hint_plan.enable_hint TO on;
3 SET pg_hint_plan.debug_print TO on;
4 SET client_min_messages TO LOG;
5 SET search_path TO public;
6
7 ----
8 ---- No.A-1-1 install
9 ---- No.A-2-1 uninstall
10 ----
11
12 -- No.A-1-1-3
13 CREATE EXTENSION pg_hint_plan;
14
15 -- No.A-1-2-3
16 DROP EXTENSION pg_hint_plan;
17
18 -- No.A-1-1-4
19 CREATE SCHEMA other_schema;
20 CREATE EXTENSION pg_hint_plan SCHEMA other_schema;
21
22 CREATE EXTENSION pg_hint_plan;
23 DROP SCHEMA other_schema;
24
25 ----
26 ---- No. A-5-1 comment pattern
27 ----
28
29 -- No. A-5-1-1
30 /*+SeqScan(t1)*/
31 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
32
33 -- No. A-5-1-2
34 /* +SeqScan(t1)*/
35 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
36
37 -- No. A-5-1-3
38 /*SeqScan(t1)*/
39 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
40
41 -- No. A-5-1-4
42 --+SeqScan(t1)
43 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
44
45 -- No. A-5-1-5
46 /* /*+SeqScan(t1)*/  */
47 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
48
49 ----
50 ---- No. A-5-2 hint position
51 ----
52
53 -- No. A-5-2-1
54 EXPLAIN (COSTS false) SELECT c1 FROM s1.t1 WHERE t1.c1 = 1;
55 /*+SeqScan(t1)*/
56 EXPLAIN (COSTS false) SELECT c1 FROM s1.t1 WHERE t1.c1 = 1;
57
58 -- No. A-5-2-2
59 EXPLAIN (COSTS false) SELECT c1, c2 AS c_2 /*+SeqScan(t1)*/ FROM s1.t1 WHERE t1.c1 = 1;
60
61 -- No. A-5-2-3
62 EXPLAIN (COSTS false) SELECT c1 AS "c1"/*+SeqScan(t1)*/ FROM s1.t1 WHERE t1.c1 = 1;
63
64 -- No. A-5-2-4
65 EXPLAIN (COSTS false) SELECT * /*+SeqScan(t1)*/ FROM s1.t1 WHERE t1.c1 = 1;
66
67 ----
68 ---- No. A-6-1 hint's table definition
69 ----
70
71 SET pg_hint_plan.enable_hint_table TO on;
72 -- No. A-6-1-1
73 \d hint_plan.hints
74
75 ----
76 ---- No. A-6-2 search condition
77 ----
78 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
79 -- No. A-6-2-1
80 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
81         VALUES (
82         'EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = ?;',
83         '',
84         'SeqScan(t1)');
85 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
86
87 -- No. A-6-2-2
88 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
89         VALUES (
90         'EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = ?;',
91         'psql',
92         'BitmapScan(t1)');
93 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
94 TRUNCATE hint_plan.hints;
95
96 -- No. A-6-2-3
97 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
98         VALUES (
99         'EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = ?;',
100         'dummy_application_name',
101         'SeqScan(t1)'
102 );
103 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
104 TRUNCATE hint_plan.hints;
105
106 -- No. A-6-2-4
107 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
108         VALUES (
109         'EXPLAIN (COSTS false) SELECT * FROM s1.t1;',
110         '',
111         'SeqScan(t1)'
112 );
113 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
114 TRUNCATE hint_plan.hints;
115
116 ----
117 ---- No. A-6-3 number of constant
118 ----
119
120 -- No. A-6-3-1
121 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
122         VALUES (
123         'EXPLAIN (COSTS false) SELECT c1 FROM s1.t1;',
124         '',
125         'SeqScan(t1)'
126 );
127 EXPLAIN (COSTS false) SELECT c1 FROM s1.t1;
128 TRUNCATE hint_plan.hints;
129
130 -- No. A-6-3-2
131 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
132         VALUES (
133         'EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = ?;',
134         '',
135         'SeqScan(t1)'
136 );
137 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
138 TRUNCATE hint_plan.hints;
139
140 -- No. A-6-3-3
141 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
142         VALUES (
143         'EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = ? OR t1.c1 = ?;',
144         '',
145         'SeqScan(t1)'
146 );
147 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1 OR t1.c1 = 0;
148 TRUNCATE hint_plan.hints;
149 SET pg_hint_plan.enable_hint_table TO off;
150
151 ----
152 ---- No. A-7-2 hint delimiter
153 ----
154
155 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
156 -- No. A-7-2-1
157 -- No. A-7-2-2
158 -- No. A-7-2-3
159 -- No. A-7-2-4
160 -- No. A-7-2-5
161 -- No. A-7-2-6
162 -- No. A-7-2-7
163 /*+Set(enable_indexscan"off")Set(enable_bitmapscan"off")*/
164 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
165
166 -- No. A-7-2-8
167 /*+ Set(enable_indexscan"off")Set(enable_bitmapscan"off")*/
168 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
169
170 -- No. A-7-2-9
171 /*+Set(enable_indexscan"off")Set(enable_bitmapscan"off") */
172 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
173
174 -- No. A-7-2-10
175 /*+ Set (enable_indexscan"off") Set (enable_bitmapscan"off")*/
176 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
177
178 -- No. A-7-2-11
179 /*+Set ( enable_indexscan"off")Set ( enable_bitmapscan"off")*/
180 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
181
182 -- No. A-7-2-12
183 /*+Set(enable_indexscan"off" ) Set(enable_bitmapscan"off" ) */
184 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
185
186 -- No. A-7-2-13
187 /*+Set( enable_indexscan "off" )Set( enable_bitmapscan "off" )*/
188 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
189
190 -- No. A-7-2-14
191 /*+ Set ( enable_indexscan "off" ) Set ( enable_bitmapscan "off" ) */
192 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
193
194 -- No. A-7-2-15
195 /*+     Set(enable_indexscan"off")Set(enable_bitmapscan"off")*/
196 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
197
198 -- No. A-7-2-16
199 /*+Set(enable_indexscan"off")Set(enable_bitmapscan"off")        */
200 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
201
202 -- No. A-7-2-17
203 /*+     Set     (enable_indexscan"off") Set     (enable_bitmapscan"off")*/
204 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
205
206 -- No. A-7-2-18
207 /*+Set  (       enable_indexscan"off")Set       (       enable_bitmapscan"off")*/
208 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
209
210 -- No. A-7-2-19
211 /*+Set(enable_indexscan"off"    )       Set(enable_bitmapscan"off"      )       */
212 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
213
214 -- No. A-7-2-20
215 /*+Set( enable_indexscan        "off"   )Set(   enable_bitmapscan       "off"   )*/
216 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
217
218 -- No. A-7-2-21
219 /*+     Set     (       enable_indexscan        "off"   )       Set     (       enable_bitmapscan       "off"   )       */
220 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
221
222 -- No. A-7-2-22
223 /*+
224 Set(enable_indexscan"off")Set(enable_bitmapscan"off")*/
225 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
226
227 -- No. A-7-2-23
228 /*+Set(enable_indexscan"off")Set(enable_bitmapscan"off")
229 */
230 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
231
232 -- No. A-7-2-24
233 /*+
234 Set
235 (enable_indexscan"off")
236 Set
237 (enable_bitmapscan"off")*/
238 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
239
240 -- No. A-7-2-25
241 /*+Set
242 (
243 enable_indexscan"off")Set
244 (
245 enable_bitmapscan"off")*/
246 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
247
248 -- No. A-7-2-26
249 /*+Set(enable_indexscan"off"
250 )
251 Set(enable_bitmapscan"off"
252 )
253 */
254 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
255
256 -- No. A-7-2-27
257 /*+Set(
258 enable_indexscan
259 "off"
260 )Set(
261 enable_bitmapscan
262 "off"
263 )*/
264 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
265
266 -- No. A-7-2-28
267 /*+
268 Set
269 (
270 enable_indexscan
271 "off"
272 )
273 Set
274 (
275 enable_bitmapscan
276 "off"
277 )
278 */
279 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
280
281 -- No. A-7-2-29
282 /*+     
283          Set(enable_indexscan"off")Set(enable_bitmapscan"off")*/
284 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
285
286 -- No. A-7-2-30
287 /*+Set(enable_indexscan"off")Set(enable_bitmapscan"off")        
288          */
289 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
290
291 -- No. A-7-2-31
292 /*+     
293          Set    
294          (enable_indexscan"off")        
295          Set    
296          (enable_bitmapscan"off")*/
297 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
298
299 -- No. A-7-2-32
300 /*+Set  
301          (      
302          enable_indexscan"off")Set      
303          (      
304          enable_bitmapscan"off")*/
305 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
306
307 -- No. A-7-2-33
308 /*+Set(enable_indexscan"off"    
309          )      
310          Set(enable_bitmapscan"off"     
311          )      
312          */
313 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
314
315 -- No. A-7-2-34
316 /*+Set(         
317          enable_indexscan       
318          "off"  
319          )Set(  
320          enable_bitmapscan      
321          "off"  
322          )*/
323 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
324
325 -- No. A-7-2-35
326 /*+     
327          Set    
328          (      
329          enable_indexscan       
330          "off"  
331          )      
332          Set    
333          (      
334          enable_bitmapscan      
335          "off"  
336          )      
337          */
338 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
339
340 ----
341 ---- No. A-7-3 hint object pattern
342 ---- No. A-9-2 message object pattern
343 ----
344
345 -- No. A-7-3-1
346 -- No. A-9-2-1
347 /*+SeqScan(t)*/
348 EXPLAIN (COSTS false) SELECT * FROM s1.t1 t WHERE t.c1 = 1;
349 /*+SeqScan(ttt)*/
350 EXPLAIN (COSTS false) SELECT * FROM s1.t1 ttt WHERE ttt.c1 = 1;
351 /*+SeqScan("t")*/
352 EXPLAIN (COSTS false) SELECT * FROM s1.t1 t WHERE t.c1 = 1;
353 /*+SeqScan("ttt")*/
354 EXPLAIN (COSTS false) SELECT * FROM s1.t1 ttt WHERE ttt.c1 = 1;
355
356 -- No. A-7-3-2
357 -- No. A-9-2-2
358 /*+SeqScan(T)*/
359 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "T" WHERE "T".c1 = 1;
360 /*+SeqScan(TTT)*/
361 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "TTT" WHERE "TTT".c1 = 1;
362 /*+SeqScan("T")*/
363 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "T" WHERE "T".c1 = 1;
364 /*+SeqScan("TTT")*/
365 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "TTT" WHERE "TTT".c1 = 1;
366
367 -- No. A-7-3-3
368 -- No. A-9-2-3
369 /*+SeqScan(()*/
370 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "(" WHERE "(".c1 = 1;
371 /*+SeqScan("(")*/
372 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "(" WHERE "(".c1 = 1;
373
374 -- No. A-7-3-4
375 -- No. A-9-2-4
376 /*+SeqScan())*/
377 EXPLAIN (COSTS false) SELECT * FROM s1.t1 ")" WHERE ")".c1 = 1;
378 /*+SeqScan(")")*/
379 EXPLAIN (COSTS false) SELECT * FROM s1.t1 ")" WHERE ")".c1 = 1;
380 /*+SeqScan(")))")*/
381 EXPLAIN (COSTS false) SELECT * FROM s1.t1 ")))" WHERE ")))".c1 = 1;
382
383 -- No. A-7-3-5
384 -- No. A-9-2-5
385 /*+SeqScan(")*/
386 EXPLAIN (COSTS false) SELECT * FROM s1.t1 """" WHERE """".c1 = 1;
387 /*+SeqScan("""")*/
388 EXPLAIN (COSTS false) SELECT * FROM s1.t1 """" WHERE """".c1 = 1;
389 /*+SeqScan("""""""")*/
390 EXPLAIN (COSTS false) SELECT * FROM s1.t1 """""""" WHERE """""""".c1 = 1;
391
392 -- No. A-7-3-6
393 -- No. A-9-2-6
394 /*+SeqScan( )*/
395 EXPLAIN (COSTS false) SELECT * FROM s1.t1 " " WHERE " ".c1 = 1;
396 /*+SeqScan(" ")*/
397 EXPLAIN (COSTS false) SELECT * FROM s1.t1 " " WHERE " ".c1 = 1;
398 /*+SeqScan("   ")*/
399 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "   " WHERE "   ".c1 = 1;
400
401 -- No. A-7-3-7
402 -- No. A-9-2-7
403 /*+SeqScan(     )*/
404 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "     " WHERE "       ".c1 = 1;
405 /*+SeqScan("    ")*/
406 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "     " WHERE "       ".c1 = 1;
407 /*+SeqScan("                    ")*/
408 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "                     " WHERE "                       ".c1 = 1;
409
410 -- No. A-7-3-8
411 -- No. A-9-2-8
412 /*+SeqScan(
413 )*/
414 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "
415 " WHERE "
416 ".c1 = 1;
417 /*+SeqScan("
418 ")*/
419 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "
420 " WHERE "
421 ".c1 = 1;
422 /*+SeqScan("
423
424
425 ")*/
426 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "
427
428
429 " WHERE "
430
431
432 ".c1 = 1;
433
434 -- No. A-7-3-9
435 -- No. A-9-2-9
436 /*+SeqScan(Set)*/
437 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "Set" WHERE "Set".c1 = 1;
438 /*+SeqScan("Set")*/
439 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "Set" WHERE "Set".c1 = 1;
440 /*+SeqScan("Set SeqScan Leading")*/
441 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "Set SeqScan Leading" WHERE "Set SeqScan Leading".c1 = 1;
442
443 -- No. A-7-3-10
444 -- No. A-9-2-10
445 /*+SeqScan(あ)*/
446 EXPLAIN (COSTS false) SELECT * FROM s1.t1 あ WHERE あ.c1 = 1;
447 /*+SeqScan(あいう)*/
448 EXPLAIN (COSTS false) SELECT * FROM s1.t1 あいう WHERE あいう.c1 = 1;
449 /*+SeqScan("あ")*/
450 EXPLAIN (COSTS false) SELECT * FROM s1.t1 あ WHERE あ.c1 = 1;
451 /*+SeqScan("あいう")*/
452 EXPLAIN (COSTS false) SELECT * FROM s1.t1 あいう WHERE あいう.c1 = 1;
453
454 -- No. A-7-3-11
455 -- No. A-9-2-11
456 /*+SeqScan(/**/)*/
457 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "/**/" WHERE "/**/".c1 = 1;
458 /*+SeqScan(/**//**//**/)*/
459 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "/**//**//**/" WHERE "/**//**//**/".c1 = 1;
460
461 -- No. A-7-3-12
462 -- No. A-9-2-12
463 /*+SeqScan("tT()""      
464 Set/**/あ")*/
465 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "tT()""       
466 Set/**/あ" WHERE "tT()""       
467 Set/**/あ".c1 = 1;
468 --"
469
470 /*+SeqScan("tT()""      
471 Setあ")*/
472 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "tT()""       
473 Setあ" WHERE "tT()""   
474 Setあ".c1 = 1;
475
476 -- No. A-7-3-13
477 -- No. A-9-2-13
478 /*+SeqScan(a123456789b123456789c123456789d123456789e123456789f123)*/
479 EXPLAIN (COSTS false) SELECT * FROM s1.t1 "123456789012345678901234567890123456789012345678901234" WHERE "123456789012345678901234567890123456789012345678901234".c1 = 1;
480
481 ----
482 ---- No. A-7-4 hint parse error
483 ----
484
485 -- No. A-7-4-1
486 /*+Set(enable_indexscan off)Set enable_tidscan off)Set(enable_bitmapscan off)SeqScan(t1)*/
487 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
488
489 -- No. A-7-4-2
490 /*+Set(enable_indexscan off)Set(enable_tidscan off Set(enable_bitmapscan off)SeqScan(t1)*/
491 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
492
493 -- No. A-7-4-3
494 /*+Set(enable_indexscan off)Set(enable_tidscan "off)Set(enable_bitmapscan off)SeqScan(t1)*/
495 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
496
497 -- No. A-7-4-4
498 /*+Set(enable_indexscan off)SeqScan("")Set(enable_bitmapscan off)*/
499 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
500
501 -- No. A-7-4-5
502 /*+Set(enable_indexscan off)NoSet(enable_tidscan off)Set(enable_bitmapscan off)SeqScan(t1)*/
503 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
504
505 -- No. A-7-4-6
506 /*+Set(enable_indexscan off)"Set"(enable_tidscan off)Set(enable_bitmapscan off)SeqScan(t1)*/
507 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
508
509 -- No. A-7-4-7
510 /*+Set(enable_indexscan off)Set(enable_tidscan /* value */off)Set(enable_bitmapscan off)SeqScan(t1)*/
511 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
512
513 ----
514 ---- No. A-8-1 original GUC parameter
515 ----
516 ---- Don't test postgresql itself.
517 -- No. A-8-1-1
518 -- SET ROLE super_user;
519 -- SET pg_hint_plan.debug_print TO off;
520 -- SHOW pg_hint_plan.enable_hint;
521 -- SHOW pg_hint_plan.debug_print;
522 -- SHOW pg_hint_plan.parse_messages;
523 -- SET pg_hint_plan.enable_hint TO off;
524 -- SET pg_hint_plan.debug_print TO on;
525 -- SET pg_hint_plan.parse_messages TO error;
526 -- SHOW pg_hint_plan.enable_hint;
527 -- SHOW pg_hint_plan.debug_print;
528 -- SHOW pg_hint_plan.parse_messages;
529 -- RESET pg_hint_plan.enable_hint;
530 -- RESET pg_hint_plan.debug_print;
531 -- RESET pg_hint_plan.parse_messages;
532 -- SHOW pg_hint_plan.enable_hint;
533 -- SHOW pg_hint_plan.debug_print;
534 -- SHOW pg_hint_plan.parse_messages;
535 -- 
536 -- -- No. A-8-1-2
537 -- SET ROLE normal_user;
538 -- SHOW pg_hint_plan.enable_hint;
539 -- SHOW pg_hint_plan.debug_print;
540 -- SHOW pg_hint_plan.parse_messages;
541 -- SET pg_hint_plan.enable_hint TO off;
542 -- SET pg_hint_plan.debug_print TO on;
543 -- SET pg_hint_plan.parse_messages TO error;
544 -- SHOW pg_hint_plan.enable_hint;
545 -- SHOW pg_hint_plan.debug_print;
546 -- SHOW pg_hint_plan.parse_messages;
547 -- RESET pg_hint_plan.enable_hint;
548 -- RESET pg_hint_plan.debug_print;
549 -- RESET pg_hint_plan.parse_messages;
550 -- SHOW pg_hint_plan.enable_hint;
551 -- SHOW pg_hint_plan.debug_print;
552 -- SHOW pg_hint_plan.parse_messages;
553 -- 
554 -- RESET ROLE;
555
556 ----
557 ---- No. A-8-2 original GUC parameter pg_hint_plan.enable_hint
558 ----
559
560 -- No. A-8-2-1
561 SET pg_hint_plan.debug_print TO off;
562 SET pg_hint_plan.enable_hint TO on;
563 SHOW pg_hint_plan.enable_hint;
564 /*+Set(enable_indexscan off)*/
565 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
566
567 -- No. A-8-2-2
568 SET pg_hint_plan.enable_hint TO off;
569 SHOW pg_hint_plan.enable_hint;
570 /*+Set(enable_indexscan off)*/
571 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
572
573 -- No. A-8-2-3
574 -- Don't test PostgreSQL itself.
575 -- SET pg_hint_plan.enable_hint TO DEFAULT;
576 -- SHOW pg_hint_plan.enable_hint;
577 -- /*+Set(enable_indexscan off)*/
578 -- EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
579
580 -- No. A-8-2-4
581 -- Don't test PostgreSQL itself
582 -- SET pg_hint_plan.enable_hint TO enable;
583 -- SHOW pg_hint_plan.enable_hint;
584
585 ----
586 ---- No. A-8-3 original GUC parameter pg_hint_plan.debug_print
587 ----
588
589 -- No. A-8-3-1
590 SET pg_hint_plan.enable_hint TO on;
591 SHOW pg_hint_plan.enable_hint;
592 SET pg_hint_plan.debug_print TO on;
593 SHOW pg_hint_plan.debug_print;
594 /*+Set(enable_indexscan off)*/
595 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
596
597 -- No. A-8-3-2
598 SET pg_hint_plan.debug_print TO off;
599 SHOW pg_hint_plan.debug_print;
600 /*+Set(enable_indexscan off)*/
601 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
602
603 -- No. A-8-3-3
604 SET pg_hint_plan.debug_print TO DEFAULT;
605 SHOW pg_hint_plan.debug_print;
606 /*+Set(enable_indexscan off)*/
607 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
608
609 -- No. A-8-3-4
610 SET pg_hint_plan.debug_print TO enable;
611 SHOW pg_hint_plan.debug_print;
612
613 ----
614 ---- No. A-8-4 original GUC parameter pg_hint_plan.parse_messages
615 ----
616
617 SET client_min_messages TO debug5;
618
619 -- No. A-8-4-1
620 SET pg_hint_plan.parse_messages TO debug5;
621 SHOW pg_hint_plan.parse_messages;
622 /*+Set*/SELECT 1;
623 SET client_min_messages TO debug4;
624 /*+Set*/SELECT 1;
625
626 -- No. A-8-4-2
627 SET pg_hint_plan.parse_messages TO debug4;
628 SHOW pg_hint_plan.parse_messages;
629 /*+Set*/SELECT 1;
630 SET client_min_messages TO debug3;
631 /*+Set*/SELECT 1;
632
633 -- No. A-8-4-3
634 SET pg_hint_plan.parse_messages TO debug3;
635 SHOW pg_hint_plan.parse_messages;
636 /*+Set*/SELECT 1;
637 SET client_min_messages TO debug2;
638 /*+Set*/SELECT 1;
639
640 -- No. A-8-4-4
641 SET pg_hint_plan.parse_messages TO debug2;
642 SHOW pg_hint_plan.parse_messages;
643 /*+Set*/SELECT 1;
644 SET client_min_messages TO debug1;
645 /*+Set*/SELECT 1;
646
647 -- No. A-8-4-5
648 SET pg_hint_plan.parse_messages TO debug1;
649 SHOW pg_hint_plan.parse_messages;
650 /*+Set*/SELECT 1;
651 SET client_min_messages TO log;
652 /*+Set*/SELECT 1;
653
654 -- No. A-8-4-6
655 SET pg_hint_plan.parse_messages TO log;
656 SHOW pg_hint_plan.parse_messages;
657 /*+Set*/SELECT 1;
658 SET client_min_messages TO info;
659 /*+Set*/SELECT 1;
660
661 -- No. A-8-4-7
662 SET pg_hint_plan.parse_messages TO info;
663 SHOW pg_hint_plan.parse_messages;
664 /*+Set*/SELECT 1;
665 SET client_min_messages TO notice;
666 /*+Set*/SELECT 1;
667
668 -- No. A-8-4-8
669 SET pg_hint_plan.parse_messages TO notice;
670 SHOW pg_hint_plan.parse_messages;
671 /*+Set*/SELECT 1;
672 SET client_min_messages TO warning;
673 /*+Set*/SELECT 1;
674
675 -- No. A-8-4-9
676 SET pg_hint_plan.parse_messages TO warning;
677 SHOW pg_hint_plan.parse_messages;
678 /*+Set*/SELECT 1;
679 SET client_min_messages TO error;
680 /*+Set*/SELECT 1;
681
682 -- No. A-8-4-10
683 SET pg_hint_plan.parse_messages TO error;
684 SHOW pg_hint_plan.parse_messages;
685 /*+Set*/SELECT 1;
686 SET client_min_messages TO error;
687 /*+Set*/SELECT 1;
688
689 -- No. A-8-4-11
690 RESET client_min_messages;
691 SET pg_hint_plan.parse_messages TO DEFAULT;
692 SHOW pg_hint_plan.parse_messages;
693 /*+Set*/SELECT 1;
694
695 -- No. A-8-4-12
696 SET pg_hint_plan.parse_messages TO fatal;
697 SHOW pg_hint_plan.parse_messages;
698
699 -- No. A-8-4-13
700 SET pg_hint_plan.parse_messages TO panic;
701 SHOW pg_hint_plan.parse_messages;
702
703 -- No. A-8-4-14
704 SET pg_hint_plan.parse_messages TO on;
705 SHOW pg_hint_plan.parse_messages;
706
707 ----
708 ---- No. A-8-5 original GUC parameter pg_hint_plan.enable_hint_table
709 ----
710
711 INSERT INTO hint_plan.hints (norm_query_string, application_name, hints)
712         VALUES (
713         'EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = ?;',
714         '',
715         'SeqScan(t1)');
716
717 -- No. A-8-5-1
718 SET pg_hint_plan.enable_hint_table TO on;
719 SHOW pg_hint_plan.enable_hint_table;
720 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
721
722 -- No. A-8-5-2
723 SET pg_hint_plan.enable_hint_table TO off;
724 SHOW pg_hint_plan.enable_hint_table;
725 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
726
727 -- No. A-8-5-3
728 SET pg_hint_plan.enable_hint_table TO DEFAULT;
729 SHOW pg_hint_plan.enable_hint_table;
730 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
731
732 -- No. A-8-5-4
733 SET pg_hint_plan.enable_hint_table TO enable;
734 SHOW pg_hint_plan.enable_hint_table;
735
736 TRUNCATE hint_plan.hints;
737
738 ----
739 ---- No. A-9-1 parse error message output
740 ----
741
742 -- No. A-9-1-1
743 /*+"Set"(enable_indexscan on)*/SELECT 1;
744 /*+Set()(enable_indexscan on)*/SELECT 1;
745 /*+Set(enable_indexscan on*/SELECT 1;
746
747 ----
748 ---- No. A-9-3 hint state output
749 ----
750
751 SET pg_hint_plan.debug_print TO on;
752 SET client_min_messages TO LOG;
753
754 -- No. A-9-3-1
755 /*+SeqScan(t1)*/
756 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
757
758 -- No. A-9-3-2
759 /*+SeqScan(no_table)*/
760 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
761
762 -- No. A-9-3-3
763 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1 AND t1.ctid = '(1,1)';
764 /*+TidScan(t1)BitmapScan(t1)*/
765 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1 AND t1.ctid = '(1,1)';
766 /*+TidScan(t1)BitmapScan(t1)IndexScan(t1)*/
767 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1 AND t1.ctid = '(1,1)';
768 /*+TidScan(t1)BitmapScan(t1)IndexScan(t1)SeqScan(t1)*/
769 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1 AND t1.ctid = '(1,1)';
770
771 -- No. A-9-3-4
772 /*+Set(enable_indexscan enable)*/
773 EXPLAIN (COSTS false) SELECT * FROM s1.t1 WHERE t1.c1 = 1;
774
775 ----
776 ---- No. A-10-1 hint state output
777 ----
778
779 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 = 1;
780 EXPLAIN (COSTS false) EXECUTE p1;
781 DEALLOCATE p1;
782
783 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 < $1;
784 EXPLAIN (COSTS false) EXECUTE p1 (1000);
785 EXPLAIN (COSTS false) EXECUTE p1 (1000);
786 EXPLAIN (COSTS false) EXECUTE p1 (1000);
787 EXPLAIN (COSTS false) EXECUTE p1 (1000);
788 EXPLAIN (COSTS false) EXECUTE p1 (1000);
789 EXPLAIN (COSTS false) EXECUTE p1 (1000);
790 DEALLOCATE p1;
791
792 -- No. A-10-1-1
793 -- No. A-10-1-2
794 /*+SeqScan(t1)*/
795 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 = 1;
796 /*+BitmapScan(t1)*/
797 EXPLAIN (COSTS false) EXECUTE p1;
798 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
799 /*+BitmapScan(t1)*/
800 EXPLAIN (COSTS false) EXECUTE p1;
801 DEALLOCATE p1;
802
803 /*+BitmapScan(t1)*/
804 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 < $1;
805 /*+SeqScan(t1)*/
806 EXPLAIN (COSTS false) EXECUTE p1 (1000);
807 /*+SeqScan(t1)*/
808 EXPLAIN (COSTS false) EXECUTE p1 (1000);
809 /*+SeqScan(t1)*/
810 EXPLAIN (COSTS false) EXECUTE p1 (1000);
811 /*+SeqScan(t1)*/
812 EXPLAIN (COSTS false) EXECUTE p1 (1000);
813 /*+SeqScan(t1)*/
814 EXPLAIN (COSTS false) EXECUTE p1 (1000);
815 /*+SeqScan(t1)*/
816 EXPLAIN (COSTS false) EXECUTE p1 (1000);
817 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
818 /*+SeqScan(t1)*/
819 EXPLAIN (COSTS false) EXECUTE p1 (1000);
820 DEALLOCATE p1;
821
822 -- No. A-10-1-3
823 -- No. A-10-1-4
824 /*+SeqScan(t1)*/
825 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 = 1;
826 EXPLAIN (COSTS false) EXECUTE p1;
827 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
828 EXPLAIN (COSTS false) EXECUTE p1;
829 DEALLOCATE p1;
830
831 /*+BitmapScan(t1)*/
832 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 < $1;
833 EXPLAIN (COSTS false) EXECUTE p1 (1000);
834 EXPLAIN (COSTS false) EXECUTE p1 (1000);
835 EXPLAIN (COSTS false) EXECUTE p1 (1000);
836 EXPLAIN (COSTS false) EXECUTE p1 (1000);
837 EXPLAIN (COSTS false) EXECUTE p1 (1000);
838 EXPLAIN (COSTS false) EXECUTE p1 (1000);
839 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
840 EXPLAIN (COSTS false) EXECUTE p1 (1000);
841 DEALLOCATE p1;
842
843 -- No. A-10-1-5
844 -- No. A-10-1-6
845 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 = 1;
846 /*+BitmapScan(t1)*/
847 EXPLAIN (COSTS false) EXECUTE p1;
848 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
849 /*+BitmapScan(t1)*/
850 EXPLAIN (COSTS false) EXECUTE p1;
851 DEALLOCATE p1;
852
853 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 < $1;
854 /*+BitmapScan(t1)*/
855 EXPLAIN (COSTS false) EXECUTE p1 (1000);
856 EXPLAIN (COSTS false) EXECUTE p1 (1000);
857 EXPLAIN (COSTS false) EXECUTE p1 (1000);
858 EXPLAIN (COSTS false) EXECUTE p1 (1000);
859 EXPLAIN (COSTS false) EXECUTE p1 (1000);
860 EXPLAIN (COSTS false) EXECUTE p1 (1000);
861 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
862 /*+BitmapScan(t1)*/
863 EXPLAIN (COSTS false) EXECUTE p1 (1000);
864 DEALLOCATE p1;
865
866 -- No. A-10-1-9
867 -- No. A-10-1-10
868 /*+SeqScan(t1)*/
869 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 = 1;
870 /*+BitmapScan(t1)*/
871 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1;
872 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
873 /*+BitmapScan(t1)*/
874 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1;
875 DEALLOCATE p1;
876
877 /*+BitmapScan(t1)*/
878 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 < $1;
879 /*+SeqScan(t1)*/
880 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
881 /*+SeqScan(t1)*/
882 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
883 /*+SeqScan(t1)*/
884 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
885 /*+SeqScan(t1)*/
886 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
887 /*+SeqScan(t1)*/
888 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
889 /*+SeqScan(t1)*/
890 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
891 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
892 /*+SeqScan(t1)*/
893 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
894 DEALLOCATE p1;
895
896 -- No. A-10-1-11
897 -- No. A-10-1-12
898 /*+SeqScan(t1)*/
899 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 = 1;
900 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1;
901 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
902 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1;
903 DEALLOCATE p1;
904
905 /*+BitmapScan(t1)*/
906 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 < $1;
907 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
908 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
909 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
910 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
911 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
912 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
913 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
914 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
915 DEALLOCATE p1;
916
917 -- No. A-10-1-13
918 -- No. A-10-1-14
919 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 = 1;
920 /*+BitmapScan(t1)*/
921 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1;
922 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
923 /*+BitmapScan(t1)*/
924 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1;
925 DEALLOCATE p1;
926
927 PREPARE p1 AS SELECT * FROM s1.t1 WHERE t1.c1 < $1;
928 /*+BitmapScan(t1)*/
929 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
930 /*+BitmapScan(t1)*/
931 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
932 /*+BitmapScan(t1)*/
933 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
934 /*+BitmapScan(t1)*/
935 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
936 /*+BitmapScan(t1)*/
937 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
938 /*+BitmapScan(t1)*/
939 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
940 UPDATE pg_catalog.pg_class SET relpages = relpages WHERE relname = 't1';
941 /*+BitmapScan(t1)*/
942 EXPLAIN (COSTS false) CREATE TABLE test AS EXECUTE p1 (1000);
943 DEALLOCATE p1;
944
945 ----
946 ---- No. A-10-4 EXECUTE statement name error
947 ----
948
949 -- No. A-10-4-1
950 EXECUTE p1;
951 SHOW pg_hint_plan.debug_print;
952
953 ----
954 ---- No. A-11-5 EXECUTE statement name error
955 ----
956
957 -- No. A-11-5-1
958 SELECT pg_stat_statements_reset();
959 SELECT * FROM s1.t1 WHERE t1.c1 = 1;
960 /*+Set(enable_seqscan off)*/ SELECT * FROM s1.t1 WHERE t1.c1 = 1;
961 /*+SeqScan(t1)*/ SELECT * FROM s1.t1 WHERE t1.c1 = 1;
962 SELECT s.query, s.calls
963   FROM public.pg_stat_statements s
964   JOIN pg_catalog.pg_database d
965     ON (s.dbid = d.oid)
966  ORDER BY 1;
967
968 ----
969 ---- No. A-12-1 reset of global variable of core at the error
970 ---- No. A-12-2 reset of global variable of original at the error
971 ----
972
973 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
974 /*+Set(enable_seqscan off)Set(geqo_threshold 100)SeqScan(t1)MergeJoin(t1 t2)NestLoop(t1 t1)*/
975 PREPARE p1 AS SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
976 EXPLAIN (COSTS false) EXECUTE p1;
977
978 -- No. A-12-1-1
979 -- No. A-12-2-1
980 SELECT name, setting FROM settings;
981 SET pg_hint_plan.parse_messages TO error;
982 /*+Set(enable_seqscan off)Set(geqo_threshold 100)SeqScan(t1)MergeJoin(t1 t2)NestLoop(t1 t1)*/
983 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
984 SELECT name, setting FROM settings;
985 /*+Set(enable_seqscan off)Set(geqo_threshold 100)SeqScan(t1)MergeJoin(t1 t2)*/
986 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
987
988 -- No. A-12-1-2
989 -- No. A-12-2-2
990 SELECT name, setting FROM settings;
991 SET pg_hint_plan.parse_messages TO error;
992 /*+Set(enable_seqscan off)Set(geqo_threshold 100)SeqScan(t1)MergeJoin(t1 t2)NestLoop(t1 t1)*/
993 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
994 SELECT name, setting FROM settings;
995 EXPLAIN (COSTS false) EXECUTE p1;
996
997 -- No. A-12-1-3
998 -- No. A-12-2-3
999 SELECT name, setting FROM settings;
1000 SET pg_hint_plan.parse_messages TO error;
1001 EXPLAIN (COSTS false) EXECUTE p2;
1002 /*+Set(enable_seqscan off)Set(geqo_threshold 100)SeqScan(t1)MergeJoin(t1 t2)*/
1003 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1004 EXPLAIN (COSTS false) EXECUTE p1;
1005 SELECT name, setting FROM settings;
1006
1007 -- No. A-12-1-4
1008 -- No. A-12-2-4
1009 SELECT name, setting FROM settings;
1010 SET pg_hint_plan.parse_messages TO error;
1011 EXPLAIN (COSTS false) EXECUTE p2;
1012 EXPLAIN (COSTS false) EXECUTE p1;
1013 SELECT name, setting FROM settings;
1014
1015 DEALLOCATE p1;
1016 SET pg_hint_plan.parse_messages TO LOG;
1017
1018 ----
1019 ---- No. A-12-3 effective range of the hint
1020 ----
1021
1022 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1023
1024 -- No. A-12-3-1
1025 SET enable_indexscan TO off;
1026 SET enable_mergejoin TO off;
1027 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1028 SELECT name, setting FROM settings;
1029 /*+Set(enable_indexscan on)Set(geqo_threshold 100)IndexScan(t2)MergeJoin(t1 t2)Leading(t2 t1)*/
1030 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1031 SELECT name, setting FROM settings;
1032 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1033
1034 -- No. A-12-3-2
1035 SET enable_indexscan TO off;
1036 SET enable_mergejoin TO off;
1037 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1038 SELECT name, setting FROM settings;
1039 BEGIN;
1040 /*+Set(enable_indexscan on)Set(geqo_threshold 100)IndexScan(t2)MergeJoin(t1 t2)Leading(t2 t1)*/
1041 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1042 COMMIT;
1043 BEGIN;
1044 SELECT name, setting FROM settings;
1045 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1046 COMMIT;
1047
1048 -- No. A-12-3-3
1049 SET enable_indexscan TO off;
1050 SET enable_mergejoin TO off;
1051 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1052 SELECT name, setting FROM settings;
1053 /*+Set(enable_indexscan on)Set(geqo_threshold 100)IndexScan(t2)MergeJoin(t1 t2)Leading(t2 t1)*/
1054 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1055 \connect
1056 SET enable_indexscan TO off;
1057 SET enable_mergejoin TO off;
1058 LOAD 'pg_hint_plan';
1059 SELECT name, setting FROM settings;
1060 EXPLAIN (COSTS false) SELECT * FROM s1.t1, s1.t2 WHERE t1.c1 = t2.c1;
1061
1062 SET pg_hint_plan.enable_hint TO on;
1063 SET pg_hint_plan.debug_print TO on;
1064 SET client_min_messages TO LOG;
1065 SET search_path TO public;
1066 RESET enable_indexscan;
1067 RESET enable_mergejoin;
1068
1069 ----
1070 ---- No. A-13 call planner recursively
1071 ----
1072
1073 CREATE OR REPLACE FUNCTION nested_planner(cnt int) RETURNS int AS $$
1074 DECLARE
1075     new_cnt int;
1076 BEGIN
1077     RAISE NOTICE 'nested_planner(%)', cnt;
1078
1079     /* 再帰終了の判断 */
1080     IF cnt <= 1 THEN
1081         RETURN 0;
1082     END IF;
1083
1084         SELECT /*+ IndexScan(t_1) */ nested_planner(cnt - 1) INTO new_cnt
1085           FROM s1.t1 t_1
1086           JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1087          ORDER BY t_1.c1 LIMIT 1;
1088
1089     RETURN new_cnt;
1090 END;
1091 $$ LANGUAGE plpgsql IMMUTABLE;
1092
1093 ----
1094 ---- No. A-13-2 use hint of main query
1095 ----
1096
1097 --No.13-2-1
1098 EXPLAIN (COSTS false) SELECT nested_planner(1) FROM s1.t1 t_1 ORDER BY t_1.c1;
1099 /*+SeqScan(t_1)*/
1100 EXPLAIN (COSTS false) SELECT nested_planner(1) FROM s1.t1 t_1 ORDER BY t_1.c1;
1101
1102 ----
1103 ---- No. A-13-3 output number of times of debugging log
1104 ----
1105
1106 --No.13-3-1
1107 EXPLAIN (COSTS false) SELECT nested_planner(1) FROM s1.t1 t_1 ORDER BY t_1.c1;
1108 /*+SeqScan(t_2)*/
1109 EXPLAIN (COSTS false) SELECT nested_planner(1) FROM s1.t1 t_1 ORDER BY t_1.c1;
1110
1111 --No.13-3-2
1112 EXPLAIN (COSTS false) SELECT nested_planner(2) FROM s1.t1 t_1 ORDER BY t_1.c1;
1113 /*+SeqScan(t_2)*/
1114 EXPLAIN (COSTS false) SELECT nested_planner(2) FROM s1.t1 t_1 ORDER BY t_1.c1;
1115
1116 --No.13-3-3
1117 --
1118 -- Redefine not to use cached plan
1119 --
1120 CREATE OR REPLACE FUNCTION nested_planner(cnt int) RETURNS int AS $$
1121 DECLARE
1122     new_cnt int;
1123 BEGIN
1124     RAISE NOTICE 'nested_planner(%)', cnt;
1125
1126     /* 再帰終了の判断 */
1127     IF cnt <= 1 THEN
1128         RETURN 0;
1129     END IF;
1130
1131         SELECT /*+ IndexScan(t_1) */ nested_planner(cnt - 1) INTO new_cnt
1132           FROM s1.t1 t_1
1133           JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1134          ORDER BY t_1.c1 LIMIT 1;
1135
1136     RETURN new_cnt;
1137 END;
1138 $$ LANGUAGE plpgsql IMMUTABLE;
1139
1140 -- The function called at the bottom desn't use a hint, the immediate
1141 -- caller level should restore its own hint. So, the first LOG from
1142 -- pg_hint_plan should use the IndexScan(t_1) hint
1143 EXPLAIN (COSTS false) SELECT nested_planner(5) FROM s1.t1 t_1 ORDER BY t_1.c1;
1144
1145 -- The top level uses SeqScan(t_1), but the function should use only
1146 -- the hint in the function.
1147 /*+SeqScan(t_1) SeqScan(t_2)*/
1148 EXPLAIN (COSTS false) SELECT nested_planner(5) FROM s1.t1 t_1 ORDER BY t_1.c1;
1149
1150 ----
1151 ---- No. A-13-4 output of debugging log on hint status
1152 ----
1153 CREATE OR REPLACE FUNCTION recall_planner() RETURNS int AS $$
1154         SELECT /*+ IndexScan(t_1) */t_1.c1
1155           FROM s1.t1 t_1
1156           JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1157          ORDER BY t_1.c1 LIMIT 1;
1158 $$ LANGUAGE SQL IMMUTABLE;
1159
1160 --No.13-4-1
1161 -- recall_planner() is reduced to constant while planning using the
1162 -- hint defined in the function. Then the outer query is planned based
1163 -- on the following hint. pg_hint_plan shows the log for the function
1164 -- but the resulting explain output doesn't contain the corresponding
1165 -- plan.
1166 /*+HashJoin(t_1 t_2)*/
1167 EXPLAIN (COSTS false)
1168  SELECT recall_planner() FROM s1.t1 t_1
1169    JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1170   ORDER BY t_1.c1;
1171
1172 --No.13-4-2
1173 --See description for No.13-4-1
1174 /*+HashJoin(st_1 st_2)*/
1175 EXPLAIN (COSTS false)
1176  SELECT recall_planner() FROM s1.t1 st_1
1177    JOIN s1.t2 st_2 ON (st_1.c1 = st_2.c1)
1178   ORDER BY st_1.c1;
1179
1180 --No.13-4-3
1181 --See description for No.13-4-1
1182 /*+HashJoin(t_1 t_2)*/
1183 EXPLAIN (COSTS false)
1184  SELECT recall_planner() FROM s1.t1 st_1
1185    JOIN s1.t2 st_2 ON (st_1.c1 = st_2.c1)
1186   ORDER BY st_1.c1;
1187
1188 --No.13-4-4
1189 --See description for No.13-4-1
1190 /*+HashJoin(st_1 st_2)*/
1191 EXPLAIN (COSTS false)
1192  SELECT recall_planner() FROM s1.t1 t_1
1193    JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1194   ORDER BY t_1.c1;
1195
1196 --No.13-4-5
1197 -- See description for No.13-4-1. No joins in ths plan, so
1198 -- pg_hint_plan doesn't complain on the wrongly written error hint.
1199 /*+HashJoin(t_1 t_1)*/
1200 EXPLAIN (COSTS false)
1201  SELECT recall_planner() FROM s1.t1 t_1
1202   ORDER BY t_1.c1;
1203
1204 --No.13-4-6
1205 CREATE OR REPLACE FUNCTION recall_planner_one_t() RETURNS int AS $$
1206         SELECT /*+ IndexScan(t_1) */t_1.c1
1207           FROM s1.t1 t_1
1208          ORDER BY t_1.c1 LIMIT 1;
1209 $$ LANGUAGE SQL IMMUTABLE;
1210
1211 EXPLAIN (COSTS false)
1212  SELECT recall_planner_one_t() FROM s1.t1 t_1
1213    JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1214   ORDER BY t_1.c1;
1215 /*+HashJoin(t_1 t_1)*/
1216 EXPLAIN (COSTS false)
1217  SELECT recall_planner_one_t() FROM s1.t1 t_1
1218    JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1219   ORDER BY t_1.c1;
1220
1221 DROP FUNCTION recall_planner_one_t(int);
1222
1223 --No.13-4-7
1224 -- See description for No.13-4-1. Complains on the wrongly written hint.
1225 /*+HashJoin(t_1 t_1)*/
1226 EXPLAIN (COSTS false)
1227  SELECT recall_planner() FROM s1.t1 t_1
1228    JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1229   ORDER BY t_1.c1;
1230
1231 --No.13-4-8
1232 /*+MergeJoin(t_1 t_2)HashJoin(t_1 t_2)*/
1233 EXPLAIN (COSTS false)
1234  SELECT recall_planner() FROM s1.t1 t_1
1235    JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
1236   ORDER BY t_1.c1;
1237
1238 --No.14-1-1 plancache invalidation
1239 CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
1240 CREATE INDEX ON s1.tpc(a);
1241 PREPARE p1 AS SELECT * FROM s1.tpc WHERE a < 999;
1242 /*+ IndexScan(tpc) */PREPARE p2 AS SELECT * FROM s1.tpc WHERE a < 999;
1243 /*+ SeqScan(tpc) */PREPARE p3(int) AS SELECT * FROM s1.tpc WHERE a = $1;
1244 EXPLAIN EXECUTE p1;
1245 EXPLAIN EXECUTE p2;
1246 EXPLAIN EXECUTE p3(500);
1247 -- The DROP invalidates the plan caches
1248 DROP TABLE s1.tpc;
1249 CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
1250 CREATE INDEX ON s1.tpc(a);
1251 EXPLAIN EXECUTE p1;
1252 EXPLAIN EXECUTE p2;
1253 EXPLAIN EXECUTE p3(500);
1254 DEALLOCATE p1;
1255 DEALLOCATE p2;
1256 DEALLOCATE p3;
1257 DROP TABLE s1.tpc;