• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revisioneb2d8f38945415d347e580f8dedaa860ae5bd181 (tree)
Time2020-02-14 16:31:26
AuthorKyotaro Horiguchi <horikyota.ntt@gmai...>
CommiterKyotaro Horiguchi

Log Message

Fix behavior of nested planning

Issue: https://github.com/ossc-db/pg_hint_plan/issues/39

When planning is nested by function call, the hints in the function
should affect the corresponding query. Maybe 9599067 introduced
that. Fix the nested planning behavior.

Change Summary

Incremental Difference

--- a/expected/ut-A.out
+++ b/expected/ut-A.out
@@ -4289,6 +4289,11 @@ CREATE OR REPLACE FUNCTION recall_planner() RETURNS int AS $$
42894289 ORDER BY t_1.c1 LIMIT 1;
42904290 $$ LANGUAGE SQL IMMUTABLE;
42914291 --No.13-4-1
4292+-- recall_planner() is reduced to constant while planning using the
4293+-- hint defined in the function. Then the outer query is planned based
4294+-- on the following hint. pg_hint_plan shows the log for the function
4295+-- but the resulting explain output doesn't contain the corresponding
4296+-- plan.
42924297 /*+HashJoin(t_1 t_2)*/
42934298 EXPLAIN (COSTS false)
42944299 SELECT recall_planner() FROM s1.t1 t_1
@@ -4296,7 +4301,7 @@ EXPLAIN (COSTS false)
42964301 ORDER BY t_1.c1;
42974302 LOG: pg_hint_plan:
42984303 used hint:
4299-HashJoin(t_1 t_2)
4304+IndexScan(t_1)
43004305 not used hint:
43014306 duplication hint:
43024307 error hint:
@@ -4320,6 +4325,7 @@ error hint:
43204325 (7 rows)
43214326
43224327 --No.13-4-2
4328+--See description for No.13-4-1
43234329 /*+HashJoin(st_1 st_2)*/
43244330 EXPLAIN (COSTS false)
43254331 SELECT recall_planner() FROM s1.t1 st_1
@@ -4327,8 +4333,8 @@ EXPLAIN (COSTS false)
43274333 ORDER BY st_1.c1;
43284334 LOG: pg_hint_plan:
43294335 used hint:
4336+IndexScan(t_1)
43304337 not used hint:
4331-HashJoin(st_1 st_2)
43324338 duplication hint:
43334339 error hint:
43344340
@@ -4351,6 +4357,7 @@ error hint:
43514357 (7 rows)
43524358
43534359 --No.13-4-3
4360+--See description for No.13-4-1
43544361 /*+HashJoin(t_1 t_2)*/
43554362 EXPLAIN (COSTS false)
43564363 SELECT recall_planner() FROM s1.t1 st_1
@@ -4358,7 +4365,7 @@ EXPLAIN (COSTS false)
43584365 ORDER BY st_1.c1;
43594366 LOG: pg_hint_plan:
43604367 used hint:
4361-HashJoin(t_1 t_2)
4368+IndexScan(t_1)
43624369 not used hint:
43634370 duplication hint:
43644371 error hint:
@@ -4381,6 +4388,7 @@ error hint:
43814388 (6 rows)
43824389
43834390 --No.13-4-4
4391+--See description for No.13-4-1
43844392 /*+HashJoin(st_1 st_2)*/
43854393 EXPLAIN (COSTS false)
43864394 SELECT recall_planner() FROM s1.t1 t_1
@@ -4388,8 +4396,8 @@ EXPLAIN (COSTS false)
43884396 ORDER BY t_1.c1;
43894397 LOG: pg_hint_plan:
43904398 used hint:
4399+IndexScan(t_1)
43914400 not used hint:
4392-HashJoin(st_1 st_2)
43934401 duplication hint:
43944402 error hint:
43954403
@@ -4411,18 +4419,18 @@ error hint:
44114419 (6 rows)
44124420
44134421 --No.13-4-5
4422+-- See description for No.13-4-1. No joins in ths plan, so
4423+-- pg_hint_plan doesn't complain on the wrongly written error hint.
44144424 /*+HashJoin(t_1 t_1)*/
44154425 EXPLAIN (COSTS false)
44164426 SELECT recall_planner() FROM s1.t1 t_1
44174427 ORDER BY t_1.c1;
4418-INFO: pg_hint_plan: hint syntax error at or near "HashJoin(t_1 t_1)"
4419-DETAIL: Relation name "t_1" is duplicated.
44204428 LOG: pg_hint_plan:
44214429 used hint:
4430+IndexScan(t_1)
44224431 not used hint:
44234432 duplication hint:
44244433 error hint:
4425-HashJoin(t_1 t_1)
44264434
44274435 LOG: pg_hint_plan:
44284436 used hint:
@@ -4446,6 +4454,13 @@ EXPLAIN (COSTS false)
44464454 SELECT recall_planner_one_t() FROM s1.t1 t_1
44474455 JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
44484456 ORDER BY t_1.c1;
4457+LOG: pg_hint_plan:
4458+used hint:
4459+IndexScan(t_1)
4460+not used hint:
4461+duplication hint:
4462+error hint:
4463+
44494464 QUERY PLAN
44504465 ---------------------------------------------
44514466 Merge Join
@@ -4463,8 +4478,8 @@ EXPLAIN (COSTS false)
44634478 ORDER BY t_1.c1;
44644479 LOG: pg_hint_plan:
44654480 used hint:
4481+IndexScan(t_1)
44664482 not used hint:
4467-HashJoin(t_1 t_1)
44684483 duplication hint:
44694484 error hint:
44704485
@@ -4490,19 +4505,18 @@ HashJoin(t_1 t_1)
44904505 DROP FUNCTION recall_planner_one_t(int);
44914506 ERROR: function recall_planner_one_t(integer) does not exist
44924507 --No.13-4-7
4508+-- See description for No.13-4-1. Complains on the wrongly written hint.
44934509 /*+HashJoin(t_1 t_1)*/
44944510 EXPLAIN (COSTS false)
44954511 SELECT recall_planner() FROM s1.t1 t_1
44964512 JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
44974513 ORDER BY t_1.c1;
4498-INFO: pg_hint_plan: hint syntax error at or near "HashJoin(t_1 t_1)"
4499-DETAIL: Relation name "t_1" is duplicated.
45004514 LOG: pg_hint_plan:
45014515 used hint:
4516+IndexScan(t_1)
45024517 not used hint:
45034518 duplication hint:
45044519 error hint:
4505-HashJoin(t_1 t_1)
45064520
45074521 INFO: pg_hint_plan: hint syntax error at or near "HashJoin(t_1 t_1)"
45084522 DETAIL: Relation name "t_1" is duplicated.
@@ -4531,14 +4545,11 @@ EXPLAIN (COSTS false)
45314545 ORDER BY t_1.c1;
45324546 INFO: pg_hint_plan: hint syntax error at or near "MergeJoin(t_1 t_2)HashJoin(t_1 t_2)"
45334547 DETAIL: Conflict join method hint.
4534-INFO: pg_hint_plan: hint syntax error at or near "MergeJoin(t_1 t_2)HashJoin(t_1 t_2)"
4535-DETAIL: Conflict join method hint.
45364548 LOG: pg_hint_plan:
45374549 used hint:
4538-HashJoin(t_1 t_2)
4550+IndexScan(t_1)
45394551 not used hint:
45404552 duplication hint:
4541-MergeJoin(t_1 t_2)
45424553 error hint:
45434554
45444555 LOG: pg_hint_plan:
--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -1825,7 +1825,7 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
18251825 * case of DESCRIBE message handling or EXECUTE command. We may still see a
18261826 * candidate top-level query in pstate in the case.
18271827 */
1828- if (!p && pstate)
1828+ if (pstate && pstate->p_sourcetext)
18291829 p = pstate->p_sourcetext;
18301830
18311831 /* We don't see a query string, return NULL */
@@ -3094,6 +3094,7 @@ pg_hint_plan_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
30943094 */
30953095 recurse_level++;
30963096 prev_hint_str = current_hint_str;
3097+ current_hint_str = NULL;
30973098
30983099 /*
30993100 * Use PG_TRY mechanism to recover GUC parameters and current_hint_state to
--- a/sql/ut-A.sql
+++ b/sql/ut-A.sql
@@ -1152,6 +1152,11 @@ CREATE OR REPLACE FUNCTION recall_planner() RETURNS int AS $$
11521152 $$ LANGUAGE SQL IMMUTABLE;
11531153
11541154 --No.13-4-1
1155+-- recall_planner() is reduced to constant while planning using the
1156+-- hint defined in the function. Then the outer query is planned based
1157+-- on the following hint. pg_hint_plan shows the log for the function
1158+-- but the resulting explain output doesn't contain the corresponding
1159+-- plan.
11551160 /*+HashJoin(t_1 t_2)*/
11561161 EXPLAIN (COSTS false)
11571162 SELECT recall_planner() FROM s1.t1 t_1
@@ -1159,6 +1164,7 @@ EXPLAIN (COSTS false)
11591164 ORDER BY t_1.c1;
11601165
11611166 --No.13-4-2
1167+--See description for No.13-4-1
11621168 /*+HashJoin(st_1 st_2)*/
11631169 EXPLAIN (COSTS false)
11641170 SELECT recall_planner() FROM s1.t1 st_1
@@ -1166,6 +1172,7 @@ EXPLAIN (COSTS false)
11661172 ORDER BY st_1.c1;
11671173
11681174 --No.13-4-3
1175+--See description for No.13-4-1
11691176 /*+HashJoin(t_1 t_2)*/
11701177 EXPLAIN (COSTS false)
11711178 SELECT recall_planner() FROM s1.t1 st_1
@@ -1173,6 +1180,7 @@ EXPLAIN (COSTS false)
11731180 ORDER BY st_1.c1;
11741181
11751182 --No.13-4-4
1183+--See description for No.13-4-1
11761184 /*+HashJoin(st_1 st_2)*/
11771185 EXPLAIN (COSTS false)
11781186 SELECT recall_planner() FROM s1.t1 t_1
@@ -1180,6 +1188,8 @@ EXPLAIN (COSTS false)
11801188 ORDER BY t_1.c1;
11811189
11821190 --No.13-4-5
1191+-- See description for No.13-4-1. No joins in ths plan, so
1192+-- pg_hint_plan doesn't complain on the wrongly written error hint.
11831193 /*+HashJoin(t_1 t_1)*/
11841194 EXPLAIN (COSTS false)
11851195 SELECT recall_planner() FROM s1.t1 t_1
@@ -1205,6 +1215,7 @@ EXPLAIN (COSTS false)
12051215 DROP FUNCTION recall_planner_one_t(int);
12061216
12071217 --No.13-4-7
1218+-- See description for No.13-4-1. Complains on the wrongly written hint.
12081219 /*+HashJoin(t_1 t_1)*/
12091220 EXPLAIN (COSTS false)
12101221 SELECT recall_planner() FROM s1.t1 t_1
Show on old repository browser