Skip to content
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/logictest: disable stats collection for system tables earlier #99155

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,14 @@ func (t *logicTest) newCluster(
stats.DefaultAsOfTime = 10 * time.Millisecond
stats.DefaultRefreshInterval = time.Millisecond

// Disable stats collection on system tables before the cluster is started,
// otherwise there is a race condition where stats may be collected before we
// can disable them with `SET CLUSTER SETTING`. We disable stats collection on
// system tables in order to have deterministic tests.
stats.AutomaticStatisticsOnSystemTables.Override(
context.Background(), &params.ServerArgs.TempStorageConfig.Settings.SV, false,
)

t.cluster = serverutils.StartNewTestCluster(t.rootT, cfg.NumNodes, params)
if cfg.UseFakeSpanResolver {
fakeResolver := physicalplanutils.FakeResolverForTestCluster(t.cluster)
Expand Down Expand Up @@ -1640,11 +1648,6 @@ func (t *logicTest) newCluster(
); err != nil {
t.Fatal(err)
}
if _, err := conn.Exec(
"SET CLUSTER SETTING sql.stats.system_tables_autostats.enabled = false",
); err != nil {
t.Fatal(err)
}

// We also disable stats forecasts to have deterministic tests. See #97003
// for details.
Expand Down
8 changes: 2 additions & 6 deletions pkg/sql/opt/exec/execbuilder/testdata/explain_analyze
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,14 @@ regions: <hidden>
statement ok
GRANT SELECT ON crdb_internal.tables TO root;

# For some reason, even though we explicitly disable the automatic stats
# collection for both user and system tables, rarely we still see that the stats
# on system.privileges were collected, so we filter out a single line from the
# output to make the test deterministic.
query T
SELECT * FROM [EXPLAIN (VERBOSE) SELECT * FROM system.privileges WHERE path = 'vtable/crdb_internal/tables']
WHERE info NOT LIKE '%estimated row count%';
EXPLAIN (VERBOSE) SELECT * FROM system.privileges WHERE path = 'vtable/crdb_internal/tables'
----
distribution: local
vectorized: true
·
• scan
columns: (username, path, privileges, grant_options, user_id)
estimated row count: 10 (missing stats)
table: privileges@privileges_path_user_id_key
spans: /"vtable/crdb_internal/tables"-/"vtable/crdb_internal/tables"/PrefixEnd