OSDN Git Service

Fix a crash bug in case debug_query_string is NULL
authorKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Thu, 24 May 2018 09:18:29 +0000 (18:18 +0900)
committerKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Fri, 8 Jun 2018 01:02:10 +0000 (10:02 +0900)
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

index 896b50c..9549c70 100644 (file)
@@ -1659,6 +1659,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;