From: Kyotaro Horiguchi Date: Tue, 16 Dec 2014 04:20:02 +0000 (+0900) Subject: Fix about unexpectedly living plpgsql query string. X-Git-Tag: REL93_1_1_2~8 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1f489193eca11d14e223f4f288990525254d6c24;p=pghintplan%2Fpg_hint_plan.git Fix about unexpectedly living plpgsql query string. 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. --- diff --git a/pg_hint_plan.c b/pg_hint_plan.c index f144e93..bce7812 100644 --- a/pg_hint_plan.c +++ b/pg_hint_plan.c @@ -527,7 +527,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, @@ -4068,7 +4070,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; + } } /* @@ -4079,7 +4084,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; }