-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql/stats: collect statistics over system tables #80123
Comments
There's two parts to this:
|
Informs cockroachdb#80123 Previously, statistics could be collected on system tables, but their use in the optimizer for planning queries was disabled. This was inadequate because without stats, full table scan might be chosen by the optimizer for queries involving system tables in cases where index access is actually cheaper. Also, it is confusing that one could ANALYZE a system table, but the collected statistics would not be used when querying the table, as shown in the EXPLAIN output. To address this, this patch enables stats usage on all system tables except system.table_statistics and system.lease, as doing so may cause hangs. A new tenant-writable cluster setting is added, `sql.stats.system_tables.enabled`, which when true allows statistics on system tables to be used by the optimizer for costing and planning queries. The default value of this setting is `true`. Collection of statistics on `system.table_statistics` and `system.lease` has been disabled because it would be confusing to allow stats to be collected that would never be used by the optimizer. Release note: none
@irfansharif In this issue you mention |
I don't need statistics over |
Is there a reason we should automatically collect stats on system tables? Or is manual collection for system tables sufficient? |
Some of these system tables are driven by automatic processes/jobs. |
Informs cockroachdb#80123 Previously, statistics could be collected on system tables, but their use in the optimizer for planning queries was disabled. This was inadequate because without stats, full table scan might be chosen by the optimizer for queries involving system tables in cases where index access is actually cheaper. Also, it is confusing that one could ANALYZE a system table, but the collected statistics would not be used when querying the table, as shown in the EXPLAIN output. To address this, this patch enables stats usage on all system tables except system.table_statistics and system.lease, as doing so may cause hangs. A new tenant-writable cluster setting is added, `sql.stats.system_tables.enabled`, which when true allows statistics on system tables to be used by the optimizer for costing and planning queries. The default value of this setting is `true`. Collection of statistics on `system.table_statistics` and `system.lease` has been disabled because it would be confusing to allow stats to be collected that would never be used by the optimizer. Release note: none
I don't know of any specific reason not to enable it, but I can imagine if some system tables are small and constantly getting updates, it might trigger a lot of stats collections, and I'm not sure if the extra reads from system tables might cause contention with writes. Also, with stats on system tables changing a lot, what would the stability of query plans for internal queries be like? With no stats, nothing is changing, but with fluctuating stats, plans will change, and if they change for the worse that may be difficult to debug. Regressions in system queries may also affect system stability so could have a greater impact than regressions in user queries. Though maybe our internal queries aren't too complex. I haven't really looked at all of them. |
Is this concern any different from small + write-heavy user tables? Or is it just that our existing system tables so far haven't functioned with auto stats, so we should tread carefully. That's fair -- at the very least I'd like |
Yes, mainly just the fear of adding more moving parts to the system. I don't know if anyone else would be worried about this. Having autostats on just a subset of system tables sounds like a good option, but maybe my fears are overblown. Would need to take a closer look. |
I don't think the reads on system tables will contend with writes because we use cockroach/pkg/sql/stats/automatic_stats.go Lines 493 to 508 in 0fcbb3c
I'm hesitant about introducing this too. We could put it behind a setting that defaults to off. If we got confidence in it before the 22.2 release we could switch it to on by default. |
Or we could default it to on at first to get more testing exposure, then switch it off before 22.2 if we see any abnormalities or suspicious slowdowns in tests. |
80761: stats: enable optimizer stats use on system tables for query planning r=msirek a=msirek Informs #80123 Previously, statistics could be collected on system tables, but their use in the optimizer for planning queries was disabled. This was inadequate because without stats, full table scan might be chosen by the optimizer for queries involving system tables in cases where index access is actually cheaper. Also, it is confusing that one could ANALYZE a system table, but the collected statistics would not be used when querying the table, as shown in the EXPLAIN output. To address this, this patch enables stats usage on all system tables except system.table_statistics and system.lease, as doing so may cause hangs. A new tenant-writable cluster setting is added, `sql.stats.system_tables.enabled`, which when true allows statistics on system tables to be used by the optimizer for costing and planning queries. The default value of this setting is `true`. Collection of statistics on `system.table_statistics` and `system.lease` has been disabled because it would be confusing to allow stats to be collected that would never be used by the optimizer. Release note: none Co-authored-by: Mark Sirek <[email protected]>
Sorry for joining the discussion late...
Yes, I'd be in favor of enabling this now, and we can disable it later if need be. |
Fixes cockroachdb#80123 Previously, mutations to system tables did not trigger automatic collection of statistics to influence optimizer costs and plan selection. This was inadequate because system tables are being used in increasingly sophisticated ways in queries, most notably around driving subsystems in CRDB, requiring avoidance of full table scans. Manual collection of stats on system tables is not sufficient to meet requirements as system tables are driven by automatic processes/jobs. To address this, this patch enables auto stats collection on system tables by default, which can be disabled by setting new cluster setting `sql.stats.system_tables_autostats.enabled` to false. Auto stats are always disabled on `system.lease` and `system.table_statistics`, no matter to value of the cluster setting, because they could potentially cause hangs if enabled. Release note: none
Fixes cockroachdb#80123 Previously, mutations to system tables did not trigger automatic collection of statistics to influence optimizer costs and plan selection. This was inadequate because system tables are being used in increasingly sophisticated ways in queries, most notably around driving subsystems in CRDB, requiring avoidance of full table scans. Manual collection of stats on system tables is not sufficient to meet requirements as system tables are driven by automatic processes/jobs. To address this, this patch enables auto stats collection on system tables by default, which can be disabled by setting new cluster setting `sql.stats.system_tables_autostats.enabled` to false. Auto stats are always disabled on `system.lease` and `system.table_statistics`, no matter the value of the cluster setting, because they could potentially cause hangs if enabled. Release note: none
Fixes cockroachdb#80123 Previously, mutations to system tables did not trigger automatic collection of statistics to influence optimizer costs and plan selection. This was inadequate because system tables are being used in increasingly sophisticated ways in queries, most notably around driving subsystems in CRDB, requiring avoidance of full table scans. Manual collection of stats on system tables is not sufficient to meet requirements as system tables are driven by automatic processes/jobs. To address this, this patch enables auto stats collection on system tables by default, which can be disabled by setting new cluster setting `sql.stats.system_tables_autostats.enabled` to false. Auto stats are always disabled on `system.lease`, `system.table_statistics`, `system.jobs` and `system.scheduled_jobs`, no matter the value of the cluster setting. Autostats on the first two tables could potentially cause hangs, and autostats on the last two tables could potentially impact system performance. Release note: none
Fixes cockroachdb#80123 Previously, mutations to system tables did not trigger automatic collection of statistics to influence optimizer costs and plan selection. This was inadequate because system tables are being used in increasingly sophisticated ways in queries, most notably around driving subsystems in CRDB, requiring avoidance of full table scans. Manual collection of stats on system tables is not sufficient to meet requirements as system tables are driven by automatic processes/jobs. To address this, this patch enables auto stats collection on system tables by default, which can be disabled by setting new cluster setting `sql.stats.system_tables_autostats.enabled` to false. Auto stats are always disabled on `system.lease`, `system.table_statistics`, `system.jobs` and `system.scheduled_jobs`, no matter the value of the cluster setting. Autostats on the first two tables could potentially cause hangs, and autostats on the last two tables could potentially impact system performance. Release note: none
80887: stats: enable auto stats collection on system tables r=msirek a=msirek Fixes #80123 Previously, mutations to system tables did not trigger automatic collection of statistics to influence optimizer costs and plan selection. This was inadequate because system tables are being used in increasingly sophisticated ways in queries, most notably around driving subsystems in CRDB, requiring avoidance of full table scans. Manual collection of stats on system tables is not sufficient to meet requirements as system tables are driven by automatic processes/jobs. To address this, this patch enables auto stats collection on system tables by default, which can be disabled by setting new cluster setting `sql.stats.system_tables_autostats.enabled` to false. Auto stats are always disabled on `system.lease`, `system.table_statistics`, `system.jobs` and `system.scheduled_jobs`, no matter the value of the cluster setting. Autostats on the first two tables could potentially cause hangs, and autostats on the last two tables could potentially impact system performance. Release note: none Co-authored-by: Mark Sirek <[email protected]>
Is your feature request related to a problem? Please describe.
We're using system tables for increasingly sophisticated usages, mostly around driving subsystems in CRDB.
system.span_configurations
is one example and is used to drive the span configs infrastructure. We currently don't auto-collect statistics over system tables, and when statistics are available (if triggered manually throughANALYZE system.some_table
for e.g.) we ignore system table statistics. See:cockroach/pkg/sql/stats/stats_cache.go
Lines 225 to 229 in b01d6c7
Describe the solution you'd like
For us to collect stats over system tables (we could either have tables opt-in or opt-out depending; we have some uncertainty around whether it made sense to consult stats over
system.table_statistics
).Describe alternatives you've considered
Not doing anything, which has severe performance implications for the span configs infrastructure. In #78215 we attributed the lack of statistics to the reason why the optimizer chooses a full table scan for an internal query, as opposed to bounded segmented index scans. For a large number of schemas, this is going to be slow.
+cc @rytaft, @ajwerner.
Jira issue: CRDB-15838
The text was updated successfully, but these errors were encountered: