#include "postgres.h"
#include "pgstat.h"
+#include "miscadmin.h"
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/namespace.h"
int nTables;
Oid *tables;
char *tableStr;
+ bool inited;
} TableList;
-static TableList excludeTables = {0, NULL, NULL};
-static TableList includeTables = {0, NULL, NULL};
+static TableList excludeTables = {0, NULL, NULL, false};
+static TableList includeTables = {0, NULL, NULL, false};
typedef struct OnlineAnalyzeTableStat {
Oid tableid;
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())
+ {
+ includeTables.inited = false;
+ excludeTables.inited = false;
+ return newval;
+ }
+
if (doit)
{
nOids = list_length(namelist);
static void
includeTablesAssign(const char *newval, void *extra)
{
- tableListAssign(newval, true, &excludeTables);
+ tableListAssign(newval, true, &includeTables);
}
#else /* PG_VERSION_NUM < 90100 */
#endif
+static void
+lateInit()
+{
+ TableList *tl[] = {&includeTables, &excludeTables};
+ int i;
+
+ if (MyBackendId == InvalidBackendId || !IsUnderPostmaster ||
+ !IsTransactionState())
+ return; /* we aren't in connected state */
+
+ for(i=0; i<lengthof(tl); i++)
+ {
+ TableList *tbl = tl[i];
+
+ if (tbl->inited == false)
+ tableListAssign(tbl->tableStr, true, tbl);
+ tbl->inited = true;
+ }
+}
+
static const char*
tableListShow(TableList *tbl)
{
int i,
len;
+ lateInit();
+
len = 1 /* \0 */ + tbl->nTables * (2 * NAMEDATALEN + 2 /* ', ' */ + 1 /* . */);
ptr = val = palloc(len);
*ptr ='\0';
TimestampTz startStamp, endStamp;
int flags;
+#ifdef PGPRO_EE
+ /* ATX is not compatible with online_analyze */
+ if (getNestLevelATX() != 0)
+ return;
+#endif
memset(&startStamp, 0, sizeof(startStamp)); /* keep compiler quiet */
case CK_INSERT:
case CK_UPDATE:
rstat->n_tuples += naffected;
+ /* FALLTHROUGH */
case CK_DELETE:
rstat->rereadStat = (reltype == OATT_PERSISTENT);
break;
case CK_UPDATE:
rstat->changes_since_analyze += 2 * naffected;
rstat->n_tuples += naffected;
+ break;
case CK_DELETE:
rstat->changes_since_analyze += naffected;
break;
if (queryDesc->estate)
naffected = queryDesc->estate->es_processed;
+ lateInit();
+
#if PG_VERSION_NUM >= 90200
if (online_analyze_enable &&
(constval = isFastTruncateCall(queryDesc)) != NULL)
Node *parsetree,
#endif
const char *queryString,
+#if PG_VERSION_NUM >= 140000
+ bool readOnlyTree,
+#endif
#if PG_VERSION_NUM >= 90300
ProcessUtilityContext context, ParamListInfo params,
#if PG_VERSION_NUM >= 100000
parsetree = pstmt->utilityStmt;
#endif
+ lateInit();
+
if (parsetree && online_analyze_enable)
{
if (IsA(parsetree, CreateTableAsStmt) &&
if (oldProcessUtilityHook)
oldProcessUtilityHook(parsetree, queryString,
+#if PG_VERSION_NUM >= 140000
+ readOnlyTree,
+#endif
#if PG_VERSION_NUM >= 90300
context, params,
#if PG_VERSION_NUM >= 100000
dest, completionTag);
else
standard_ProcessUtility(parsetree, queryString,
+#if PG_VERSION_NUM >= 140000
+ readOnlyTree,
+#endif
#if PG_VERSION_NUM >= 90300
context, params,
#if PG_VERSION_NUM >= 100000
RegisterXactCallback(removeTable, NULL);
}
+#if PG_VERSION_NUM < 150000
void _PG_fini(void);
void
_PG_fini(void)
excludeTables.tables = includeTables.tables = NULL;
excludeTables.nTables = includeTables.nTables = 0;
}
+#endif