• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revision5762a54432a7fcf47984c9a452d13e9b43fbae60 (tree)
Time2014-12-18 16:37:12
AuthorKyotaro Horiguchi <horiguchi.kyotaro@lab....>
CommiterKyotaro Horiguchi

Log Message

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.

Change Summary

Incremental Difference

--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -32,6 +32,7 @@
3232 #include "utils/memutils.h"
3333 #include "utils/rel.h"
3434 #include "utils/syscache.h"
35+#include "utils/resowner.h"
3536
3637 #include "catalog/pg_class.h"
3738
@@ -430,6 +431,10 @@ static void pg_hint_plan_plpgsql_stmt_beg(PLpgSQL_execstate *estate,
430431 PLpgSQL_stmt *stmt);
431432 static void pg_hint_plan_plpgsql_stmt_end(PLpgSQL_execstate *estate,
432433 PLpgSQL_stmt *stmt);
434+static void plpgsql_query_erase_callback(ResourceReleasePhase phase,
435+ bool isCommit,
436+ bool isTopLevel,
437+ void *arg);
433438
434439 /* GUC variables */
435440 static bool pg_hint_plan_enable_hint = true;
@@ -623,6 +628,8 @@ _PG_init(void)
623628 /* setup PL/pgSQL plugin hook */
624629 var_ptr = (PLpgSQL_plugin **) find_rendezvous_variable("PLpgSQL_plugin");
625630 *var_ptr = &plugin_funcs;
631+
632+ RegisterResourceReleaseCallback(plpgsql_query_erase_callback, NULL);
626633 }
627634
628635 /*
@@ -4089,6 +4096,17 @@ pg_hint_plan_plpgsql_stmt_end(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
40894096 plpgsql_query_string = NULL;
40904097 }
40914098
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+
40924110 #define standard_join_search pg_hint_plan_standard_join_search
40934111 #define join_search_one_level pg_hint_plan_join_search_one_level
40944112 #define make_join_rel make_join_rel_wrapper
Show on old repository browser