X-Git-Url: http://www.sigaev.ru/git/gitweb.cgi?p=plantuner.git;a=blobdiff_plain;f=plantuner.c;h=3c5c6c7dbe5e495ccc2ff16de12a2ebfb6695da4;hp=5a1d4809131a329e2e8a153644be2a27a9ee7768;hb=3c3fe972db47384cef46dbf3f286bda95667d867;hpb=e254f0c16b288a261d2ed1c7c6110223f359d3ff diff --git a/plantuner.c b/plantuner.c index 5a1d480..3c5c6c7 100644 --- a/plantuner.c +++ b/plantuner.c @@ -30,7 +30,9 @@ #include #include +#include #include +#include #include #include #include @@ -58,6 +60,8 @@ static char *enableIndexesOutStr = ""; get_relation_info_hook_type prevHook = NULL; static bool fix_empty_table = false; +static bool plantuner_enable_inited = false; +static bool plantuner_disable_inited = false; static const char * indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) @@ -74,6 +78,23 @@ indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) if (!SplitIdentifierString(rawname, ',', &namelist)) goto cleanup; + /* + * follow work could be done only in normal processing because of + * accsess to system catalog + */ + if (MyBackendId == InvalidBackendId || !IsUnderPostmaster || + !IsNormalProcessingMode() || MyAuxProcType != NotAnAuxProcess || + !IsTransactionState()) + { + /* reset init state */ + if (isDisable) + plantuner_disable_inited = false; + else + plantuner_enable_inited = false; + + return newval; + } + if (doit) { nOids = list_length(namelist); @@ -83,6 +104,11 @@ indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) (int)(sizeof(Oid) * (nOids+1))); } + if (isDisable) + plantuner_disable_inited = true; + else + plantuner_enable_inited = true; + foreach(l, namelist) { char *curname = (char *) lfirst(l); @@ -161,6 +187,15 @@ assignEnabledIndexes(const char * newval, bool doit, GucSource source) return indexesAssign(newval, doit, source, false); } +static void +lateInit() +{ + if (!plantuner_enable_inited) + indexesAssign(enableIndexesOutStr, true, PGC_S_USER, false); + if (!plantuner_disable_inited) + indexesAssign(disableIndexesOutStr, true, PGC_S_USER, true); +} + #if PG_VERSION_NUM >= 90100 static bool @@ -215,6 +250,8 @@ indexFilter(PlannerInfo *root, Oid relationObjectId, bool inhparent, { int i; + lateInit(); + for(i=0;i