- tabentry == NULL /* a new table */ ||
- (
- /* do not analyze too often, if both stamps are exceeded the go */
- TimestampDifferenceExceeds(tabentry->analyze_timestamp, now, online_analyze_min_interval) &&
- TimestampDifferenceExceeds(tabentry->autovac_analyze_timestamp, now, online_analyze_min_interval) &&
- /* be in sync with relation_needs_vacanalyze */
- ((double)(changes_since_analyze(tabentry) + naffected)) >=
- online_analyze_scale_factor * ((double)(tabentry->n_dead_tuples + tabentry->n_live_tuples)) +
- (double)online_analyze_threshold
- )
- )
+ /* do not reread data if it was a truncation */
+ operation != CK_TRUNCATE && operation != CK_FASTTRUNCATE &&
+ /* read for persistent table and for temp teble if it allowed */
+ (reltype == OATT_PERSISTENT || online_analyze_local_tracking == false) &&
+ /* read only for new table or we know that it's needed */
+ (newTable == true || rstat->rereadStat == true)
+ )
+ {
+ rstat->rereadStat = false;
+
+ tabentry = pgstat_fetch_stat_tabentry(relOid);
+
+ if (tabentry)
+ {
+ rstat->n_tuples =
+#if PG_VERSION_NUM >= 160000
+ tabentry->dead_tuples + tabentry->live_tuples;
+#else
+ tabentry->n_dead_tuples + tabentry->n_live_tuples;
+#endif
+
+ rstat->mod_since_analyze =
+#if PG_VERSION_NUM >= 160000
+ tabentry->mod_since_analyze;
+#elif PG_VERSION_NUM >= 90000
+ tabentry->changes_since_analyze;
+#else
+ tabentry->n_live_tuples + tabentry->n_dead_tuples -
+ tabentry->last_anl_tuples;
+#endif
+
+ rstat->last_autoanalyze_time =
+#if PG_VERSION_NUM >= 160000
+ tabentry->last_autoanalyze_time;
+#else
+ tabentry->autovac_analyze_timestamp;
+#endif
+
+ rstat->last_analyze_time =
+#if PG_VERSION_NUM >= 160000
+ tabentry->last_analyze_time;
+#else
+ tabentry->analyze_timestamp;
+#endif
+ }
+ }
+
+ if (newTable ||
+ /* force analyze after truncate, fasttruncate already did analyze */
+ operation == CK_TRUNCATE || (
+ /* do not analyze too often, if both stamps are exceeded the go */
+ TimestampDifferenceExceeds(rstat->last_analyze_time, now, online_analyze_min_interval) &&
+ TimestampDifferenceExceeds(rstat->last_autoanalyze_time, now, online_analyze_min_interval) &&
+ /* do not analyze too small tables */
+ rstat->n_tuples + rstat->mod_since_analyze + naffected > online_analyze_lower_limit &&
+ /* be in sync with relation_needs_vacanalyze */
+ ((double)(rstat->mod_since_analyze + naffected)) >=
+ online_analyze_scale_factor * ((double)rstat->n_tuples) +
+ (double)online_analyze_threshold))