2 * Copyright (c) 2011 Teodor Sigaev <teodor@sigaev.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "access/transam.h"
34 #include "access/xact.h"
35 #include "catalog/namespace.h"
36 #include "commands/vacuum.h"
37 #include "executor/executor.h"
38 #include "nodes/nodes.h"
39 #include "nodes/parsenodes.h"
40 #include "storage/bufmgr.h"
41 #include "utils/builtins.h"
42 #include "utils/hsearch.h"
43 #include "utils/memutils.h"
44 #include "utils/lsyscache.h"
45 #include "utils/guc.h"
46 #if PG_VERSION_NUM >= 90200
47 #include "catalog/pg_class.h"
48 #include "nodes/primnodes.h"
49 #include "tcop/utility.h"
50 #include "utils/rel.h"
51 #include "utils/relcache.h"
52 #include "utils/timestamp.h"
53 #if PG_VERSION_NUM >= 90500
54 #include "nodes/makefuncs.h"
55 #if PG_VERSION_NUM >= 100000
56 #include "utils/varlena.h"
57 #include "utils/regproc.h"
62 #ifdef PG_MODULE_MAGIC
66 static bool online_analyze_enable = true;
67 static bool online_analyze_local_tracking = false;
68 static bool online_analyze_verbose = true;
69 static double online_analyze_scale_factor = 0.1;
70 static int online_analyze_threshold = 50;
71 static int online_analyze_capacity_threshold = 100000;
72 static double online_analyze_min_interval = 10000;
73 static int online_analyze_lower_limit = 0;
75 static ExecutorEnd_hook_type oldExecutorEndHook = NULL;
76 #if PG_VERSION_NUM >= 90200
77 static ProcessUtility_hook_type oldProcessUtilityHook = NULL;
82 CK_SELECT = CMD_SELECT,
83 CK_UPDATE = CMD_UPDATE,
84 CK_INSERT = CMD_INSERT,
85 CK_DELETE = CMD_DELETE,
97 OATT_PERSISTENT = 0x01,
98 OATT_TEMPORARY = 0x02,
100 } OnlineAnalyzeTableType;
102 static const struct config_enum_entry online_analyze_table_type_options[] =
104 {"all", OATT_ALL, false},
105 {"persistent", OATT_PERSISTENT, false},
106 {"temporary", OATT_TEMPORARY, false},
107 {"none", OATT_NONE, false},
111 static int online_analyze_table_type = (int)OATT_ALL;
113 typedef struct TableList {
119 static TableList excludeTables = {0, NULL, NULL};
120 static TableList includeTables = {0, NULL, NULL};
122 typedef struct OnlineAnalyzeTableStat {
125 PgStat_Counter n_tuples;
126 PgStat_Counter changes_since_analyze;
127 TimestampTz autovac_analyze_timestamp;
128 TimestampTz analyze_timestamp;
129 } OnlineAnalyzeTableStat;
131 static MemoryContext onlineAnalyzeMemoryContext = NULL;
132 static HTAB *relstats = NULL;
134 static void relstatsInit(void);
136 #if PG_VERSION_NUM < 100000
138 oid_cmp(const void *a, const void *b)
140 if (*(Oid*)a == *(Oid*)b)
142 return (*(Oid*)a > *(Oid*)b) ? 1 : -1;
147 tableListAssign(const char * newval, bool doit, TableList *tbl)
156 rawname = pstrdup(newval);
158 if (!SplitIdentifierString(rawname, ',', &namelist))
163 nOids = list_length(namelist);
164 newOids = malloc(sizeof(Oid) * (nOids+1));
166 elog(ERROR,"could not allocate %d bytes",
167 (int)(sizeof(Oid) * (nOids+1)));
172 char *curname = (char *) lfirst(l);
173 #if PG_VERSION_NUM >= 90200
174 Oid relOid = RangeVarGetRelid(makeRangeVarFromNameList(
175 stringToQualifiedNameList(curname)), NoLock, true);
177 Oid relOid = RangeVarGetRelid(makeRangeVarFromNameList(
178 stringToQualifiedNameList(curname)), true);
181 if (relOid == InvalidOid)
183 #if PG_VERSION_NUM >= 90100
186 elog(WARNING,"'%s' does not exist", curname);
189 else if ( get_rel_relkind(relOid) != RELKIND_RELATION )
191 #if PG_VERSION_NUM >= 90100
194 elog(WARNING,"'%s' is not an table", curname);
199 newOids[i++] = relOid;
208 tbl->tables = newOids;
209 if (tbl->nTables > 1)
210 qsort(tbl->tables, tbl->nTables, sizeof(tbl->tables[0]), oid_cmp);
226 #if PG_VERSION_NUM >= 90100
228 excludeTablesCheck(char **newval, void **extra, GucSource source)
232 val = (char*)tableListAssign(*newval, false, &excludeTables);
244 excludeTablesAssign(const char *newval, void *extra)
246 tableListAssign(newval, true, &excludeTables);
250 includeTablesCheck(char **newval, void **extra, GucSource source)
254 val = (char*)tableListAssign(*newval, false, &includeTables);
266 includeTablesAssign(const char *newval, void *extra)
268 tableListAssign(newval, true, &excludeTables);
271 #else /* PG_VERSION_NUM < 90100 */
274 excludeTablesAssign(const char * newval, bool doit, GucSource source)
276 return tableListAssign(newval, doit, &excludeTables);
280 includeTablesAssign(const char * newval, bool doit, GucSource source)
282 return tableListAssign(newval, doit, &includeTables);
288 tableListShow(TableList *tbl)
294 len = 1 /* \0 */ + tbl->nTables * (2 * NAMEDATALEN + 2 /* ', ' */ + 1 /* . */);
295 ptr = val = palloc(len);
297 for(i=0; i<tbl->nTables; i++)
299 char *relname = get_rel_name(tbl->tables[i]);
300 Oid nspOid = get_rel_namespace(tbl->tables[i]);
301 char *nspname = get_namespace_name(nspOid);
303 if ( relname == NULL || nspOid == InvalidOid || nspname == NULL )
306 ptr += snprintf(ptr, len - (ptr - val), "%s%s.%s",
315 excludeTablesShow(void)
317 return tableListShow(&excludeTables);
321 includeTablesShow(void)
323 return tableListShow(&includeTables);
327 matchOid(TableList *tbl, Oid oid)
329 Oid *StopLow = tbl->tables,
330 *StopHigh = tbl->tables + tbl->nTables,
333 /* Loop invariant: StopLow <= val < StopHigh */
334 while (StopLow < StopHigh)
336 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
338 if (*StopMiddle == oid)
340 else if (*StopMiddle < oid)
341 StopLow = StopMiddle + 1;
343 StopHigh = StopMiddle;
349 #if PG_VERSION_NUM >= 90500
351 makeRangeVarFromOid(Oid relOid)
354 get_namespace_name(get_rel_namespace(relOid)),
355 get_rel_name(relOid),
363 makeAnalyze(Oid relOid, CmdKind operation, int64 naffected)
365 TimestampTz now = GetCurrentTimestamp();
367 OnlineAnalyzeTableType reltype;
370 OnlineAnalyzeTableStat *rstat,
372 PgStat_StatTabEntry *tabentry = NULL;
374 if (relOid == InvalidOid)
378 /* return if there is no changes */
380 else if (naffected < 0)
381 /* number if affected rows is unknown */
384 rel = RelationIdGetRelation(relOid);
385 if (rel->rd_rel->relkind != RELKIND_RELATION)
392 #if PG_VERSION_NUM >= 90100
393 (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
395 (rel->rd_istemp || rel->rd_islocaltemp)
397 ? OATT_TEMPORARY : OATT_PERSISTENT;
402 * includeTables overwrites excludeTables
404 switch(online_analyze_table_type)
407 if (get_rel_relkind(relOid) != RELKIND_RELATION ||
408 (matchOid(&excludeTables, relOid) == true &&
409 matchOid(&includeTables, relOid) == false))
413 if (get_rel_relkind(relOid) != RELKIND_RELATION ||
414 matchOid(&includeTables, relOid) == false)
418 case OATT_PERSISTENT:
421 * skip analyze if relation's type doesn't not match
422 * online_analyze_table_type
424 if ((online_analyze_table_type & reltype) == 0 ||
425 matchOid(&excludeTables, relOid) == true)
427 if (matchOid(&includeTables, relOid) == false)
434 * Do not store data about persistent table in local memory because we
435 * could not track changes of them: they could be changed by another
436 * backends. So always get a pgstat table entry.
438 if (reltype == OATT_TEMPORARY)
439 rstat = hash_search(relstats, &relOid, HASH_ENTER, &found);
441 rstat = &dummyrstat; /* found == false for following if */
445 MemSet(rstat, 0, sizeof(*rstat));
446 rstat->tableid = relOid;
450 if (operation == CK_VACUUM)
452 /* force reread because vacuum could change n_tuples */
453 rstat->rereadStat = true;
456 else if (operation == CK_ANALYZE)
459 rstat->changes_since_analyze = 0;
460 rstat->analyze_timestamp = now;
462 rstat->rereadStat = true;
466 Assert(rstat->tableid == relOid);
469 /* do not reread data if it was a truncation */
470 operation != CK_TRUNCATE && operation != CK_FASTTRUNCATE &&
471 /* read for persistent table and for temp teble if it allowed */
472 (reltype == OATT_PERSISTENT || online_analyze_local_tracking == false) &&
473 /* read only for new table or we know that it's needed */
474 (newTable == true || rstat->rereadStat == true)
477 rstat->rereadStat = false;
479 tabentry = pgstat_fetch_stat_tabentry(relOid);
483 rstat->n_tuples = tabentry->n_dead_tuples + tabentry->n_live_tuples;
484 rstat->changes_since_analyze =
485 #if PG_VERSION_NUM >= 90000
486 tabentry->changes_since_analyze;
488 tabentry->n_live_tuples + tabentry->n_dead_tuples -
489 tabentry->last_anl_tuples;
491 rstat->autovac_analyze_timestamp =
492 tabentry->autovac_analyze_timestamp;
493 rstat->analyze_timestamp = tabentry->analyze_timestamp;
498 /* force analyze after truncate, fasttruncate already did analyze */
499 operation == CK_TRUNCATE || (
500 /* do not analyze too often, if both stamps are exceeded the go */
501 TimestampDifferenceExceeds(rstat->analyze_timestamp, now, online_analyze_min_interval) &&
502 TimestampDifferenceExceeds(rstat->autovac_analyze_timestamp, now, online_analyze_min_interval) &&
503 /* do not analyze too small tables */
504 rstat->n_tuples + rstat->changes_since_analyze + naffected > online_analyze_lower_limit &&
505 /* be in sync with relation_needs_vacanalyze */
506 ((double)(rstat->changes_since_analyze + naffected)) >=
507 online_analyze_scale_factor * ((double)rstat->n_tuples) +
508 (double)online_analyze_threshold))
510 #if PG_VERSION_NUM < 90500
513 VacuumParams vacstmt;
515 TimestampTz startStamp, endStamp;
518 memset(&startStamp, 0, sizeof(startStamp)); /* keep compiler quiet */
520 memset(&vacstmt, 0, sizeof(vacstmt));
522 vacstmt.freeze_min_age = -1;
523 vacstmt.freeze_table_age = -1; /* ??? */
525 #if PG_VERSION_NUM < 90500
526 vacstmt.type = T_VacuumStmt;
527 vacstmt.relation = NULL;
528 vacstmt.va_cols = NIL;
529 #if PG_VERSION_NUM >= 90000
530 vacstmt.options = VACOPT_ANALYZE;
531 if (online_analyze_verbose)
532 vacstmt.options |= VACOPT_VERBOSE;
534 vacstmt.vacuum = vacstmt.full = false;
535 vacstmt.analyze = true;
536 vacstmt.verbose = online_analyze_verbose;
539 vacstmt.multixact_freeze_min_age = -1;
540 vacstmt.multixact_freeze_table_age = -1;
541 vacstmt.log_min_duration = -1;
544 if (online_analyze_verbose)
545 startStamp = GetCurrentTimestamp();
548 #if PG_VERSION_NUM < 90500
550 #if PG_VERSION_NUM >= 90018
553 , GetAccessStrategy(BAS_VACUUM)
554 #if (PG_VERSION_NUM >= 90000) && (PG_VERSION_NUM < 90004)
558 makeRangeVarFromOid(relOid),
559 VACOPT_ANALYZE | ((online_analyze_verbose) ? VACOPT_VERBOSE : 0),
560 &vacstmt, NULL, true, GetAccessStrategy(BAS_VACUUM)
564 /* Make changes visible to subsequent calls */
565 CommandCounterIncrement();
567 if (online_analyze_verbose)
572 endStamp = GetCurrentTimestamp();
573 TimestampDifference(startStamp, endStamp, &secs, µsecs);
574 elog(INFO, "analyze \"%s\" took %.02f seconds",
575 get_rel_name(relOid),
576 ((double)secs) + ((double)microsecs)/1.0e6);
579 rstat->autovac_analyze_timestamp = now;
580 rstat->changes_since_analyze = 0;
587 rstat->n_tuples += naffected;
589 rstat->rereadStat = (reltype == OATT_PERSISTENT);
592 case CK_FASTTRUNCATE:
593 rstat->rereadStat = false;
600 /* update last analyze timestamp in local memory of backend */
603 tabentry->analyze_timestamp = now;
604 tabentry->changes_since_analyze = 0;
607 /* force reload stat for new table */
609 pgstat_clear_snapshot();
614 #if PG_VERSION_NUM >= 90000
616 tabentry->changes_since_analyze += naffected;
622 rstat->changes_since_analyze += naffected;
623 rstat->n_tuples += naffected;
626 rstat->changes_since_analyze += 2 * naffected;
627 rstat->n_tuples += naffected;
629 rstat->changes_since_analyze += naffected;
632 case CK_FASTTRUNCATE:
633 rstat->changes_since_analyze = 0;
641 /* Reset local cache if we are over limit */
642 if (hash_get_num_entries(relstats) > online_analyze_capacity_threshold)
647 isFastTruncateCall(QueryDesc *queryDesc)
654 queryDesc->plannedstmt &&
655 queryDesc->operation == CMD_SELECT &&
656 queryDesc->plannedstmt->planTree &&
657 queryDesc->plannedstmt->planTree->targetlist &&
658 list_length(queryDesc->plannedstmt->planTree->targetlist) == 1
662 te = linitial(queryDesc->plannedstmt->planTree->targetlist);
664 if (!IsA(te, TargetEntry))
667 fe = (FuncExpr*)te->expr;
670 fe && IsA(fe, FuncExpr) &&
671 fe->funcid >= FirstNormalObjectId &&
672 fe->funcretset == false &&
673 fe->funcresulttype == VOIDOID &&
674 fe->funcvariadic == false &&
675 list_length(fe->args) == 1
679 constval = linitial(fe->args);
682 IsA(constval,Const) &&
683 constval->consttype == TEXTOID &&
684 strcmp(get_func_name(fe->funcid), "fasttruncate") == 0
692 extern PGDLLIMPORT void onlineAnalyzeHooker(QueryDesc *queryDesc);
694 onlineAnalyzeHooker(QueryDesc *queryDesc)
696 int64 naffected = -1;
699 if (queryDesc->estate)
700 naffected = queryDesc->estate->es_processed;
702 #if PG_VERSION_NUM >= 90200
703 if (online_analyze_enable &&
704 (constval = isFastTruncateCall(queryDesc)) != NULL)
706 Datum tblnamed = constval->constvalue;
707 char *tblname = text_to_cstring(DatumGetTextP(tblnamed));
709 makeRangeVarFromNameList(stringToQualifiedNameList(tblname));
711 makeAnalyze(RangeVarGetRelid(tblvar,
714 CK_FASTTRUNCATE, -1);
718 if (online_analyze_enable && queryDesc->plannedstmt &&
719 (queryDesc->operation == CMD_INSERT ||
720 queryDesc->operation == CMD_UPDATE ||
721 queryDesc->operation == CMD_DELETE
722 #if PG_VERSION_NUM < 90200
723 || (queryDesc->operation == CMD_SELECT &&
724 queryDesc->plannedstmt->intoClause)
728 #if PG_VERSION_NUM < 90200
729 if (queryDesc->operation == CMD_SELECT)
731 Oid relOid = RangeVarGetRelid(queryDesc->plannedstmt->intoClause->rel, true);
733 makeAnalyze(relOid, queryDesc->operation, naffected);
737 if (queryDesc->plannedstmt->resultRelations &&
738 queryDesc->plannedstmt->rtable)
742 foreach(l, queryDesc->plannedstmt->resultRelations)
744 int n = lfirst_int(l);
745 RangeTblEntry *rte = list_nth(queryDesc->plannedstmt->rtable, n-1);
747 if (rte->rtekind == RTE_RELATION)
748 makeAnalyze(rte->relid, (CmdKind)queryDesc->operation, naffected);
753 if (oldExecutorEndHook)
754 oldExecutorEndHook(queryDesc);
756 standard_ExecutorEnd(queryDesc);
759 static List *toremove = NIL;
762 * removeTable called on transaction end, see call RegisterXactCallback() below
765 removeTable(XactEvent event, void *arg)
771 case XACT_EVENT_COMMIT:
773 case XACT_EVENT_ABORT:
779 foreach(cell, toremove)
781 Oid relOid = lfirst_oid(cell);
783 hash_search(relstats, &relOid, HASH_REMOVE, NULL);
790 #if PG_VERSION_NUM >= 90200
792 onlineAnalyzeHookerUtility(
793 #if PG_VERSION_NUM >= 100000
798 const char *queryString,
799 #if PG_VERSION_NUM >= 90300
800 ProcessUtilityContext context, ParamListInfo params,
801 #if PG_VERSION_NUM >= 100000
802 QueryEnvironment *queryEnv,
805 ParamListInfo params, bool isTopLevel,
807 DestReceiver *dest, char *completionTag) {
808 List *tblnames = NIL;
809 CmdKind op = CK_INSERT;
810 #if PG_VERSION_NUM >= 100000
811 Node *parsetree = NULL;
813 if (pstmt->commandType == CMD_UTILITY)
814 parsetree = pstmt->utilityStmt;
817 if (parsetree && online_analyze_enable)
819 if (IsA(parsetree, CreateTableAsStmt) &&
820 ((CreateTableAsStmt*)parsetree)->into)
823 list_make1((RangeVar*)copyObject(((CreateTableAsStmt*)parsetree)->into->rel));
826 else if (IsA(parsetree, TruncateStmt))
828 tblnames = list_copy(((TruncateStmt*)parsetree)->relations);
831 else if (IsA(parsetree, DropStmt) &&
832 ((DropStmt*)parsetree)->removeType == OBJECT_TABLE)
836 foreach(cell, ((DropStmt*)parsetree)->objects)
838 List *relname = (List *) lfirst(cell);
839 RangeVar *rel = makeRangeVarFromNameList(relname);
840 Oid relOid = RangeVarGetRelid(rel, NoLock, true);
842 if (OidIsValid(relOid))
846 ctx = MemoryContextSwitchTo(TopTransactionContext);
847 toremove = lappend_oid(toremove, relOid);
848 MemoryContextSwitchTo(ctx);
852 else if (IsA(parsetree, VacuumStmt))
854 VacuumStmt *vac = (VacuumStmt*)parsetree;
856 #if PG_VERSION_NUM >= 110000
857 tblnames = vac->rels;
860 tblnames = list_make1(vac->relation);
863 if (vac->options & (VACOPT_VACUUM | VACOPT_FULL | VACOPT_FREEZE))
865 /* optionally with analyze */
868 /* drop all collected stat */
872 else if (vac->options & VACOPT_ANALYZE)
876 /* should reset all counters */
880 OnlineAnalyzeTableStat *rstat;
881 TimestampTz now = GetCurrentTimestamp();
883 hash_seq_init(&hs, relstats);
885 while((rstat = hash_seq_search(&hs)) != NULL)
887 rstat->changes_since_analyze = 0;
888 rstat->analyze_timestamp = now;
897 #if PG_VERSION_NUM >= 100000
898 #define parsetree pstmt
901 if (oldProcessUtilityHook)
902 oldProcessUtilityHook(parsetree, queryString,
903 #if PG_VERSION_NUM >= 90300
905 #if PG_VERSION_NUM >= 100000
911 dest, completionTag);
913 standard_ProcessUtility(parsetree, queryString,
914 #if PG_VERSION_NUM >= 90300
916 #if PG_VERSION_NUM >= 100000
922 dest, completionTag);
924 #if PG_VERSION_NUM >= 100000
934 #if PG_VERSION_NUM >= 110000
935 (IsA(lfirst(l), VacuumRelation)) ?
936 ((VacuumRelation*)lfirst(l))->relation :
938 (RangeVar*)lfirst(l);
941 Assert(IsA(tblname, RangeVar));
943 tblOid = RangeVarGetRelid(tblname, NoLock, true);
944 makeAnalyze(tblOid, op, -1);
957 MemSet(&hash_ctl, 0, sizeof(hash_ctl));
959 hash_ctl.hash = oid_hash;
960 flags |= HASH_FUNCTION;
962 if (onlineAnalyzeMemoryContext)
964 Assert(relstats != NULL);
965 MemoryContextReset(onlineAnalyzeMemoryContext);
969 Assert(relstats == NULL);
971 #if PG_VERSION_NUM < 90600
972 onlineAnalyzeMemoryContext =
973 AllocSetContextCreate(CacheMemoryContext,
974 "online_analyze storage context",
975 ALLOCSET_DEFAULT_MINSIZE,
976 ALLOCSET_DEFAULT_INITSIZE,
977 ALLOCSET_DEFAULT_MAXSIZE
980 onlineAnalyzeMemoryContext =
981 AllocSetContextCreate(CacheMemoryContext,
982 "online_analyze storage context", ALLOCSET_DEFAULT_SIZES);
986 hash_ctl.hcxt = onlineAnalyzeMemoryContext;
987 flags |= HASH_CONTEXT;
989 hash_ctl.keysize = sizeof(Oid);
991 hash_ctl.entrysize = sizeof(OnlineAnalyzeTableStat);
994 relstats = hash_create("online_analyze storage", 1024, &hash_ctl, flags);
1003 oldExecutorEndHook = ExecutorEnd_hook;
1005 ExecutorEnd_hook = onlineAnalyzeHooker;
1007 #if PG_VERSION_NUM >= 90200
1008 oldProcessUtilityHook = ProcessUtility_hook;
1010 ProcessUtility_hook = onlineAnalyzeHookerUtility;
1014 DefineCustomBoolVariable(
1015 "online_analyze.enable",
1016 "Enable on-line analyze",
1017 "Enables analyze of table directly after insert/update/delete/select into",
1018 &online_analyze_enable,
1019 #if PG_VERSION_NUM >= 80400
1020 online_analyze_enable,
1023 #if PG_VERSION_NUM >= 80400
1025 #if PG_VERSION_NUM >= 90100
1033 DefineCustomBoolVariable(
1034 "online_analyze.local_tracking",
1035 "Per backend tracking",
1036 "Per backend tracking for temp tables (do not use system statistic)",
1037 &online_analyze_local_tracking,
1038 #if PG_VERSION_NUM >= 80400
1039 online_analyze_local_tracking,
1042 #if PG_VERSION_NUM >= 80400
1044 #if PG_VERSION_NUM >= 90100
1052 DefineCustomBoolVariable(
1053 "online_analyze.verbose",
1054 "Verbosity of on-line analyze",
1055 "Make ANALYZE VERBOSE after table's changes",
1056 &online_analyze_verbose,
1057 #if PG_VERSION_NUM >= 80400
1058 online_analyze_verbose,
1061 #if PG_VERSION_NUM >= 80400
1063 #if PG_VERSION_NUM >= 90100
1071 DefineCustomRealVariable(
1072 "online_analyze.scale_factor",
1073 "fraction of table size to start on-line analyze",
1074 "fraction of table size to start on-line analyze",
1075 &online_analyze_scale_factor,
1076 #if PG_VERSION_NUM >= 80400
1077 online_analyze_scale_factor,
1082 #if PG_VERSION_NUM >= 80400
1084 #if PG_VERSION_NUM >= 90100
1092 DefineCustomIntVariable(
1093 "online_analyze.threshold",
1094 "min number of row updates before on-line analyze",
1095 "min number of row updates before on-line analyze",
1096 &online_analyze_threshold,
1097 #if PG_VERSION_NUM >= 80400
1098 online_analyze_threshold,
1103 #if PG_VERSION_NUM >= 80400
1105 #if PG_VERSION_NUM >= 90100
1113 DefineCustomIntVariable(
1114 "online_analyze.capacity_threshold",
1115 "Max local cache table capacity",
1116 "Max local cache table capacity",
1117 &online_analyze_capacity_threshold,
1118 #if PG_VERSION_NUM >= 80400
1119 online_analyze_capacity_threshold,
1124 #if PG_VERSION_NUM >= 80400
1126 #if PG_VERSION_NUM >= 90100
1134 DefineCustomRealVariable(
1135 "online_analyze.min_interval",
1136 "minimum time interval between analyze call (in milliseconds)",
1137 "minimum time interval between analyze call (in milliseconds)",
1138 &online_analyze_min_interval,
1139 #if PG_VERSION_NUM >= 80400
1140 online_analyze_min_interval,
1145 #if PG_VERSION_NUM >= 80400
1147 #if PG_VERSION_NUM >= 90100
1155 DefineCustomEnumVariable(
1156 "online_analyze.table_type",
1157 "Type(s) of table for online analyze: all(default), persistent, temporary, none",
1159 &online_analyze_table_type,
1160 #if PG_VERSION_NUM >= 80400
1161 online_analyze_table_type,
1163 online_analyze_table_type_options,
1165 #if PG_VERSION_NUM >= 80400
1167 #if PG_VERSION_NUM >= 90100
1175 DefineCustomStringVariable(
1176 "online_analyze.exclude_tables",
1177 "List of tables which will not online analyze",
1179 &excludeTables.tableStr,
1180 #if PG_VERSION_NUM >= 80400
1185 #if PG_VERSION_NUM >= 90100
1187 excludeTablesAssign,
1189 excludeTablesAssign,
1194 DefineCustomStringVariable(
1195 "online_analyze.include_tables",
1196 "List of tables which will online analyze",
1198 &includeTables.tableStr,
1199 #if PG_VERSION_NUM >= 80400
1204 #if PG_VERSION_NUM >= 90100
1206 includeTablesAssign,
1208 includeTablesAssign,
1213 DefineCustomIntVariable(
1214 "online_analyze.lower_limit",
1215 "min number of rows in table to analyze",
1216 "min number of rows in table to analyze",
1217 &online_analyze_lower_limit,
1218 #if PG_VERSION_NUM >= 80400
1219 online_analyze_lower_limit,
1224 #if PG_VERSION_NUM >= 80400
1226 #if PG_VERSION_NUM >= 90100
1234 RegisterXactCallback(removeTable, NULL);
1237 void _PG_fini(void);
1241 ExecutorEnd_hook = oldExecutorEndHook;
1242 #if PG_VERSION_NUM >= 90200
1243 ProcessUtility_hook = oldProcessUtilityHook;
1246 if (excludeTables.tables)
1247 free(excludeTables.tables);
1248 if (includeTables.tables)
1249 free(includeTables.tables);
1251 excludeTables.tables = includeTables.tables = NULL;
1252 excludeTables.nTables = includeTables.nTables = 0;