From 816040df7e7ee159007895743fec7e76f7f10e90 Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi Date: Thu, 24 May 2018 18:18:29 +0900 Subject: [PATCH] Fix a crash bug in case debug_query_string is NULL pg_hint_plan believed that debug_query_string cannot be null when parse_analyze is called, but for example in the case under exec_describe_statement_message, it is not. We see the query string in pstate even in the case, so use it instead in the case. Since pstate is storing the query of the lowermost level, we should use debug_query_string in other cases. --- pg_hint_plan.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pg_hint_plan.c b/pg_hint_plan.c index 7069e3c..87a640e 100644 --- a/pg_hint_plan.c +++ b/pg_hint_plan.c @@ -1803,6 +1803,21 @@ get_query_string(ParseState *pstate, Query *query, Query **jumblequery) { const char *p = debug_query_string; + /* + * If debug_query_string is set, it is the top level statement. But in some + * cases we reach here with debug_query_string set NULL for example in the + * case of DESCRIBE message handling. We may still see a candidate + * top-level query in pstate in the case. + */ + if (!p) + { + /* We don't see a query string, return NULL */ + if (!pstate->p_sourcetext) + return NULL; + + p = pstate->p_sourcetext; + } + if (jumblequery != NULL) *jumblequery = query; -- 2.11.0