リビジョン | 5762a54432a7fcf47984c9a452d13e9b43fbae60 (tree) |
---|---|
日時 | 2014-12-18 16:37:12 |
作者 | Kyotaro Horiguchi <horiguchi.kyotaro@lab....> |
コミッター | Kyotaro Horiguchi |
Fix to remove plpgsql query string on non-local exit.
Pl/pgsql query string stored internally squatted after an execution
error then pg_hint_plan afterward read it for hints and ignores really
given ones. This commit makes it erased at the end of transaction.
@@ -32,6 +32,7 @@ | ||
32 | 32 | #include "utils/memutils.h" |
33 | 33 | #include "utils/rel.h" |
34 | 34 | #include "utils/syscache.h" |
35 | +#include "utils/resowner.h" | |
35 | 36 | |
36 | 37 | #include "catalog/pg_class.h" |
37 | 38 |
@@ -430,6 +431,10 @@ static void pg_hint_plan_plpgsql_stmt_beg(PLpgSQL_execstate *estate, | ||
430 | 431 | PLpgSQL_stmt *stmt); |
431 | 432 | static void pg_hint_plan_plpgsql_stmt_end(PLpgSQL_execstate *estate, |
432 | 433 | PLpgSQL_stmt *stmt); |
434 | +static void plpgsql_query_erase_callback(ResourceReleasePhase phase, | |
435 | + bool isCommit, | |
436 | + bool isTopLevel, | |
437 | + void *arg); | |
433 | 438 | |
434 | 439 | /* GUC variables */ |
435 | 440 | static bool pg_hint_plan_enable_hint = true; |
@@ -623,6 +628,8 @@ _PG_init(void) | ||
623 | 628 | /* setup PL/pgSQL plugin hook */ |
624 | 629 | var_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin"); |
625 | 630 | *var_ptr = &plugin_funcs; |
631 | + | |
632 | + RegisterResourceReleaseCallback(plpgsql_query_erase_callback, NULL); | |
626 | 633 | } |
627 | 634 | |
628 | 635 | /* |
@@ -4089,6 +4096,17 @@ pg_hint_plan_plpgsql_stmt_end(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt) | ||
4089 | 4096 | plpgsql_query_string = NULL; |
4090 | 4097 | } |
4091 | 4098 | |
4099 | +void plpgsql_query_erase_callback(ResourceReleasePhase phase, | |
4100 | + bool isCommit, | |
4101 | + bool isTopLevel, | |
4102 | + void *arg) | |
4103 | +{ | |
4104 | + if (phase != RESOURCE_RELEASE_AFTER_LOCKS) | |
4105 | + return; | |
4106 | + /* Force erase stored plpgsql query string */ | |
4107 | + plpgsql_query_string = NULL; | |
4108 | +} | |
4109 | + | |
4092 | 4110 | #define standard_join_search pg_hint_plan_standard_join_search |
4093 | 4111 | #define join_search_one_level pg_hint_plan_join_search_one_level |
4094 | 4112 | #define make_join_rel make_join_rel_wrapper |