You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 25.1 we enabled automatic partial stats collection by default. It
works by scanning an index of the table outside of the bounds according
to the last stats collection (i.e. lower than min and higher than max).
If the last stats collection was such that there is no lower bound (which
can happen when we only have a bucket for NULL values as well as "outer"
buckets), we fail the partial stats collection. Previously, this would
result in failing the stats collection job which is logged at the ERROR
level, but this failure is benign and shouldn't result in a scary
looking log.
To prevent unnecessary user concerns this commit adds the logic to
swallow the benign errors which allows us to short-circuit the
particular stats collection without failing the job. We currently treat
all errors with `ObjectNotInPrerequisiteState` PG code as "benign"
(there are 4 more related to partial stats, apart from the scenario
mentioned above). To have some observability into this swalling behavior
we add a log message at INFO level. Additionally, we don't swallow the
error if the stats collection was executed via EXPLAIN or EXPLAIN ANALYZE
(meaning that it was explicitly user-initiated).
The fact that the job will be marked as having "succeeded" can be
confusing since it won't have a corresponding new statistics, but we find
this behavior better overall.
Additionally, this commit extends the error message to also include the
table and index names as well as their IDs.
Release note (bug fix): In 25.1 version CockroachDB enabled automatic
partial stats collection by default (by flipping
`sql.stats.automatic_partial_collection.enabled` cluster setting to
`true`). Previously, partial stats collection could encounter some
expected scenarios that would be reported with PG error code `55000`
and would show up as failed stats jobs. These errors are benign and will
no longer be reported (the stats job will be marked as "succeeded" but
new stats won't be created).
Copy file name to clipboardExpand all lines: docs/generated/settings/settings-for-tenants.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -369,7 +369,7 @@ sql.stats.multi_column_collection.enabled boolean true multi-column statistics c
369
369
sql.stats.non_default_columns.min_retention_period duration 24h0m0s minimum retention period for table statistics collected on non-default columns application
370
370
sql.stats.non_indexed_json_histograms.enabled boolean false set to true to collect table statistics histograms on non-indexed JSON columns application
371
371
sql.stats.persisted_rows.max integer 1000000 maximum number of rows of statement and transaction statistics that will be persisted in the system tables before compaction begins application
372
-
sql.stats.post_events.enabled boolean false if set, an event is logged for every CREATE STATISTICS job application
372
+
sql.stats.post_events.enabled boolean false if set, an event is logged for every successful CREATE STATISTICS job application
373
373
sql.stats.response.max integer 20000 the maximum number of statements and transaction stats returned in a CombinedStatements request application
374
374
sql.stats.response.show_internal.enabled boolean false controls if statistics for internal executions should be returned by the CombinedStatements and if internal sessions should be returned by the ListSessions endpoints. These endpoints are used to display statistics on the SQL Activity pages application
375
375
sql.stats.system_tables.enabled boolean true when true, enables use of statistics on system tables by the query optimizer application
Copy file name to clipboardExpand all lines: docs/generated/settings/settings.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -324,7 +324,7 @@
324
324
<tr><td><divid="setting-sql-stats-non-default-columns-min-retention-period" class="anchored"><code>sql.stats.non_default_columns.min_retention_period</code></div></td><td>duration</td><td><code>24h0m0s</code></td><td>minimum retention period for table statistics collected on non-default columns</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
325
325
<tr><td><divid="setting-sql-stats-non-indexed-json-histograms-enabled" class="anchored"><code>sql.stats.non_indexed_json_histograms.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>set to true to collect table statistics histograms on non-indexed JSON columns</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
326
326
<tr><td><divid="setting-sql-stats-persisted-rows-max" class="anchored"><code>sql.stats.persisted_rows.max</code></div></td><td>integer</td><td><code>1000000</code></td><td>maximum number of rows of statement and transaction statistics that will be persisted in the system tables before compaction begins</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
327
-
<tr><td><divid="setting-sql-stats-post-events-enabled" class="anchored"><code>sql.stats.post_events.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>if set, an event is logged for every CREATE STATISTICS job</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
327
+
<tr><td><divid="setting-sql-stats-post-events-enabled" class="anchored"><code>sql.stats.post_events.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>if set, an event is logged for every successful CREATE STATISTICS job</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
328
328
<tr><td><divid="setting-sql-stats-response-max" class="anchored"><code>sql.stats.response.max</code></div></td><td>integer</td><td><code>20000</code></td><td>the maximum number of statements and transaction stats returned in a CombinedStatements request</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
329
329
<tr><td><divid="setting-sql-stats-response-show-internal-enabled" class="anchored"><code>sql.stats.response.show_internal.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>controls if statistics for internal executions should be returned by the CombinedStatements and if internal sessions should be returned by the ListSessions endpoints. These endpoints are used to display statistics on the SQL Activity pages</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
330
330
<tr><td><divid="setting-sql-stats-system-tables-enabled" class="anchored"><code>sql.stats.system_tables.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>when true, enables use of statistics on system tables by the query optimizer</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
Copy file name to clipboardExpand all lines: pkg/sql/logictest/testdata/logic_test/distsql_stats
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2702,10 +2702,10 @@ statement ok
2702
2702
CREATE TABLE xyz (x INT, y INT, z INT, INDEX (x, y));
2703
2703
2704
2704
statement error pq: column x does not have a prior statistic
2705
-
CREATE STATISTICS xyz_x ON x FROM xyz USING EXTREMES;
2705
+
EXPLAIN ANALYZE CREATE STATISTICS xyz_x ON x FROM xyz USING EXTREMES;
2706
2706
2707
2707
statement error pq: the latest full statistic for column a has no histogram
2708
-
CREATE STATISTICS u_partial ON a FROM u USING EXTREMES;
2708
+
EXPLAIN ANALYZE CREATE STATISTICS u_partial ON a FROM u USING EXTREMES;
2709
2709
2710
2710
statement error pq: table xy does not contain a non-partial forward index with y as a prefix column
2711
2711
CREATE STATISTICS xy_y_partial ON y FROM xy USING EXTREMES;
@@ -2724,8 +2724,8 @@ CREATE STATISTICS only_null_stat ON a FROM only_null;
2724
2724
statement ok
2725
2725
SELECT crdb_internal.clear_table_stats_cache();
2726
2726
2727
-
statement error pq: only outer or NULL bounded buckets exist in the index, so partial stats cannot be collected
2728
-
CREATE STATISTICS only_null_partial ON a FROM only_null USING EXTREMES;
2727
+
statement error pq: only outer or NULL bounded buckets exist in only_null@only_null_a_idx \(table ID \d+, column IDs \[1\]\), so partial stats cannot be collected
2728
+
EXPLAIN ANALYZE CREATE STATISTICS only_null_partial ON a FROM only_null USING EXTREMES;
0 commit comments