Skip to content

Commit

Permalink
sql: fix TestCreateStatisticsCanBeCancelled hang
Browse files Browse the repository at this point in the history
Previously, this test could hang if there was an automatic
stats came in concurrently with a manual stats collection,
where the request filter would end up hanging and being called twice.
To address this patch will disable automatic stats collections
on the table.

Fixes: cockroachdb#109007
Release note: None
  • Loading branch information
fqazi committed Aug 18, 2023
1 parent 104ed81 commit 4cef84b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/sql/stats/create_stats_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ func TestCreateStatisticsCanBeCancelled(t *testing.T) {
sqlDB := sqlutils.MakeSQLRunner(conn)

sqlDB.Exec(t, `CREATE DATABASE d`)
sqlDB.Exec(t, `CREATE TABLE d.t (x INT PRIMARY KEY)`)
sqlDB.Exec(t, `CREATE TABLE d.t (x INT PRIMARY KEY) WITH (sql_stats_automatic_collection_enabled = false)`)
sqlDB.Exec(t, `INSERT INTO d.t SELECT generate_series(1,1000)`)
var tID descpb.ID
sqlDB.QueryRow(t, `SELECT 'd.t'::regclass::int`).Scan(&tID)
setTableID(tID)

// Run CREATE STATISTICS and wait for to create the job.
allowRequest = make(chan struct{})
Expand All @@ -159,6 +158,9 @@ func TestCreateStatisticsCanBeCancelled(t *testing.T) {
errCh <- err
}()
allowRequest <- struct{}{}
// If we end up ever retrying the txn, we should not block on
// the allow request channel again.
setTableID(descpb.InvalidID)
testutils.SucceedsSoon(t, func() error {
row := conn.QueryRow("SELECT query_id FROM [SHOW CLUSTER STATEMENTS] WHERE query LIKE 'CREATE STATISTICS%';")
var queryID string
Expand Down Expand Up @@ -214,7 +216,6 @@ func TestAtMostOneRunningCreateStats(t *testing.T) {
case err := <-errCh:
t.Fatal(err)
}

autoStatsRunShouldFail := func() {
_, err := conn.Exec(`CREATE STATISTICS __auto__ FROM d.t`)
expected := "another CREATE STATISTICS job is already running"
Expand Down

0 comments on commit 4cef84b

Please sign in to comment.