X-Git-Url: http://www.sigaev.ru/git/gitweb.cgi?p=plantuner.git;a=blobdiff_plain;f=plantuner.c;h=85954637707b817522f1c4722e719e35e54a3691;hp=458236ebe79cb508efcd55b0aa53224d6f0dc2e4;hb=0bfe8d22e41a4a690ef9ca950f56c65ef194fe4d;hpb=c652b3f04b5123c4731858c37bf3a6abd820bd13 diff --git a/plantuner.c b/plantuner.c index 458236e..8595463 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,22 @@ 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 || + !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 +103,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); @@ -122,12 +147,16 @@ indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) { if (isDisable) { - nDisabledIndexes = nOids; + nDisabledIndexes = i; + if (disabledIndexes) + free(disabledIndexes); disabledIndexes = newOids; } else { - nEnabledIndexes = nOids; + nEnabledIndexes = i; + if (enabledIndexes) + free(enabledIndexes); enabledIndexes = newOids; } } @@ -157,6 +186,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 @@ -211,6 +249,8 @@ indexFilter(PlannerInfo *root, Oid relationObjectId, bool inhparent, { int i; + lateInit(); + for(i=0;ipages = 0.0; + rel->pages = 1.0; rel->tuples = 0.0; } @@ -273,6 +313,8 @@ IndexFilterShow(Oid* indexes, int nIndexes) int i, len; + lateInit(); + len = 1 /* \0 */ + nIndexes * (2 * NAMEDATALEN + 2 /* ', ' */ + 1 /* . */); ptr = val = palloc(len);