add online_analyze.lower_limit, use int64 to count changes rows
authorTeodor Sigaev <teodor@sigaev.ru>
Fri, 3 Feb 2017 14:39:08 +0000 (17:39 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Fri, 3 Feb 2017 14:39:08 +0000 (17:39 +0300)
README.online_analyze
online_analyze.c

index b181da5..f7d2942 100644 (file)
@@ -24,6 +24,9 @@ online_analyze.threshold = 50
 online_analyze.min_interval = 10000
     Minimum time interval between analyze call per table (in milliseconds)
 
+online_analyze.lower_limit = 0
+       Min number of rows in table to analyze
+
 online_analyze.table_type = "all"
        Type(s) of table for online analyze: all, persistent, temporary, none
 
index b1a3578..924cc7e 100644 (file)
@@ -63,6 +63,7 @@ static double online_analyze_scale_factor = 0.1;
 static int online_analyze_threshold = 50;
 static int online_analyze_capacity_threshold = 100000;
 static double online_analyze_min_interval = 10000;
+static int online_analyze_lower_limit = 0;
 
 static ExecutorEnd_hook_type oldExecutorEndHook = NULL;
 #if PG_VERSION_NUM >= 90200
@@ -336,7 +337,7 @@ makeRangeVarFromOid(Oid relOid)
 #endif
 
 static void
-makeAnalyze(Oid relOid, CmdType operation, int32 naffected)
+makeAnalyze(Oid relOid, CmdType operation, int64 naffected)
 {
        TimestampTz                             now = GetCurrentTimestamp();
        Relation                                rel;
@@ -454,6 +455,8 @@ makeAnalyze(Oid relOid, CmdType operation, int32 naffected)
                /* do not analyze too often, if both stamps are exceeded the go */
                TimestampDifferenceExceeds(rstat->analyze_timestamp, now, online_analyze_min_interval) &&
                TimestampDifferenceExceeds(rstat->autovac_analyze_timestamp, now, online_analyze_min_interval) &&
+               /* do not analyze too small tables */
+               rstat->n_tuples + rstat->changes_since_analyze + naffected > online_analyze_lower_limit &&
                /* be in sync with relation_needs_vacanalyze */
                ((double)(rstat->changes_since_analyze + naffected)) >=
                         online_analyze_scale_factor * ((double)rstat->n_tuples) +
@@ -559,7 +562,7 @@ extern PGDLLIMPORT void onlineAnalyzeHooker(QueryDesc *queryDesc);
 void
 onlineAnalyzeHooker(QueryDesc *queryDesc)
 {
-       uint32  naffected = -1;
+       int64   naffected = -1;
 
        if (queryDesc->estate)
                naffected = queryDesc->estate->es_processed;
@@ -883,6 +886,28 @@ _PG_init(void)
 #endif
                includeTablesShow
        );
+
+       DefineCustomIntVariable(
+               "online_analyze.lower_limit",
+               "min number of rows in table to analyze",
+               "min number of rows in table to analyze",
+               &online_analyze_lower_limit,
+#if PG_VERSION_NUM >= 80400
+               online_analyze_lower_limit,
+#endif
+               0,
+               0x7fffffff,
+               PGC_USERSET,
+#if PG_VERSION_NUM >= 80400
+               GUC_NOT_IN_SAMPLE,
+#if PG_VERSION_NUM >= 90100
+               NULL,
+#endif
+#endif
+               NULL,
+               NULL
+       );
+
 }
 
 void _PG_fini(void);