• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revision4e3c9871ca22d4a5916c1d659787bca3cb09a184 (tree)
Time2020-02-14 15:57:35
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
@@ -4415,6 +4415,11 @@ CREATE OR REPLACE FUNCTION recall_planner() RETURNS int AS $$
44154415 ORDER BY t_1.c1 LIMIT 1;
44164416 $$ LANGUAGE SQL IMMUTABLE;
44174417 --No.13-4-1
4418+-- recall_planner() is reduced to constant while planning using the
4419+-- hint defined in the function. Then the outer query is planned based
4420+-- on the following hint. pg_hint_plan shows the log for the function
4421+-- but the resulting explain output doesn't contain the corresponding
4422+-- plan.
44184423 /*+HashJoin(t_1 t_2)*/
44194424 EXPLAIN (COSTS false)
44204425 SELECT recall_planner() FROM s1.t1 t_1
@@ -4422,7 +4427,7 @@ EXPLAIN (COSTS false)
44224427 ORDER BY t_1.c1;
44234428 LOG: pg_hint_plan:
44244429 used hint:
4425-HashJoin(t_1 t_2)
4430+IndexScan(t_1)
44264431 not used hint:
44274432 duplication hint:
44284433 error hint:
@@ -4446,6 +4451,7 @@ error hint:
44464451 (7 rows)
44474452
44484453 --No.13-4-2
4454+--See description for No.13-4-1
44494455 /*+HashJoin(st_1 st_2)*/
44504456 EXPLAIN (COSTS false)
44514457 SELECT recall_planner() FROM s1.t1 st_1
@@ -4453,8 +4459,8 @@ EXPLAIN (COSTS false)
44534459 ORDER BY st_1.c1;
44544460 LOG: pg_hint_plan:
44554461 used hint:
4462+IndexScan(t_1)
44564463 not used hint:
4457-HashJoin(st_1 st_2)
44584464 duplication hint:
44594465 error hint:
44604466
@@ -4477,6 +4483,7 @@ error hint:
44774483 (7 rows)
44784484
44794485 --No.13-4-3
4486+--See description for No.13-4-1
44804487 /*+HashJoin(t_1 t_2)*/
44814488 EXPLAIN (COSTS false)
44824489 SELECT recall_planner() FROM s1.t1 st_1
@@ -4484,7 +4491,7 @@ EXPLAIN (COSTS false)
44844491 ORDER BY st_1.c1;
44854492 LOG: pg_hint_plan:
44864493 used hint:
4487-HashJoin(t_1 t_2)
4494+IndexScan(t_1)
44884495 not used hint:
44894496 duplication hint:
44904497 error hint:
@@ -4507,6 +4514,7 @@ error hint:
45074514 (6 rows)
45084515
45094516 --No.13-4-4
4517+--See description for No.13-4-1
45104518 /*+HashJoin(st_1 st_2)*/
45114519 EXPLAIN (COSTS false)
45124520 SELECT recall_planner() FROM s1.t1 t_1
@@ -4514,8 +4522,8 @@ EXPLAIN (COSTS false)
45144522 ORDER BY t_1.c1;
45154523 LOG: pg_hint_plan:
45164524 used hint:
4525+IndexScan(t_1)
45174526 not used hint:
4518-HashJoin(st_1 st_2)
45194527 duplication hint:
45204528 error hint:
45214529
@@ -4537,18 +4545,18 @@ error hint:
45374545 (6 rows)
45384546
45394547 --No.13-4-5
4548+-- See description for No.13-4-1. No joins in ths plan, so
4549+-- pg_hint_plan doesn't complain on the wrongly written error hint.
45404550 /*+HashJoin(t_1 t_1)*/
45414551 EXPLAIN (COSTS false)
45424552 SELECT recall_planner() FROM s1.t1 t_1
45434553 ORDER BY t_1.c1;
4544-INFO: pg_hint_plan: hint syntax error at or near "HashJoin(t_1 t_1)"
4545-DETAIL: Relation name "t_1" is duplicated.
45464554 LOG: pg_hint_plan:
45474555 used hint:
4556+IndexScan(t_1)
45484557 not used hint:
45494558 duplication hint:
45504559 error hint:
4551-HashJoin(t_1 t_1)
45524560
45534561 LOG: pg_hint_plan:
45544562 used hint:
@@ -4572,6 +4580,13 @@ EXPLAIN (COSTS false)
45724580 SELECT recall_planner_one_t() FROM s1.t1 t_1
45734581 JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
45744582 ORDER BY t_1.c1;
4583+LOG: pg_hint_plan:
4584+used hint:
4585+IndexScan(t_1)
4586+not used hint:
4587+duplication hint:
4588+error hint:
4589+
45754590 QUERY PLAN
45764591 ---------------------------------------------
45774592 Merge Join
@@ -4589,8 +4604,8 @@ EXPLAIN (COSTS false)
45894604 ORDER BY t_1.c1;
45904605 LOG: pg_hint_plan:
45914606 used hint:
4607+IndexScan(t_1)
45924608 not used hint:
4593-HashJoin(t_1 t_1)
45944609 duplication hint:
45954610 error hint:
45964611
@@ -4616,19 +4631,18 @@ HashJoin(t_1 t_1)
46164631 DROP FUNCTION recall_planner_one_t(int);
46174632 ERROR: function recall_planner_one_t(integer) does not exist
46184633 --No.13-4-7
4634+-- See description for No.13-4-1. Complains on the wrongly written hint.
46194635 /*+HashJoin(t_1 t_1)*/
46204636 EXPLAIN (COSTS false)
46214637 SELECT recall_planner() FROM s1.t1 t_1
46224638 JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
46234639 ORDER BY t_1.c1;
4624-INFO: pg_hint_plan: hint syntax error at or near "HashJoin(t_1 t_1)"
4625-DETAIL: Relation name "t_1" is duplicated.
46264640 LOG: pg_hint_plan:
46274641 used hint:
4642+IndexScan(t_1)
46284643 not used hint:
46294644 duplication hint:
46304645 error hint:
4631-HashJoin(t_1 t_1)
46324646
46334647 INFO: pg_hint_plan: hint syntax error at or near "HashJoin(t_1 t_1)"
46344648 DETAIL: Relation name "t_1" is duplicated.
@@ -4657,14 +4671,11 @@ EXPLAIN (COSTS false)
46574671 ORDER BY t_1.c1;
46584672 INFO: pg_hint_plan: hint syntax error at or near "MergeJoin(t_1 t_2)HashJoin(t_1 t_2)"
46594673 DETAIL: Conflict join method hint.
4660-INFO: pg_hint_plan: hint syntax error at or near "MergeJoin(t_1 t_2)HashJoin(t_1 t_2)"
4661-DETAIL: Conflict join method hint.
46624674 LOG: pg_hint_plan:
46634675 used hint:
4664-HashJoin(t_1 t_2)
4676+IndexScan(t_1)
46654677 not used hint:
46664678 duplication hint:
4667-MergeJoin(t_1 t_2)
46684679 error hint:
46694680
46704681 LOG: pg_hint_plan:
--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -1816,7 +1816,7 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery)
18161816 * case of DESCRIBE message handling or EXECUTE command. We may still see a
18171817 * candidate top-level query in pstate in the case.
18181818 */
1819- if (!p && pstate)
1819+ if (pstate && pstate->p_sourcetext)
18201820 p = pstate->p_sourcetext;
18211821
18221822 /* We don't see a query string, return NULL */
@@ -3085,6 +3085,7 @@ pg_hint_plan_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
30853085 */
30863086 recurse_level++;
30873087 prev_hint_str = current_hint_str;
3088+ current_hint_str = NULL;
30883089
30893090 /*
30903091 * 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