|
| 1 | +-- Tests for the query parser |
| 2 | +LOAD 'pg_hint_plan'; |
| 3 | +SET pg_hint_plan.debug_print TO on; |
| 4 | +SET client_min_messages TO LOG; |
| 5 | +SET pg_hint_plan.enable_hint TO on; |
| 6 | +-- Dollar-based constants. |
| 7 | +SELECT $$fox$$ AS constant; |
| 8 | + constant |
| 9 | +---------- |
| 10 | + fox |
| 11 | +(1 row) |
| 12 | + |
| 13 | +SELECT $SomeTag$s fox$SomeTag$ AS constant; |
| 14 | + constant |
| 15 | +---------- |
| 16 | + s fox |
| 17 | +(1 row) |
| 18 | + |
| 19 | +-- Dollar-based constants with quotes embedded. |
| 20 | +SELECT $$Mike's fox$$ AS constant; |
| 21 | + constant |
| 22 | +------------ |
| 23 | + Mike's fox |
| 24 | +(1 row) |
| 25 | + |
| 26 | +SELECT $SomeTag$Mike's fox$SomeTag$ AS constant; |
| 27 | + constant |
| 28 | +------------ |
| 29 | + Mike's fox |
| 30 | +(1 row) |
| 31 | + |
| 32 | +SELECT $$Mike"s fox$$ AS constant; |
| 33 | + constant |
| 34 | +------------ |
| 35 | + Mike"s fox |
| 36 | +(1 row) |
| 37 | + |
| 38 | +SELECT $SomeTag$Mike"s fox$SomeTag$ AS constant; |
| 39 | + constant |
| 40 | +------------ |
| 41 | + Mike"s fox |
| 42 | +(1 row) |
| 43 | + |
| 44 | +CREATE TABLE hint_parser_tab (a int, b int); |
| 45 | +CREATE INDEX hint_parser_ind ON hint_parser_tab(a); |
| 46 | +INSERT INTO hint_parser_tab VALUES (generate_series(1,200), generate_series(1,200)); |
| 47 | +EXPLAIN SELECT /*+ IndexScan (hint_parser_tab hint_parser_ind) */ b |
| 48 | + FROM hint_parser_tab WHERE a = 108; |
| 49 | +LOG: available indexes for IndexScan(hint_parser_tab): hint_parser_ind |
| 50 | +LOG: pg_hint_plan: |
| 51 | +used hint: |
| 52 | +IndexScan(hint_parser_tab hint_parser_ind) |
| 53 | +not used hint: |
| 54 | +duplication hint: |
| 55 | +error hint: |
| 56 | + |
| 57 | + QUERY PLAN |
| 58 | +----------------------------------------------------------------------------------------- |
| 59 | + Index Scan using hint_parser_ind on hint_parser_tab (cost=0.15..36.35 rows=11 width=4) |
| 60 | + Index Cond: (a = 108) |
| 61 | +(2 rows) |
| 62 | + |
| 63 | +SELECT /*+ IndexScan (hint_parser_tab hint_parser_ind) */ b |
| 64 | + FROM hint_parser_tab WHERE a = 108; |
| 65 | +LOG: available indexes for IndexScan(hint_parser_tab): hint_parser_ind |
| 66 | +LOG: pg_hint_plan: |
| 67 | +used hint: |
| 68 | +IndexScan(hint_parser_tab hint_parser_ind) |
| 69 | +not used hint: |
| 70 | +duplication hint: |
| 71 | +error hint: |
| 72 | + |
| 73 | + b |
| 74 | +----- |
| 75 | + 108 |
| 76 | +(1 row) |
| 77 | + |
| 78 | +-- Dollar-quoted constant with hint embedded. |
| 79 | +-- IndexScan used, with SeqScan ignored because it is a query constant. |
| 80 | +EXPLAIN SELECT /*+ IndexScan (hint_parser_tab hint_parser_ind) */ b, |
| 81 | + $$/*+ SeqScan (hint_parser_tab) */$$ AS hint_ignored |
| 82 | + FROM hint_parser_tab WHERE a = 108; |
| 83 | +LOG: available indexes for IndexScan(hint_parser_tab): hint_parser_ind |
| 84 | +LOG: pg_hint_plan: |
| 85 | +used hint: |
| 86 | +IndexScan(hint_parser_tab hint_parser_ind) |
| 87 | +not used hint: |
| 88 | +duplication hint: |
| 89 | +error hint: |
| 90 | + |
| 91 | + QUERY PLAN |
| 92 | +------------------------------------------------------------------------------------------ |
| 93 | + Index Scan using hint_parser_ind on hint_parser_tab (cost=0.15..36.35 rows=11 width=36) |
| 94 | + Index Cond: (a = 108) |
| 95 | +(2 rows) |
| 96 | + |
| 97 | +-- Different dollar-based pattern. |
| 98 | +-- SeqScan used, with IndexScan ignored because it is a query constant. |
| 99 | +EXPLAIN SELECT /*+ SeqScan (hint_parser_tab) */ b, |
| 100 | + $SomeTag$/*+ IndexScan (hint_parser_tab hint_parser_ind */$SomeTag$ AS hint_ignored |
| 101 | + FROM hint_parser_tab WHERE a = 108; |
| 102 | +LOG: pg_hint_plan: |
| 103 | +used hint: |
| 104 | +SeqScan(hint_parser_tab) |
| 105 | +not used hint: |
| 106 | +duplication hint: |
| 107 | +error hint: |
| 108 | + |
| 109 | + QUERY PLAN |
| 110 | +------------------------------------------------------------------ |
| 111 | + Seq Scan on hint_parser_tab (cost=0.00..38.25 rows=11 width=36) |
| 112 | + Filter: (a = 108) |
| 113 | +(2 rows) |
| 114 | + |
| 115 | +DROP TABLE hint_parser_tab; |
0 commit comments