+ * Retrieve hint string from the current query.
+ */
+static void
+pg_hint_plan_post_parse_analyze(ParseState *pstate, Query *query)
+{
+ if (prev_post_parse_analyze_hook)
+ prev_post_parse_analyze_hook(pstate, query);
+
+ /* always retrieve hint from the top-level query string */
+ if (plpgsql_recurse_level == 0)
+ current_hint_retrieved = false;
+
+ get_current_hint_string(pstate, query);
+}
+
+/*
+ * We need to reset current_hint_retrieved flag always when a command execution
+ * is finished. This is true even for a pure utility command that doesn't
+ * involve planning phase.
+ */
+static void
+pg_hint_plan_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
+ ProcessUtilityContext context,
+ ParamListInfo params, QueryEnvironment *queryEnv,
+ DestReceiver *dest, char *completionTag)
+{
+ if (prev_ProcessUtility_hook)
+ prev_ProcessUtility_hook(pstmt, queryString, context, params, queryEnv,
+ dest, completionTag);
+ else
+ standard_ProcessUtility(pstmt, queryString, context, params, queryEnv,
+ dest, completionTag);
+
+ if (plpgsql_recurse_level == 0)
+ current_hint_retrieved = false;
+}
+
+/*