Skip to content

Commit adc3de4

Browse files
craig[bot]dhartunian
andcommitted
Merge #151502
151502: sql: set fraction stale rows to 4 on sql stats tables r=michae2,alyshanjahani-crl a=dhartunian Previously, stats collection on StatementStatisticsTableSchema and TransactionStatisticsTableSchema were triggered at 20% stale rows which was very low and would trigger often during flushing of SQL statement stats. This commit adds a migration that sets `sql_stats_automatic_collection_fraction_stale_rows` at 4 which will reduce stats collection overhead. Since this table is updated very regularly, we expect stats to stay up to date even with the higher threshold. As recommended, we also set `sql_stats_automatic_partial_collection_fraction_stale_rows` to 1.0 Michael Erickson contributed helpful insights: See #147443 (comment) for calculations that led to the number selection. There was an additional discussion on this PR regarding setting static stats, that was also rejected since the queries running on these tables are varied and complex. See #151502 (review) Resolves: #147443 Epic: None Release note: None Co-authored-by: David Hartunian <[email protected]>
2 parents 22b0b5b + c52ad13 commit adc3de4

File tree

12 files changed

+223
-36
lines changed

12 files changed

+223
-36
lines changed

docs/generated/settings/settings-for-tenants.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,4 @@ trace.zipkin.collector string the address of a Zipkin instance to receive trace
421421
ui.database_locality_metadata.enabled boolean true if enabled shows extended locality data about databases and tables in DB Console which can be expensive to compute application
422422
ui.default_timezone string the default timezone used to format timestamps in the ui application
423423
ui.display_timezone enumeration etc/utc the timezone used to format timestamps in the ui. This setting is deprecatedand will be removed in a future version. Use the 'ui.default_timezone' setting instead. 'ui.default_timezone' takes precedence over this setting. [etc/utc = 0, america/new_york = 1] application
424-
version version 1000025.3-upgrading-to-1000025.4-step-010 set the active cluster version in the format '<major>.<minor>' application
424+
version version 1000025.3-upgrading-to-1000025.4-step-012 set the active cluster version in the format '<major>.<minor>' application

docs/generated/settings/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,6 @@
379379
<tr><td><div id="setting-ui-database-locality-metadata-enabled" class="anchored"><code>ui.database_locality_metadata.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>if enabled shows extended locality data about databases and tables in DB Console which can be expensive to compute</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
380380
<tr><td><div id="setting-ui-default-timezone" class="anchored"><code>ui.default_timezone</code></div></td><td>string</td><td><code></code></td><td>the default timezone used to format timestamps in the ui</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
381381
<tr><td><div id="setting-ui-display-timezone" class="anchored"><code>ui.display_timezone</code></div></td><td>enumeration</td><td><code>etc/utc</code></td><td>the timezone used to format timestamps in the ui. This setting is deprecatedand will be removed in a future version. Use the &#39;ui.default_timezone&#39; setting instead. &#39;ui.default_timezone&#39; takes precedence over this setting. [etc/utc = 0, america/new_york = 1]</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
382-
<tr><td><div id="setting-version" class="anchored"><code>version</code></div></td><td>version</td><td><code>1000025.3-upgrading-to-1000025.4-step-010</code></td><td>set the active cluster version in the format &#39;&lt;major&gt;.&lt;minor&gt;&#39;</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
382+
<tr><td><div id="setting-version" class="anchored"><code>version</code></div></td><td>version</td><td><code>1000025.3-upgrading-to-1000025.4-step-012</code></td><td>set the active cluster version in the format &#39;&lt;major&gt;.&lt;minor&gt;&#39;</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
383383
</tbody>
384384
</table>

pkg/clusterversion/cockroach_versions.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ const (
222222
// system.statement_diagnostics to support transaction-level diagnostic bundle collection.
223223
V25_4_TransactionDiagnosticsSupport
224224

225+
// V25_4_SystemStatsTablesAutostatsFraction sets the autostats fraction for
226+
// system.statement_statistics and system.transaction_statistics to 0.9
227+
// to reduce frequent automatic statistics collection.
228+
V25_4_SystemStatsTablesAutostatsFraction
229+
225230
// *************************************************
226231
// Step (1) Add new versions above this comment.
227232
// Do not add new versions to a patch release.
@@ -281,6 +286,8 @@ var versionTable = [numKeys]roachpb.Version{
281286

282287
V25_4_TransactionDiagnosticsSupport: {Major: 25, Minor: 3, Internal: 10},
283288

289+
V25_4_SystemStatsTablesAutostatsFraction: {Major: 25, Minor: 3, Internal: 12},
290+
284291
// *************************************************
285292
// Step (2): Add new versions above this comment.
286293
// Do not add new versions to a patch release.

pkg/sql/catalog/bootstrap/testdata/testdata

Lines changed: 8 additions & 8 deletions
Large diffs are not rendered by default.

pkg/sql/catalog/systemschema/system.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ CREATE TABLE system.statement_statistics (
702702
total_estimated_execution_time,
703703
p99_latency
704704
)
705-
)
705+
) WITH (sql_stats_automatic_collection_fraction_stale_rows = 4, sql_stats_automatic_partial_collection_fraction_stale_rows = 1);
706706
`
707707

708708
TransactionStatisticsTableSchema = `
@@ -751,7 +751,7 @@ CREATE TABLE system.transaction_statistics (
751751
total_estimated_execution_time,
752752
p99_latency
753753
)
754-
);
754+
) WITH (sql_stats_automatic_collection_fraction_stale_rows = 4, sql_stats_automatic_partial_collection_fraction_stale_rows = 1);
755755
`
756756

757757
StatementActivityTableSchema = `
@@ -1421,7 +1421,7 @@ const SystemDatabaseName = catconstants.SystemDatabaseName
14211421
// release version).
14221422
//
14231423
// NB: Don't set this to clusterversion.Latest; use a specific version instead.
1424-
var SystemDatabaseSchemaBootstrapVersion = clusterversion.V25_4_TransactionDiagnosticsSupport.Version()
1424+
var SystemDatabaseSchemaBootstrapVersion = clusterversion.V25_4_SystemStatsTablesAutostatsFraction.Version()
14251425

14261426
// MakeSystemDatabaseDesc constructs a copy of the system database
14271427
// descriptor.
@@ -3380,6 +3380,10 @@ var (
33803380
ConstraintID: tbl.NextConstraintID,
33813381
}}
33823382
tbl.NextConstraintID++
3383+
tbl.AutoStatsSettings = &catpb.AutoStatsSettings{
3384+
FractionStaleRows: &[]float64{4.0}[0],
3385+
PartialFractionStaleRows: &[]float64{1.0}[0],
3386+
}
33833387
},
33843388
)
33853389

@@ -3604,6 +3608,10 @@ var (
36043608
ConstraintID: tbl.NextConstraintID,
36053609
}}
36063610
tbl.NextConstraintID++
3611+
tbl.AutoStatsSettings = &catpb.AutoStatsSettings{
3612+
FractionStaleRows: &[]float64{4.0}[0],
3613+
PartialFractionStaleRows: &[]float64{1.0}[0],
3614+
}
36073615
},
36083616
)
36093617

pkg/sql/catalog/systemschema_test/testdata/bootstrap_system

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

pkg/sql/catalog/systemschema_test/testdata/bootstrap_tenant

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

pkg/sql/logictest/testdata/logic_test/crdb_internal_catalog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ skipif config schema-locked-disabled local-mixed-25.3
133133
query IT
134134
SELECT id, strip_volatile(descriptor) FROM crdb_internal.kv_catalog_descriptor WHERE id IN (1, 2, 3, 29, 4294966962) OR (id > 100 and id < 200) ORDER BY id
135135
----
136-
1 {"database": {"id": 1, "name": "system", "privileges": {"ownerProto": "node", "users": [{"privileges": "2048", "userProto": "admin", "withGrantOption": "2048"}, {"privileges": "2048", "userProto": "root", "withGrantOption": "2048"}], "version": 3}, "systemDatabaseSchemaVersion": {"internal": 10, "majorVal": 1000025, "minorVal": 3}, "version": "1"}}
136+
1 {"database": {"id": 1, "name": "system", "privileges": {"ownerProto": "node", "users": [{"privileges": "2048", "userProto": "admin", "withGrantOption": "2048"}, {"privileges": "2048", "userProto": "root", "withGrantOption": "2048"}], "version": 3}, "systemDatabaseSchemaVersion": {"internal": 12, "majorVal": 1000025, "minorVal": 3}, "version": "1"}}
137137
3 {"table": {"columns": [{"id": 1, "name": "id", "type": {"family": "IntFamily", "oid": 20, "width": 64}}, {"id": 2, "name": "descriptor", "nullable": true, "type": {"family": "BytesFamily", "oid": 17}}], "formatVersion": 3, "id": 3, "name": "descriptor", "nextColumnId": 3, "nextConstraintId": 2, "nextIndexId": 2, "nextMutationId": 1, "parentId": 1, "primaryIndex": {"constraintId": 1, "encodingType": 1, "foreignKey": {}, "geoConfig": {}, "id": 1, "interleave": {}, "keyColumnDirections": ["ASC"], "keyColumnIds": [1], "keyColumnNames": ["id"], "name": "primary", "partitioning": {}, "sharded": {}, "storeColumnIds": [2], "storeColumnNames": ["descriptor"], "unique": true, "vecConfig": {}, "version": 4}, "privileges": {"ownerProto": "node", "users": [{"privileges": "32", "userProto": "admin", "withGrantOption": "32"}, {"privileges": "32", "userProto": "root", "withGrantOption": "32"}], "version": 3}, "replacementOf": {"time": {}}, "unexposedParentSchemaId": 29, "version": "1"}}
138138
29 {"schema": {"defaultPrivileges": {"type": "SCHEMA"}, "id": 29, "name": "public", "privileges": {"ownerProto": "node", "users": [{"privileges": "2", "userProto": "admin", "withGrantOption": "2"}, {"privileges": "516", "userProto": "public"}, {"privileges": "2", "userProto": "root", "withGrantOption": "2"}], "version": 3}, "version": "1"}}
139139
101 {"schema": {"id": 101, "name": "public", "parentId": 100, "privileges": {"ownerProto": "root", "users": [{"privileges": "2", "userProto": "admin", "withGrantOption": "2"}, {"privileges": "516", "userProto": "public"}, {"privileges": "2", "userProto": "root", "withGrantOption": "2"}], "version": 3}, "version": "1"}}

pkg/upgrade/upgrades/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ go_library(
2020
"v25_3_add_hot_range_logger_job.go",
2121
"v25_3_add_users_last_login_time_column.go",
2222
"v25_4_inspect_errors_table.go",
23+
"v25_4_system_stats_tables_autostats_fraction.go",
2324
"v25_4_transaction_diagnostics_tables.go",
2425
],
2526
importpath = "github.com/cockroachdb/cockroach/pkg/upgrade/upgrades",
@@ -87,6 +88,7 @@ go_test(
8788
"v25_3_add_hot_range_logger_job_test.go",
8889
"v25_3_add_users_last_login_time_column_test.go",
8990
"v25_4_inspect_errors_table_test.go",
91+
"v25_4_system_stats_tables_autostats_fraction_test.go",
9092
"v25_4_transaction_diagnostics_tables_test.go",
9193
"version_starvation_test.go",
9294
],

pkg/upgrade/upgrades/upgrades.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ var upgrades = []upgradebase.Upgrade{
103103
upgrade.RestoreActionNotRequired("cluster restore does not restore these tables"),
104104
),
105105

106+
upgrade.NewTenantUpgrade(
107+
"set autostats fraction for system stats tables",
108+
clusterversion.V25_4_SystemStatsTablesAutostatsFraction.Version(),
109+
upgrade.NoPrecondition,
110+
systemStatsTablesAutostatsFractionMigration,
111+
upgrade.RestoreActionNotRequired("cluster restore does not restore table storage parameters"),
112+
),
113+
106114
// Note: when starting a new release version, the first upgrade (for
107115
// Vxy_zStart) must be a newFirstUpgrade. Keep this comment at the bottom.
108116
}

0 commit comments

Comments
 (0)