X-Git-Url: http://sigaev.ru/git/gitweb.cgi?p=plantuner.git;a=blobdiff_plain;f=plantuner.c;h=5a1d4809131a329e2e8a153644be2a27a9ee7768;hp=a91bf067bb5f0bc20f6c61459fb21730505952fc;hb=e254f0c16b288a261d2ed1c7c6110223f359d3ff;hpb=6c66d17a2dc6e5372e0136ae495370a359a3f913 diff --git a/plantuner.c b/plantuner.c index a91bf06..5a1d480 100644 --- a/plantuner.c +++ b/plantuner.c @@ -6,13 +6,13 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -40,14 +40,18 @@ #include #include #include +#if PG_VERSION_NUM >= 100000 +#include +#include +#endif PG_MODULE_MAGIC; -static int nDisabledIndexes = 0; +static int nDisabledIndexes = 0; static Oid *disabledIndexes = NULL; static char *disableIndexesOutStr = ""; -static int nEnabledIndexes = 0; +static int nEnabledIndexes = 0; static Oid *enabledIndexes = NULL; static char *enableIndexesOutStr = ""; @@ -56,11 +60,11 @@ static bool fix_empty_table = false; static const char * -indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) +indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) { - char *rawname; - List *namelist; - ListCell *l; + char *rawname; + List *namelist; + ListCell *l; Oid *newOids = NULL; int nOids = 0, i = 0; @@ -70,18 +74,27 @@ indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) if (!SplitIdentifierString(rawname, ',', &namelist)) goto cleanup; - if (doit) + if (doit) { nOids = list_length(namelist); newOids = malloc(sizeof(Oid) * (nOids+1)); if (!newOids) - elog(ERROR,"could not allocate %d bytes", (int)(sizeof(Oid) * (nOids+1))); + elog(ERROR,"could not allocate %d bytes", + (int)(sizeof(Oid) * (nOids+1))); } foreach(l, namelist) { - char *curname = (char *) lfirst(l); - Oid indexOid = RangeVarGetRelid(makeRangeVarFromNameList(stringToQualifiedNameList(curname)), true); + char *curname = (char *) lfirst(l); +#if PG_VERSION_NUM >= 90200 + Oid indexOid = RangeVarGetRelid( + makeRangeVarFromNameList(stringToQualifiedNameList(curname)), + NoLock, true); +#else + Oid indexOid = RangeVarGetRelid( + makeRangeVarFromNameList(stringToQualifiedNameList(curname)), + true); +#endif if (indexOid == InvalidOid) { @@ -105,16 +118,20 @@ indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable) } } - if (doit) + if (doit) { if (isDisable) { - nDisabledIndexes = nOids; + nDisabledIndexes = i; + if (disabledIndexes) + free(disabledIndexes); disabledIndexes = newOids; } else { - nEnabledIndexes = nOids; + nEnabledIndexes = i; + if (enabledIndexes) + free(enabledIndexes); enabledIndexes = newOids; } } @@ -135,13 +152,13 @@ cleanup: static const char * assignDisabledIndexes(const char * newval, bool doit, GucSource source) { - return indexesAssign(newval, doit, source, true); + return indexesAssign(newval, doit, source, true); } static const char * assignEnabledIndexes(const char * newval, bool doit, GucSource source) { - return indexesAssign(newval, doit, source, false); + return indexesAssign(newval, doit, source, false); } #if PG_VERSION_NUM >= 90100 @@ -193,7 +210,9 @@ assignEnabledIndexesNew(const char *newval, void *extra) #endif static void -indexFilter(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel) { +indexFilter(PlannerInfo *root, Oid relationObjectId, bool inhparent, + RelOptInfo *rel) +{ int i; for(i=0;ird_rel->relkind == RELKIND_RELATION) @@ -250,28 +264,28 @@ execPlantuner(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInf heap_close(relation, NoLock); /* - * Call next hook if it exists + * Call next hook if it exists */ if (prevHook) prevHook(root, relationObjectId, inhparent, rel); } static const char* -IndexFilterShow(Oid* indexes, int nIndexes) +IndexFilterShow(Oid* indexes, int nIndexes) { - char *val, *ptr; - int i, + char *val, *ptr; + int i, len; len = 1 /* \0 */ + nIndexes * (2 * NAMEDATALEN + 2 /* ', ' */ + 1 /* . */); ptr = val = palloc(len); - *ptr ='\0'; + *ptr =(char)'\0'; for(i=0; i