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;
449 else if (operation == CK_VACUUM)
451 /* force reread becouse vacuum could change n_tuples */
452 rstat->rereadStat = true;
455 else if (operation == CK_ANALYZE)
458 rstat->changes_since_analyze = 0;
459 rstat->analyze_timestamp = now;
463 Assert(rstat->tableid == relOid);
466 /* do not reread data if it was a truncation */
467 operation != CK_TRUNCATE && operation != CK_FASTTRUNCATE &&
468 /* read for persistent table and for temp teble if it allowed */
469 (reltype == OATT_PERSISTENT || online_analyze_local_tracking == false) &&
470 /* read only for new table or we know that it's needed */
471 (newTable == true || rstat->rereadStat == true)
474 rstat->rereadStat = false;
476 tabentry = pgstat_fetch_stat_tabentry(relOid);
480 rstat->n_tuples = tabentry->n_dead_tuples + tabentry->n_live_tuples;
481 rstat->changes_since_analyze =
482 #if PG_VERSION_NUM >= 90000
483 tabentry->changes_since_analyze;
485 tabentry->n_live_tuples + tabentry->n_dead_tuples -
486 tabentry->last_anl_tuples;
488 rstat->autovac_analyze_timestamp =
489 tabentry->autovac_analyze_timestamp;
490 rstat->analyze_timestamp = tabentry->analyze_timestamp;
495 /* force analyze after truncate, fasttruncate already did analyze */
496 operation == CK_TRUNCATE || (
497 /* do not analyze too often, if both stamps are exceeded the go */
498 TimestampDifferenceExceeds(rstat->analyze_timestamp, now, online_analyze_min_interval) &&
499 TimestampDifferenceExceeds(rstat->autovac_analyze_timestamp, now, online_analyze_min_interval) &&
500 /* do not analyze too small tables */
501 rstat->n_tuples + rstat->changes_since_analyze + naffected > online_analyze_lower_limit &&
502 /* be in sync with relation_needs_vacanalyze */
503 ((double)(rstat->changes_since_analyze + naffected)) >=
504 online_analyze_scale_factor * ((double)rstat->n_tuples) +
505 (double)online_analyze_threshold))
507 #if PG_VERSION_NUM < 90500
510 VacuumParams vacstmt;
512 TimestampTz startStamp, endStamp;
515 memset(&startStamp, 0, sizeof(startStamp)); /* keep compiler quiet */
517 memset(&vacstmt, 0, sizeof(vacstmt));
519 vacstmt.freeze_min_age = -1;
520 vacstmt.freeze_table_age = -1; /* ??? */
522 #if PG_VERSION_NUM < 90500
523 vacstmt.type = T_VacuumStmt;
524 vacstmt.relation = NULL;
525 vacstmt.va_cols = NIL;
526 #if PG_VERSION_NUM >= 90000
527 vacstmt.options = VACOPT_ANALYZE;
528 if (online_analyze_verbose)
529 vacstmt.options |= VACOPT_VERBOSE;
531 vacstmt.vacuum = vacstmt.full = false;
532 vacstmt.analyze = true;
533 vacstmt.verbose = online_analyze_verbose;
536 vacstmt.multixact_freeze_min_age = -1;
537 vacstmt.multixact_freeze_table_age = -1;
538 vacstmt.log_min_duration = -1;
541 if (online_analyze_verbose)
542 startStamp = GetCurrentTimestamp();
545 #if PG_VERSION_NUM < 90500
547 #if PG_VERSION_NUM >= 90018
550 , GetAccessStrategy(BAS_VACUUM)
551 #if (PG_VERSION_NUM >= 90000) && (PG_VERSION_NUM < 90004)
555 makeRangeVarFromOid(relOid),
556 VACOPT_ANALYZE | ((online_analyze_verbose) ? VACOPT_VERBOSE : 0),
557 &vacstmt, NULL, true, GetAccessStrategy(BAS_VACUUM)
561 if (online_analyze_verbose)
566 endStamp = GetCurrentTimestamp();
567 TimestampDifference(startStamp, endStamp, &secs, µsecs);
568 elog(INFO, "analyze \"%s\" took %.02f seconds",
569 get_rel_name(relOid),
570 ((double)secs) + ((double)microsecs)/1.0e6);
573 rstat->autovac_analyze_timestamp = now;
574 rstat->changes_since_analyze = 0;
581 rstat->n_tuples += naffected;
583 rstat->rereadStat = (reltype == OATT_PERSISTENT);
586 case CK_FASTTRUNCATE:
587 rstat->rereadStat = false;
594 /* update last analyze timestamp in local memory of backend */
597 tabentry->analyze_timestamp = now;
598 tabentry->changes_since_analyze = 0;
601 /* force reload stat for new table */
603 pgstat_clear_snapshot();
608 #if PG_VERSION_NUM >= 90000
610 tabentry->changes_since_analyze += naffected;
616 rstat->changes_since_analyze += naffected;
617 rstat->n_tuples += naffected;
620 rstat->changes_since_analyze += 2 * naffected;
621 rstat->n_tuples += naffected;
623 rstat->changes_since_analyze += naffected;
626 case CK_FASTTRUNCATE:
627 rstat->changes_since_analyze = 0;
635 /* Reset local cache if we are over limit */
636 if (hash_get_num_entries(relstats) > online_analyze_capacity_threshold)
641 isFastTruncateCall(QueryDesc *queryDesc)
648 queryDesc->plannedstmt &&
649 queryDesc->operation == CMD_SELECT &&
650 queryDesc->plannedstmt->planTree &&
651 queryDesc->plannedstmt->planTree->targetlist &&
652 list_length(queryDesc->plannedstmt->planTree->targetlist) == 1
656 te = linitial(queryDesc->plannedstmt->planTree->targetlist);
658 if (!IsA(te, TargetEntry))
661 fe = (FuncExpr*)te->expr;
664 fe && IsA(fe, FuncExpr) &&
665 fe->funcid >= FirstNormalObjectId &&
666 fe->funcretset == false &&
667 fe->funcresulttype == VOIDOID &&
668 fe->funcvariadic == false &&
669 list_length(fe->args) == 1
673 constval = linitial(fe->args);
676 IsA(constval,Const) &&
677 constval->consttype == TEXTOID &&
678 strcmp(get_func_name(fe->funcid), "fasttruncate") == 0
686 extern PGDLLIMPORT void onlineAnalyzeHooker(QueryDesc *queryDesc);
688 onlineAnalyzeHooker(QueryDesc *queryDesc)
690 int64 naffected = -1;
693 if (queryDesc->estate)
694 naffected = queryDesc->estate->es_processed;
696 #if PG_VERSION_NUM >= 90200
697 if (online_analyze_enable &&
698 (constval = isFastTruncateCall(queryDesc)) != NULL)
700 Datum tblnamed = constval->constvalue;
701 char *tblname = text_to_cstring(DatumGetTextP(tblnamed));
703 makeRangeVarFromNameList(stringToQualifiedNameList(tblname));
705 makeAnalyze(RangeVarGetRelid(tblvar,
708 CK_FASTTRUNCATE, -1);
712 if (online_analyze_enable && queryDesc->plannedstmt &&
713 (queryDesc->operation == CMD_INSERT ||
714 queryDesc->operation == CMD_UPDATE ||
715 queryDesc->operation == CMD_DELETE
716 #if PG_VERSION_NUM < 90200
717 || (queryDesc->operation == CMD_SELECT &&
718 queryDesc->plannedstmt->intoClause)
722 #if PG_VERSION_NUM < 90200
723 if (queryDesc->operation == CMD_SELECT)
725 Oid relOid = RangeVarGetRelid(queryDesc->plannedstmt->intoClause->rel, true);
727 makeAnalyze(relOid, queryDesc->operation, naffected);
731 if (queryDesc->plannedstmt->resultRelations &&
732 queryDesc->plannedstmt->rtable)
736 foreach(l, queryDesc->plannedstmt->resultRelations)
738 int n = lfirst_int(l);
739 RangeTblEntry *rte = list_nth(queryDesc->plannedstmt->rtable, n-1);
741 if (rte->rtekind == RTE_RELATION)
742 makeAnalyze(rte->relid, (CmdKind)queryDesc->operation, naffected);
747 if (oldExecutorEndHook)
748 oldExecutorEndHook(queryDesc);
750 standard_ExecutorEnd(queryDesc);
753 static List *toremove = NIL;
756 * removeTable called on transaction end, see call RegisterXactCallback() below
759 removeTable(XactEvent event, void *arg)
765 case XACT_EVENT_COMMIT:
767 case XACT_EVENT_ABORT:
773 foreach(cell, toremove)
775 Oid relOid = lfirst_oid(cell);
777 hash_search(relstats, &relOid, HASH_REMOVE, NULL);
784 #if PG_VERSION_NUM >= 90200
786 onlineAnalyzeHookerUtility(
787 #if PG_VERSION_NUM >= 100000
792 const char *queryString,
793 #if PG_VERSION_NUM >= 90300
794 ProcessUtilityContext context, ParamListInfo params,
795 #if PG_VERSION_NUM >= 100000
796 QueryEnvironment *queryEnv,
799 ParamListInfo params, bool isTopLevel,
801 DestReceiver *dest, char *completionTag) {
802 List *tblnames = NIL;
803 CmdKind op = CK_INSERT;
804 #if PG_VERSION_NUM >= 100000
805 Node *parsetree = NULL;
807 if (pstmt->commandType == CMD_UTILITY)
808 parsetree = pstmt->utilityStmt;
811 if (parsetree && online_analyze_enable)
813 if (IsA(parsetree, CreateTableAsStmt) &&
814 ((CreateTableAsStmt*)parsetree)->into)
817 list_make1((RangeVar*)copyObject(((CreateTableAsStmt*)parsetree)->into->rel));
820 else if (IsA(parsetree, TruncateStmt))
822 tblnames = list_copy(((TruncateStmt*)parsetree)->relations);
825 else if (IsA(parsetree, DropStmt) &&
826 ((DropStmt*)parsetree)->removeType == OBJECT_TABLE)
830 foreach(cell, ((DropStmt*)parsetree)->objects)
832 List *relname = (List *) lfirst(cell);
833 RangeVar *rel = makeRangeVarFromNameList(relname);
834 Oid relOid = RangeVarGetRelid(rel, NoLock, true);
836 if (OidIsValid(relOid))
840 ctx = MemoryContextSwitchTo(TopTransactionContext);
841 toremove = lappend_oid(toremove, relOid);
842 MemoryContextSwitchTo(ctx);
846 else if (IsA(parsetree, VacuumStmt))
848 VacuumStmt *vac = (VacuumStmt*)parsetree;
851 tblnames = list_make1(vac->relation);
853 if (vac->options & (VACOPT_VACUUM | VACOPT_FULL | VACOPT_FREEZE))
855 /* optionally with analyze */
858 /* drop all collected stat */
862 else if (vac->options & VACOPT_ANALYZE)
866 /* should reset all counters */
870 OnlineAnalyzeTableStat *rstat;
871 TimestampTz now = GetCurrentTimestamp();
873 hash_seq_init(&hs, relstats);
875 while((rstat = hash_seq_search(&hs)) != NULL)
877 rstat->changes_since_analyze = 0;
878 rstat->analyze_timestamp = now;
887 #if PG_VERSION_NUM >= 100000
888 #define parsetree pstmt
891 if (oldProcessUtilityHook)
892 oldProcessUtilityHook(parsetree, queryString,
893 #if PG_VERSION_NUM >= 90300
895 #if PG_VERSION_NUM >= 100000
901 dest, completionTag);
903 standard_ProcessUtility(parsetree, queryString,
904 #if PG_VERSION_NUM >= 90300
906 #if PG_VERSION_NUM >= 100000
912 dest, completionTag);
914 #if PG_VERSION_NUM >= 100000
923 RangeVar *tblname = (RangeVar*)lfirst(l);
924 Oid tblOid = RangeVarGetRelid(tblname, NoLock, true);
926 makeAnalyze(tblOid, op, -1);
938 MemSet(&hash_ctl, 0, sizeof(hash_ctl));
940 hash_ctl.hash = oid_hash;
941 flags |= HASH_FUNCTION;
943 if (onlineAnalyzeMemoryContext)
945 Assert(relstats != NULL);
946 MemoryContextReset(onlineAnalyzeMemoryContext);
950 Assert(relstats == NULL);
951 onlineAnalyzeMemoryContext =
952 AllocSetContextCreate(CacheMemoryContext,
953 "online_analyze storage context",
954 #if PG_VERSION_NUM < 90600
955 ALLOCSET_DEFAULT_MINSIZE,
956 ALLOCSET_DEFAULT_INITSIZE,
957 ALLOCSET_DEFAULT_MAXSIZE
959 ALLOCSET_DEFAULT_SIZES
964 hash_ctl.hcxt = onlineAnalyzeMemoryContext;
965 flags |= HASH_CONTEXT;
967 hash_ctl.keysize = sizeof(Oid);
969 hash_ctl.entrysize = sizeof(OnlineAnalyzeTableStat);
972 relstats = hash_create("online_analyze storage", 1024, &hash_ctl, flags);
981 oldExecutorEndHook = ExecutorEnd_hook;
983 ExecutorEnd_hook = onlineAnalyzeHooker;
985 #if PG_VERSION_NUM >= 90200
986 oldProcessUtilityHook = ProcessUtility_hook;
988 ProcessUtility_hook = onlineAnalyzeHookerUtility;
992 DefineCustomBoolVariable(
993 "online_analyze.enable",
994 "Enable on-line analyze",
995 "Enables analyze of table directly after insert/update/delete/select into",
996 &online_analyze_enable,
997 #if PG_VERSION_NUM >= 80400
998 online_analyze_enable,
1001 #if PG_VERSION_NUM >= 80400
1003 #if PG_VERSION_NUM >= 90100
1011 DefineCustomBoolVariable(
1012 "online_analyze.local_tracking",
1013 "Per backend tracking",
1014 "Per backend tracking for temp tables (do not use system statistic)",
1015 &online_analyze_local_tracking,
1016 #if PG_VERSION_NUM >= 80400
1017 online_analyze_local_tracking,
1020 #if PG_VERSION_NUM >= 80400
1022 #if PG_VERSION_NUM >= 90100
1030 DefineCustomBoolVariable(
1031 "online_analyze.verbose",
1032 "Verbosity of on-line analyze",
1033 "Make ANALYZE VERBOSE after table's changes",
1034 &online_analyze_verbose,
1035 #if PG_VERSION_NUM >= 80400
1036 online_analyze_verbose,
1039 #if PG_VERSION_NUM >= 80400
1041 #if PG_VERSION_NUM >= 90100
1049 DefineCustomRealVariable(
1050 "online_analyze.scale_factor",
1051 "fraction of table size to start on-line analyze",
1052 "fraction of table size to start on-line analyze",
1053 &online_analyze_scale_factor,
1054 #if PG_VERSION_NUM >= 80400
1055 online_analyze_scale_factor,
1060 #if PG_VERSION_NUM >= 80400
1062 #if PG_VERSION_NUM >= 90100
1070 DefineCustomIntVariable(
1071 "online_analyze.threshold",
1072 "min number of row updates before on-line analyze",
1073 "min number of row updates before on-line analyze",
1074 &online_analyze_threshold,
1075 #if PG_VERSION_NUM >= 80400
1076 online_analyze_threshold,
1081 #if PG_VERSION_NUM >= 80400
1083 #if PG_VERSION_NUM >= 90100
1091 DefineCustomIntVariable(
1092 "online_analyze.capacity_threshold",
1093 "Max local cache table capacity",
1094 "Max local cache table capacity",
1095 &online_analyze_capacity_threshold,
1096 #if PG_VERSION_NUM >= 80400
1097 online_analyze_capacity_threshold,
1102 #if PG_VERSION_NUM >= 80400
1104 #if PG_VERSION_NUM >= 90100
1112 DefineCustomRealVariable(
1113 "online_analyze.min_interval",
1114 "minimum time interval between analyze call (in milliseconds)",
1115 "minimum time interval between analyze call (in milliseconds)",
1116 &online_analyze_min_interval,
1117 #if PG_VERSION_NUM >= 80400
1118 online_analyze_min_interval,
1123 #if PG_VERSION_NUM >= 80400
1125 #if PG_VERSION_NUM >= 90100
1133 DefineCustomEnumVariable(
1134 "online_analyze.table_type",
1135 "Type(s) of table for online analyze: all(default), persistent, temporary, none",
1137 &online_analyze_table_type,
1138 #if PG_VERSION_NUM >= 80400
1139 online_analyze_table_type,
1141 online_analyze_table_type_options,
1143 #if PG_VERSION_NUM >= 80400
1145 #if PG_VERSION_NUM >= 90100
1153 DefineCustomStringVariable(
1154 "online_analyze.exclude_tables",
1155 "List of tables which will not online analyze",
1157 &excludeTables.tableStr,
1158 #if PG_VERSION_NUM >= 80400
1163 #if PG_VERSION_NUM >= 90100
1165 excludeTablesAssign,
1167 excludeTablesAssign,
1172 DefineCustomStringVariable(
1173 "online_analyze.include_tables",
1174 "List of tables which will online analyze",
1176 &includeTables.tableStr,
1177 #if PG_VERSION_NUM >= 80400
1182 #if PG_VERSION_NUM >= 90100
1184 includeTablesAssign,
1186 includeTablesAssign,
1191 DefineCustomIntVariable(
1192 "online_analyze.lower_limit",
1193 "min number of rows in table to analyze",
1194 "min number of rows in table to analyze",
1195 &online_analyze_lower_limit,
1196 #if PG_VERSION_NUM >= 80400
1197 online_analyze_lower_limit,
1202 #if PG_VERSION_NUM >= 80400
1204 #if PG_VERSION_NUM >= 90100
1212 RegisterXactCallback(removeTable, NULL);
1215 void _PG_fini(void);
1219 ExecutorEnd_hook = oldExecutorEndHook;
1220 #if PG_VERSION_NUM >= 90200
1221 ProcessUtility_hook = oldProcessUtilityHook;
1224 if (excludeTables.tables)
1225 free(excludeTables.tables);
1226 if (includeTables.tables)
1227 free(includeTables.tables);
1229 excludeTables.tables = includeTables.tables = NULL;
1230 excludeTables.nTables = includeTables.nTables = 0;