static bool pg_hint_plan_enable_hint_table = false;
static int plpgsql_recurse_level = 0; /* PLpgSQL recursion level */
+static int recurse_level = 0; /* recursion level incl. direct SPI calls */
static int hint_inhibit_level = 0; /* Inhibit hinting if this is above 0 */
/* (This could not be above 1) */
static int max_hint_nworkers = -1; /* Maximum nworkers of Workers hints */
{
ParallelHint *hint;
- hint = palloc(sizeof(ScanMethodHint));
+ hint = palloc(sizeof(ParallelHint));
hint->base.hint_str = hint_str;
hint->base.keyword = keyword;
hint->base.hint_keyword = hint_keyword;
int save_nestlevel;
PlannedStmt *result;
HintState *hstate;
+ const char *prev_hint_str;
/*
* Use standard planner if pg_hint_plan is disabled or current nesting
{
MemoryContext oldcontext;
- if (current_hint_str)
- pfree((void *)current_hint_str);
-
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
current_hint_str =
get_hints_from_comment((char *)error_context_stack->arg);
}
/*
+ * The planner call below may replace current_hint_str. Store and restore
+ * it so that the subsequent planning in the upper level doesn't get
+ * confused.
+ */
+ recurse_level++;
+ prev_hint_str = current_hint_str;
+
+ /*
* Use PG_TRY mechanism to recover GUC parameters and current_hint_state to
* the state when this planner started when error occurred in planner.
*/
result = (*prev_planner) (parse, cursorOptions, boundParams);
else
result = standard_planner(parse, cursorOptions, boundParams);
+
+ current_hint_str = prev_hint_str;
+ recurse_level--;
}
PG_CATCH();
{
* Rollback changes of GUC parameters, and pop current hint context
* from hint stack to rewind the state.
*/
+ current_hint_str = prev_hint_str;
+ recurse_level--;
AtEOXact_GUC(true, save_nestlevel);
pop_hint();
PG_RE_THROW();
/*
* current_hint_str is useless after planning of the top-level query.
*/
- if (plpgsql_recurse_level < 1 && current_hint_str)
+ if (recurse_level < 1 && current_hint_str)
{
pfree((void *)current_hint_str);
current_hint_str = NULL;