OSDN Git Service

Fix about unexpectedly living plpgsql query string.
authorKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Tue, 16 Dec 2014 04:20:02 +0000 (13:20 +0900)
committerKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Wed, 17 Dec 2014 01:46:52 +0000 (10:46 +0900)
pg_hint_plan forgot to erase plpgsql query strings when it is NOT a
static statement, so it continued to read hints from the remenbered
wrong query string after using dynamic execution of a statement. This
commit makes it to be erased for any types of pl/pgsql statement.

pg_hint_plan.c

index 11ac127..240a128 100644 (file)
@@ -490,7 +490,9 @@ static const HintParser parsers[] = {
  * PL/pgSQL plugin for retrieving string representation of each query during
  * function execution.
  */
-const char *plpgsql_query_string = NULL;
+static const char *plpgsql_query_string = NULL;
+static enum PLpgSQL_stmt_types plpgsql_query_string_src;
+
 PLpgSQL_plugin  plugin_funcs = {
        NULL,
        NULL,
@@ -3682,7 +3684,10 @@ pg_hint_plan_plpgsql_stmt_beg(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
        }
 
        if (expr)
+       {
                plpgsql_query_string = expr->query;
+               plpgsql_query_string_src = (enum PLpgSQL_stmt_types) stmt->cmd_type;
+       }
 }
 
 /*
@@ -3693,7 +3698,8 @@ pg_hint_plan_plpgsql_stmt_beg(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
 static void
 pg_hint_plan_plpgsql_stmt_end(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
 {
-       if ((enum PLpgSQL_stmt_types) stmt->cmd_type == PLPGSQL_STMT_EXECSQL)
+       if (plpgsql_query_string &&
+               plpgsql_query_string_src == stmt->cmd_type)
                plpgsql_query_string = NULL;
 }