リビジョン | 439b0a98dbe1674a39da1d56d305a3db3898c1c7 (tree) |
---|---|
日時 | 2014-12-17 10:47:23 |
作者 | 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 | #if PG_VERSION_NUM >= 90200 |
36 | 37 | #include "catalog/pg_class.h" |
37 | 38 | #endif |
@@ -409,6 +410,10 @@ static void pg_hint_plan_plpgsql_stmt_beg(PLpgSQL_execstate *estate, | ||
409 | 410 | PLpgSQL_stmt *stmt); |
410 | 411 | static void pg_hint_plan_plpgsql_stmt_end(PLpgSQL_execstate *estate, |
411 | 412 | PLpgSQL_stmt *stmt); |
413 | +static void plpgsql_query_erase_callback(ResourceReleasePhase phase, | |
414 | + bool isCommit, | |
415 | + bool isTopLevel, | |
416 | + void *arg); | |
412 | 417 | |
413 | 418 | /* GUC variables */ |
414 | 419 | static bool pg_hint_plan_enable_hint = true; |
@@ -573,6 +578,8 @@ _PG_init(void) | ||
573 | 578 | /* setup PL/pgSQL plugin hook */ |
574 | 579 | var_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin"); |
575 | 580 | *var_ptr = &plugin_funcs; |
581 | + | |
582 | + RegisterResourceReleaseCallback(plpgsql_query_erase_callback, NULL); | |
576 | 583 | } |
577 | 584 | |
578 | 585 | /* |
@@ -3703,6 +3710,17 @@ pg_hint_plan_plpgsql_stmt_end(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt) | ||
3703 | 3710 | plpgsql_query_string = NULL; |
3704 | 3711 | } |
3705 | 3712 | |
3713 | +void plpgsql_query_erase_callback(ResourceReleasePhase phase, | |
3714 | + bool isCommit, | |
3715 | + bool isTopLevel, | |
3716 | + void *arg) | |
3717 | +{ | |
3718 | + if (phase != RESOURCE_RELEASE_AFTER_LOCKS) | |
3719 | + return; | |
3720 | + /* Force erase stored plpgsql query string */ | |
3721 | + plpgsql_query_string = NULL; | |
3722 | +} | |
3723 | + | |
3706 | 3724 | #define standard_join_search pg_hint_plan_standard_join_search |
3707 | 3725 | #define join_search_one_level pg_hint_plan_join_search_one_level |
3708 | 3726 | #define make_join_rel make_join_rel_wrapper |