projects
/
plantuner.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
also check IsTransactionState, it helps support of pg_reload_config
[plantuner.git]
/
plantuner.c
diff --git
a/plantuner.c
b/plantuner.c
index
4e89d91
..
3c5c6c7
100644
(file)
--- a/
plantuner.c
+++ b/
plantuner.c
@@
-30,7
+30,9
@@
#include <postgres.h>
#include <fmgr.h>
#include <postgres.h>
#include <fmgr.h>
+#include <miscadmin.h>
#include <access/heapam.h>
#include <access/heapam.h>
+#include <access/xact.h>
#include <catalog/namespace.h>
#include <catalog/pg_class.h>
#include <nodes/pg_list.h>
#include <catalog/namespace.h>
#include <catalog/pg_class.h>
#include <nodes/pg_list.h>
@@
-40,6
+42,10
@@
#include <utils/guc.h>
#include <utils/lsyscache.h>
#include <utils/rel.h>
#include <utils/guc.h>
#include <utils/lsyscache.h>
#include <utils/rel.h>
+#if PG_VERSION_NUM >= 100000
+#include <utils/regproc.h>
+#include <utils/varlena.h>
+#endif
PG_MODULE_MAGIC;
PG_MODULE_MAGIC;
@@
-54,6
+60,8
@@
static char *enableIndexesOutStr = "";
get_relation_info_hook_type prevHook = NULL;
static bool fix_empty_table = false;
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)
static const char *
indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable)
@@
-70,6
+78,23
@@
indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable)
if (!SplitIdentifierString(rawname, ',', &namelist))
goto cleanup;
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);
if (doit)
{
nOids = list_length(namelist);
@@
-79,6
+104,11
@@
indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable)
(int)(sizeof(Oid) * (nOids+1)));
}
(int)(sizeof(Oid) * (nOids+1)));
}
+ if (isDisable)
+ plantuner_disable_inited = true;
+ else
+ plantuner_enable_inited = true;
+
foreach(l, namelist)
{
char *curname = (char *) lfirst(l);
foreach(l, namelist)
{
char *curname = (char *) lfirst(l);
@@
-118,12
+148,16
@@
indexesAssign(const char * newval, bool doit, GucSource source, bool isDisable)
{
if (isDisable)
{
{
if (isDisable)
{
- nDisabledIndexes = nOids;
+ nDisabledIndexes = i;
+ if (disabledIndexes)
+ free(disabledIndexes);
disabledIndexes = newOids;
}
else
{
disabledIndexes = newOids;
}
else
{
- nEnabledIndexes = nOids;
+ nEnabledIndexes = i;
+ if (enabledIndexes)
+ free(enabledIndexes);
enabledIndexes = newOids;
}
}
enabledIndexes = newOids;
}
}
@@
-153,6
+187,15
@@
assignEnabledIndexes(const char * newval, bool doit, GucSource source)
return indexesAssign(newval, doit, source, false);
}
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
#if PG_VERSION_NUM >= 90100
static bool
@@
-207,6
+250,8
@@
indexFilter(PlannerInfo *root, Oid relationObjectId, bool inhparent,
{
int i;
{
int i;
+ lateInit();
+
for(i=0;i<nDisabledIndexes;i++)
{
ListCell *l;
for(i=0;i<nDisabledIndexes;i++)
{
ListCell *l;
@@
-269,6
+314,8
@@
IndexFilterShow(Oid* indexes, int nIndexes)
int i,
len;
int i,
len;
+ lateInit();
+
len = 1 /* \0 */ + nIndexes * (2 * NAMEDATALEN + 2 /* ', ' */ + 1 /* . */);
ptr = val = palloc(len);
len = 1 /* \0 */ + nIndexes * (2 * NAMEDATALEN + 2 /* ', ' */ + 1 /* . */);
ptr = val = palloc(len);