• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revision9db100fedece81e8774b299341d266b514627026 (tree)
Time2020-02-17 21:08:52
AuthorKyotaro Horiguchi <horikyota.ntt@gmai...>
CommiterKyotaro Horiguchi

Log Message

Restore current hint state when returned from non-hinted query planning.

If no hint is given for the current level query, pg_hint_plan_planner
calls the next level of planner after erasing the
current_hint_state. But it forgot to restore the state before the
planning of the rest part of the current-level query. It is
(a-kind-of) broken by the commit 2c73975 and d1a839a but overlooked by
assuming the required side-effect of the fix. Get back the behavior
by restoring current_hint_state after returned from the lower level
planner with unhinted query.

Issue: https://github.com/ossc-db/pg_hint_plan/issues/30
Reported-by: higuchi-daisuke

Change Summary

Incremental Difference

--- a/expected/ut-A.out
+++ b/expected/ut-A.out
@@ -4260,7 +4260,12 @@ SQL statement "SELECT /*+ IndexScan(t_1) */ nested_planner(cnt - 1)
42604260 ORDER BY t_1.c1 LIMIT 1"
42614261 PL/pgSQL function nested_planner(integer) line 12 at SQL statement
42624262 LOG: pg_hint_plan:
4263-no hint
4263+used hint:
4264+IndexScan(t_1)
4265+not used hint:
4266+duplication hint:
4267+error hint:
4268+
42644269 CONTEXT: SQL statement "SELECT /*+ IndexScan(t_1) */ nested_planner(cnt - 1) FROM s1.t1 t_1
42654270 JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
42664271 ORDER BY t_1.c1 LIMIT 1"
@@ -4278,7 +4283,12 @@ SQL statement "SELECT /*+ IndexScan(t_1) */ nested_planner(cnt - 1)
42784283 ORDER BY t_1.c1 LIMIT 1"
42794284 PL/pgSQL function nested_planner(integer) line 12 at SQL statement
42804285 LOG: pg_hint_plan:
4281-no hint
4286+used hint:
4287+IndexScan(t_1)
4288+not used hint:
4289+duplication hint:
4290+error hint:
4291+
42824292 CONTEXT: SQL statement "SELECT /*+ IndexScan(t_1) */ nested_planner(cnt - 1) FROM s1.t1 t_1
42834293 JOIN s1.t2 t_2 ON (t_1.c1 = t_2.c1)
42844294 ORDER BY t_1.c1 LIMIT 1"
--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -2858,9 +2858,14 @@ standard_planner_proc:
28582858 }
28592859 current_hint = NULL;
28602860 if (prev_planner)
2861- return (*prev_planner) (parse, cursorOptions, boundParams);
2861+ result = (*prev_planner) (parse, cursorOptions, boundParams);
28622862 else
2863- return standard_planner(parse, cursorOptions, boundParams);
2863+ result = standard_planner(parse, cursorOptions, boundParams);
2864+
2865+ if (HintStateStack)
2866+ current_hint = (HintState *) lfirst(list_head(HintStateStack));
2867+
2868+ return result;
28642869 }
28652870
28662871 /*
Show on old repository browser