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 "catalog/namespace.h"
35 #include "commands/vacuum.h"
36 #include "executor/executor.h"
37 #include "nodes/nodes.h"
38 #include "nodes/parsenodes.h"
39 #include "storage/bufmgr.h"
40 #include "utils/builtins.h"
41 #include "utils/hsearch.h"
42 #include "utils/memutils.h"
43 #include "utils/lsyscache.h"
44 #include "utils/guc.h"
45 #if PG_VERSION_NUM >= 90200
46 #include "catalog/pg_class.h"
47 #include "nodes/primnodes.h"
48 #include "tcop/utility.h"
49 #include "utils/rel.h"
50 #include "utils/relcache.h"
51 #include "utils/timestamp.h"
52 #if PG_VERSION_NUM >= 90500
53 #include "nodes/makefuncs.h"
54 #if PG_VERSION_NUM >= 100000
55 #include "utils/varlena.h"
56 #include "utils/regproc.h"
61 #ifdef PG_MODULE_MAGIC
65 static bool online_analyze_enable = true;
66 static bool online_analyze_local_tracking = false;
67 static bool online_analyze_verbose = true;
68 static double online_analyze_scale_factor = 0.1;
69 static int online_analyze_threshold = 50;
70 static int online_analyze_capacity_threshold = 100000;
71 static double online_analyze_min_interval = 10000;
72 static int online_analyze_lower_limit = 0;
74 static ExecutorEnd_hook_type oldExecutorEndHook = NULL;
75 #if PG_VERSION_NUM >= 90200
76 static ProcessUtility_hook_type oldProcessUtilityHook = NULL;
81 CK_SELECT = CMD_SELECT,
82 CK_UPDATE = CMD_UPDATE,
83 CK_INSERT = CMD_INSERT,
84 CK_DELETE = CMD_DELETE,
96 OATT_PERSISTENT = 0x01,
97 OATT_TEMPORARY = 0x02,
99 } OnlineAnalyzeTableType;
101 static const struct config_enum_entry online_analyze_table_type_options[] =
103 {"all", OATT_ALL, false},
104 {"persistent", OATT_PERSISTENT, false},
105 {"temporary", OATT_TEMPORARY, false},
106 {"none", OATT_NONE, false},
110 static int online_analyze_table_type = (int)OATT_ALL;
112 typedef struct TableList {
118 static TableList excludeTables = {0, NULL, NULL};
119 static TableList includeTables = {0, NULL, NULL};
121 typedef struct OnlineAnalyzeTableStat {
124 PgStat_Counter n_tuples;
125 PgStat_Counter changes_since_analyze;
126 TimestampTz autovac_analyze_timestamp;
127 TimestampTz analyze_timestamp;
128 } OnlineAnalyzeTableStat;
130 static MemoryContext onlineAnalyzeMemoryContext = NULL;
131 static HTAB *relstats = NULL;
133 static void relstatsInit(void);
135 #if PG_VERSION_NUM < 100000
137 oid_cmp(const void *a, const void *b)
139 if (*(Oid*)a == *(Oid*)b)
141 return (*(Oid*)a > *(Oid*)b) ? 1 : -1;
146 tableListAssign(const char * newval, bool doit, TableList *tbl)
155 rawname = pstrdup(newval);
157 if (!SplitIdentifierString(rawname, ',', &namelist))
162 nOids = list_length(namelist);
163 newOids = malloc(sizeof(Oid) * (nOids+1));
165 elog(ERROR,"could not allocate %d bytes",
166 (int)(sizeof(Oid) * (nOids+1)));
171 char *curname = (char *) lfirst(l);
172 #if PG_VERSION_NUM >= 90200
173 Oid relOid = RangeVarGetRelid(makeRangeVarFromNameList(
174 stringToQualifiedNameList(curname)), NoLock, true);
176 Oid relOid = RangeVarGetRelid(makeRangeVarFromNameList(
177 stringToQualifiedNameList(curname)), true);
180 if (relOid == InvalidOid)
182 #if PG_VERSION_NUM >= 90100
185 elog(WARNING,"'%s' does not exist", curname);
188 else if ( get_rel_relkind(relOid) != RELKIND_RELATION )
190 #if PG_VERSION_NUM >= 90100
193 elog(WARNING,"'%s' is not an table", curname);
198 newOids[i++] = relOid;
207 tbl->tables = newOids;
208 if (tbl->nTables > 1)
209 qsort(tbl->tables, tbl->nTables, sizeof(tbl->tables[0]), oid_cmp);
225 #if PG_VERSION_NUM >= 90100
227 excludeTablesCheck(char **newval, void **extra, GucSource source)
231 val = (char*)tableListAssign(*newval, false, &excludeTables);
243 excludeTablesAssign(const char *newval, void *extra)
245 tableListAssign(newval, true, &excludeTables);
249 includeTablesCheck(char **newval, void **extra, GucSource source)
253 val = (char*)tableListAssign(*newval, false, &includeTables);
265 includeTablesAssign(const char *newval, void *extra)
267 tableListAssign(newval, true, &excludeTables);
270 #else /* PG_VERSION_NUM < 90100 */
273 excludeTablesAssign(const char * newval, bool doit, GucSource source)
275 return tableListAssign(newval, doit, &excludeTables);
279 includeTablesAssign(const char * newval, bool doit, GucSource source)
281 return tableListAssign(newval, doit, &includeTables);
287 tableListShow(TableList *tbl)
293 len = 1 /* \0 */ + tbl->nTables * (2 * NAMEDATALEN + 2 /* ', ' */ + 1 /* . */);
294 ptr = val = palloc(len);
296 for(i=0; i<tbl->nTables; i++)
298 char *relname = get_rel_name(tbl->tables[i]);
299 Oid nspOid = get_rel_namespace(tbl->tables[i]);
300 char *nspname = get_namespace_name(nspOid);
302 if ( relname == NULL || nspOid == InvalidOid || nspname == NULL )
305 ptr += snprintf(ptr, len - (ptr - val), "%s%s.%s",
314 excludeTablesShow(void)
316 return tableListShow(&excludeTables);
320 includeTablesShow(void)
322 return tableListShow(&includeTables);
326 matchOid(TableList *tbl, Oid oid)
328 Oid *StopLow = tbl->tables,
329 *StopHigh = tbl->tables + tbl->nTables,
332 /* Loop invariant: StopLow <= val < StopHigh */
333 while (StopLow < StopHigh)
335 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
337 if (*StopMiddle == oid)
339 else if (*StopMiddle < oid)
340 StopLow = StopMiddle + 1;
342 StopHigh = StopMiddle;
348 #if PG_VERSION_NUM >= 90500
350 makeRangeVarFromOid(Oid relOid)
353 get_namespace_name(get_rel_namespace(relOid)),
354 get_rel_name(relOid),
362 makeAnalyze(Oid relOid, CmdKind operation, int64 naffected)
364 TimestampTz now = GetCurrentTimestamp();
366 OnlineAnalyzeTableType reltype;
369 OnlineAnalyzeTableStat *rstat,
371 PgStat_StatTabEntry *tabentry = NULL;
373 if (relOid == InvalidOid)
377 /* return if there is no changes */
379 else if (naffected < 0)
380 /* number if affected rows is unknown */
383 rel = RelationIdGetRelation(relOid);
384 if (rel->rd_rel->relkind != RELKIND_RELATION)
391 #if PG_VERSION_NUM >= 90100
392 (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
394 (rel->rd_istemp || rel->rd_islocaltemp)
396 ? OATT_TEMPORARY : OATT_PERSISTENT;
401 * includeTables overwrites excludeTables
403 switch(online_analyze_table_type)
406 if (get_rel_relkind(relOid) != RELKIND_RELATION ||
407 (matchOid(&excludeTables, relOid) == true &&
408 matchOid(&includeTables, relOid) == false))
412 if (get_rel_relkind(relOid) != RELKIND_RELATION ||
413 matchOid(&includeTables, relOid) == false)
417 case OATT_PERSISTENT:
420 * skip analyze if relation's type doesn't not match
421 * online_analyze_table_type
423 if ((online_analyze_table_type & reltype) == 0 ||
424 matchOid(&excludeTables, relOid) == true)
426 if (matchOid(&includeTables, relOid) == false)
433 * Do not store data about persistent table in local memory because we
434 * could not track changes of them: they could be changed by another
435 * backends. So always get a pgstat table entry.
437 if (reltype == OATT_TEMPORARY)
438 rstat = hash_search(relstats, &relOid, HASH_ENTER, &found);
440 rstat = &dummyrstat; /* found == false for following if */
444 MemSet(rstat, 0, sizeof(*rstat));
445 rstat->tableid = relOid;
448 else if (operation == CK_VACUUM)
450 /* force reread becouse vacuum could change n_tuples */
451 rstat->rereadStat = true;
454 else if (operation == CK_ANALYZE)
457 rstat->changes_since_analyze = 0;
458 rstat->analyze_timestamp = now;
462 Assert(rstat->tableid == relOid);
465 /* do not reread data if it was a truncation */
466 operation != CK_TRUNCATE && operation != CK_FASTTRUNCATE &&
467 /* read for persistent table and for temp teble if it allowed */
468 (reltype == OATT_PERSISTENT || online_analyze_local_tracking == false) &&
469 /* read only for new table or we know that it's needed */
470 (newTable == true || rstat->rereadStat == true)
473 rstat->rereadStat = false;
475 tabentry = pgstat_fetch_stat_tabentry(relOid);
479 rstat->n_tuples = tabentry->n_dead_tuples + tabentry->n_live_tuples;
480 rstat->changes_since_analyze =
481 #if PG_VERSION_NUM >= 90000
482 tabentry->changes_since_analyze;
484 tabentry->n_live_tuples + tabentry->n_dead_tuples -
485 tabentry->last_anl_tuples;
487 rstat->autovac_analyze_timestamp =
488 tabentry->autovac_analyze_timestamp;
489 rstat->analyze_timestamp = tabentry->analyze_timestamp;
494 /* force analyze after truncate, fasttruncate already did analyze */
495 operation == CK_TRUNCATE || (
496 /* do not analyze too often, if both stamps are exceeded the go */
497 TimestampDifferenceExceeds(rstat->analyze_timestamp, now, online_analyze_min_interval) &&
498 TimestampDifferenceExceeds(rstat->autovac_analyze_timestamp, now, online_analyze_min_interval) &&
499 /* do not analyze too small tables */
500 rstat->n_tuples + rstat->changes_since_analyze + naffected > online_analyze_lower_limit &&
501 /* be in sync with relation_needs_vacanalyze */
502 ((double)(rstat->changes_since_analyze + naffected)) >=
503 online_analyze_scale_factor * ((double)rstat->n_tuples) +
504 (double)online_analyze_threshold))
506 #if PG_VERSION_NUM < 90500
509 VacuumParams vacstmt;
511 TimestampTz startStamp, endStamp;
514 memset(&startStamp, 0, sizeof(startStamp)); /* keep compiler quiet */
516 memset(&vacstmt, 0, sizeof(vacstmt));
518 vacstmt.freeze_min_age = -1;
519 vacstmt.freeze_table_age = -1; /* ??? */
521 #if PG_VERSION_NUM < 90500
522 vacstmt.type = T_VacuumStmt;
523 vacstmt.relation = NULL;
524 vacstmt.va_cols = NIL;
525 #if PG_VERSION_NUM >= 90000
526 vacstmt.options = VACOPT_ANALYZE;
527 if (online_analyze_verbose)
528 vacstmt.options |= VACOPT_VERBOSE;
530 vacstmt.vacuum = vacstmt.full = false;
531 vacstmt.analyze = true;
532 vacstmt.verbose = online_analyze_verbose;
535 vacstmt.multixact_freeze_min_age = -1;
536 vacstmt.multixact_freeze_table_age = -1;
537 vacstmt.log_min_duration = -1;
540 if (online_analyze_verbose)
541 startStamp = GetCurrentTimestamp();
544 #if PG_VERSION_NUM < 90500
546 #if PG_VERSION_NUM >= 90018
549 , GetAccessStrategy(BAS_VACUUM)
550 #if (PG_VERSION_NUM >= 90000) && (PG_VERSION_NUM < 90004)
554 makeRangeVarFromOid(relOid),
555 VACOPT_ANALYZE | ((online_analyze_verbose) ? VACOPT_VERBOSE : 0),
556 &vacstmt, NULL, true, GetAccessStrategy(BAS_VACUUM)
560 if (online_analyze_verbose)
565 endStamp = GetCurrentTimestamp();
566 TimestampDifference(startStamp, endStamp, &secs, µsecs);
567 elog(INFO, "analyze \"%s\" took %.02f seconds",
568 get_rel_name(relOid),
569 ((double)secs) + ((double)microsecs)/1.0e6);
572 rstat->autovac_analyze_timestamp = now;
573 rstat->changes_since_analyze = 0;
580 rstat->n_tuples += naffected;
582 rstat->rereadStat = (reltype == OATT_PERSISTENT);
585 case CK_FASTTRUNCATE:
586 rstat->rereadStat = false;
593 /* update last analyze timestamp in local memory of backend */
596 tabentry->analyze_timestamp = now;
597 tabentry->changes_since_analyze = 0;
600 /* force reload stat for new table */
602 pgstat_clear_snapshot();
607 #if PG_VERSION_NUM >= 90000
609 tabentry->changes_since_analyze += naffected;
615 rstat->changes_since_analyze += naffected;
616 rstat->n_tuples += naffected;
619 rstat->changes_since_analyze += 2 * naffected;
620 rstat->n_tuples += naffected;
622 rstat->changes_since_analyze += naffected;
625 case CK_FASTTRUNCATE:
626 rstat->changes_since_analyze = 0;
634 /* Reset local cache if we are over limit */
635 if (hash_get_num_entries(relstats) > online_analyze_capacity_threshold)
640 isFastTruncateCall(QueryDesc *queryDesc)
647 queryDesc->plannedstmt &&
648 queryDesc->operation == CMD_SELECT &&
649 queryDesc->plannedstmt->planTree &&
650 queryDesc->plannedstmt->planTree->targetlist &&
651 list_length(queryDesc->plannedstmt->planTree->targetlist) == 1 &&
652 IsA(linitial(queryDesc->plannedstmt->planTree->targetlist), TargetEntry)
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 &&
670 IsA(linitial(fe->args), Const)
674 constval = linitial(fe->args);
677 IsA(constval,Const) &&
678 constval->consttype == TEXTOID &&
679 strcmp(get_func_name(fe->funcid), "fasttruncate") == 0
688 extern PGDLLIMPORT void onlineAnalyzeHooker(QueryDesc *queryDesc);
690 onlineAnalyzeHooker(QueryDesc *queryDesc)
692 int64 naffected = -1;
695 if (queryDesc->estate)
696 naffected = queryDesc->estate->es_processed;
698 #if PG_VERSION_NUM >= 90200
699 if (online_analyze_enable &&
700 (constval = isFastTruncateCall(queryDesc)) != NULL)
702 Datum tblnamed = constval->constvalue;
703 char *tblname = text_to_cstring(DatumGetTextP(tblnamed));
705 makeRangeVarFromNameList(stringToQualifiedNameList(tblname));
707 makeAnalyze(RangeVarGetRelid(tblvar,
710 CK_FASTTRUNCATE, -1);
714 if (online_analyze_enable && queryDesc->plannedstmt &&
715 (queryDesc->operation == CMD_INSERT ||
716 queryDesc->operation == CMD_UPDATE ||
717 queryDesc->operation == CMD_DELETE
718 #if PG_VERSION_NUM < 90200
719 || (queryDesc->operation == CMD_SELECT &&
720 queryDesc->plannedstmt->intoClause)
724 #if PG_VERSION_NUM < 90200
725 if (queryDesc->operation == CMD_SELECT)
727 Oid relOid = RangeVarGetRelid(queryDesc->plannedstmt->intoClause->rel, true);
729 makeAnalyze(relOid, queryDesc->operation, naffected);
733 if (queryDesc->plannedstmt->resultRelations &&
734 queryDesc->plannedstmt->rtable)
738 foreach(l, queryDesc->plannedstmt->resultRelations)
740 int n = lfirst_int(l);
741 RangeTblEntry *rte = list_nth(queryDesc->plannedstmt->rtable, n-1);
743 if (rte->rtekind == RTE_RELATION)
744 makeAnalyze(rte->relid, (CmdKind)queryDesc->operation, naffected);
749 if (oldExecutorEndHook)
750 oldExecutorEndHook(queryDesc);
752 standard_ExecutorEnd(queryDesc);
755 #if PG_VERSION_NUM >= 90200
757 onlineAnalyzeHookerUtility(
758 #if PG_VERSION_NUM >= 100000
763 const char *queryString,
764 #if PG_VERSION_NUM >= 90300
765 ProcessUtilityContext context, ParamListInfo params,
766 #if PG_VERSION_NUM >= 100000
767 QueryEnvironment *queryEnv,
770 ParamListInfo params, bool isTopLevel,
772 DestReceiver *dest, char *completionTag) {
773 List *tblnames = NIL;
774 CmdKind op = CK_INSERT;
775 #if PG_VERSION_NUM >= 100000
776 Node *parsetree = NULL;
778 if (pstmt->commandType == CMD_UTILITY)
779 parsetree = pstmt->utilityStmt;
782 if (parsetree && online_analyze_enable)
784 if (IsA(parsetree, CreateTableAsStmt) &&
785 ((CreateTableAsStmt*)parsetree)->into)
788 list_make1((RangeVar*)copyObject(((CreateTableAsStmt*)parsetree)->into->rel));
791 else if (IsA(parsetree, TruncateStmt))
793 tblnames = list_copy(((TruncateStmt*)parsetree)->relations);
796 else if (IsA(parsetree, VacuumStmt))
798 VacuumStmt *vac = (VacuumStmt*)parsetree;
800 tblnames = list_make1(vac->relation);
802 if (vac->options & (VACOPT_VACUUM | VACOPT_FULL | VACOPT_FREEZE))
803 /* optionally with analyze */
805 else if (vac->options & VACOPT_ANALYZE)
812 #if PG_VERSION_NUM >= 100000
813 #define parsetree pstmt
816 if (oldProcessUtilityHook)
817 oldProcessUtilityHook(parsetree, queryString,
818 #if PG_VERSION_NUM >= 90300
820 #if PG_VERSION_NUM >= 100000
826 dest, completionTag);
828 standard_ProcessUtility(parsetree, queryString,
829 #if PG_VERSION_NUM >= 90300
831 #if PG_VERSION_NUM >= 100000
837 dest, completionTag);
839 #if PG_VERSION_NUM >= 100000
848 RangeVar *tblname = (RangeVar*)lfirst(l);
849 Oid tblOid = RangeVarGetRelid(tblname, NoLock, true);
851 makeAnalyze(tblOid, op, -1);
863 MemSet(&hash_ctl, 0, sizeof(hash_ctl));
865 hash_ctl.hash = oid_hash;
866 flags |= HASH_FUNCTION;
868 if (onlineAnalyzeMemoryContext)
870 Assert(relstats != NULL);
871 MemoryContextReset(onlineAnalyzeMemoryContext);
875 Assert(relstats == NULL);
876 onlineAnalyzeMemoryContext =
877 AllocSetContextCreate(CacheMemoryContext,
878 "online_analyze storage context",
879 #if PG_VERSION_NUM < 90600
880 ALLOCSET_DEFAULT_MINSIZE,
881 ALLOCSET_DEFAULT_INITSIZE,
882 ALLOCSET_DEFAULT_MAXSIZE
884 ALLOCSET_DEFAULT_SIZES
889 hash_ctl.hcxt = onlineAnalyzeMemoryContext;
890 flags |= HASH_CONTEXT;
892 hash_ctl.keysize = sizeof(Oid);
894 hash_ctl.entrysize = sizeof(OnlineAnalyzeTableStat);
897 relstats = hash_create("online_analyze storage", 1024, &hash_ctl, flags);
906 oldExecutorEndHook = ExecutorEnd_hook;
908 ExecutorEnd_hook = onlineAnalyzeHooker;
910 #if PG_VERSION_NUM >= 90200
911 oldProcessUtilityHook = ProcessUtility_hook;
913 ProcessUtility_hook = onlineAnalyzeHookerUtility;
917 DefineCustomBoolVariable(
918 "online_analyze.enable",
919 "Enable on-line analyze",
920 "Enables analyze of table directly after insert/update/delete/select into",
921 &online_analyze_enable,
922 #if PG_VERSION_NUM >= 80400
923 online_analyze_enable,
926 #if PG_VERSION_NUM >= 80400
928 #if PG_VERSION_NUM >= 90100
936 DefineCustomBoolVariable(
937 "online_analyze.local_tracking",
938 "Per backend tracking",
939 "Per backend tracking for temp tables (do not use system statistic)",
940 &online_analyze_local_tracking,
941 #if PG_VERSION_NUM >= 80400
942 online_analyze_local_tracking,
945 #if PG_VERSION_NUM >= 80400
947 #if PG_VERSION_NUM >= 90100
955 DefineCustomBoolVariable(
956 "online_analyze.verbose",
957 "Verbosity of on-line analyze",
958 "Make ANALYZE VERBOSE after table's changes",
959 &online_analyze_verbose,
960 #if PG_VERSION_NUM >= 80400
961 online_analyze_verbose,
964 #if PG_VERSION_NUM >= 80400
966 #if PG_VERSION_NUM >= 90100
974 DefineCustomRealVariable(
975 "online_analyze.scale_factor",
976 "fraction of table size to start on-line analyze",
977 "fraction of table size to start on-line analyze",
978 &online_analyze_scale_factor,
979 #if PG_VERSION_NUM >= 80400
980 online_analyze_scale_factor,
985 #if PG_VERSION_NUM >= 80400
987 #if PG_VERSION_NUM >= 90100
995 DefineCustomIntVariable(
996 "online_analyze.threshold",
997 "min number of row updates before on-line analyze",
998 "min number of row updates before on-line analyze",
999 &online_analyze_threshold,
1000 #if PG_VERSION_NUM >= 80400
1001 online_analyze_threshold,
1006 #if PG_VERSION_NUM >= 80400
1008 #if PG_VERSION_NUM >= 90100
1016 DefineCustomIntVariable(
1017 "online_analyze.capacity_threshold",
1018 "Max local cache table capacity",
1019 "Max local cache table capacity",
1020 &online_analyze_capacity_threshold,
1021 #if PG_VERSION_NUM >= 80400
1022 online_analyze_capacity_threshold,
1027 #if PG_VERSION_NUM >= 80400
1029 #if PG_VERSION_NUM >= 90100
1037 DefineCustomRealVariable(
1038 "online_analyze.min_interval",
1039 "minimum time interval between analyze call (in milliseconds)",
1040 "minimum time interval between analyze call (in milliseconds)",
1041 &online_analyze_min_interval,
1042 #if PG_VERSION_NUM >= 80400
1043 online_analyze_min_interval,
1048 #if PG_VERSION_NUM >= 80400
1050 #if PG_VERSION_NUM >= 90100
1058 DefineCustomEnumVariable(
1059 "online_analyze.table_type",
1060 "Type(s) of table for online analyze: all(default), persistent, temporary, none",
1062 &online_analyze_table_type,
1063 #if PG_VERSION_NUM >= 80400
1064 online_analyze_table_type,
1066 online_analyze_table_type_options,
1068 #if PG_VERSION_NUM >= 80400
1070 #if PG_VERSION_NUM >= 90100
1078 DefineCustomStringVariable(
1079 "online_analyze.exclude_tables",
1080 "List of tables which will not online analyze",
1082 &excludeTables.tableStr,
1083 #if PG_VERSION_NUM >= 80400
1088 #if PG_VERSION_NUM >= 90100
1090 excludeTablesAssign,
1092 excludeTablesAssign,
1097 DefineCustomStringVariable(
1098 "online_analyze.include_tables",
1099 "List of tables which will online analyze",
1101 &includeTables.tableStr,
1102 #if PG_VERSION_NUM >= 80400
1107 #if PG_VERSION_NUM >= 90100
1109 includeTablesAssign,
1111 includeTablesAssign,
1116 DefineCustomIntVariable(
1117 "online_analyze.lower_limit",
1118 "min number of rows in table to analyze",
1119 "min number of rows in table to analyze",
1120 &online_analyze_lower_limit,
1121 #if PG_VERSION_NUM >= 80400
1122 online_analyze_lower_limit,
1127 #if PG_VERSION_NUM >= 80400
1129 #if PG_VERSION_NUM >= 90100
1139 void _PG_fini(void);
1143 ExecutorEnd_hook = oldExecutorEndHook;
1144 #if PG_VERSION_NUM >= 90200
1145 ProcessUtility_hook = oldProcessUtilityHook;
1148 if (excludeTables.tables)
1149 free(excludeTables.tables);
1150 if (includeTables.tables)
1151 free(includeTables.tables);
1153 excludeTables.tables = includeTables.tables = NULL;
1154 excludeTables.nTables = includeTables.nTables = 0;