From: Kyotaro Horiguchi Date: Thu, 24 May 2018 09:18:29 +0000 (+0900) Subject: Fix a crash bug in case debug_query_string is NULL X-Git-Tag: REL11_1_3_2~10 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=816040df7e7ee159007895743fec7e76f7f10e90;p=pghintplan%2Fpg_hint_plan.git 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. --- 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;