Skip to content

Commit

Permalink
Merge pull request #103039 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.1-102021

release-23.1: sql: fix crdb_internal statment_activity and transaction_activity tables
  • Loading branch information
j82w authored May 10, 2023
2 parents 354a983 + e15a439 commit f66e662
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/observability
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ INSERT INTO system.users VALUES ('node', NULL, true, 3)
statement ok
GRANT node TO root

statement ok
SELECT * FROM crdb_internal.transaction_activity

statement ok
SELECT * FROM crdb_internal.statement_activity

# Upsert all transaction_activity
query T retry
EXPLAIN (VERBOSE) UPSERT INTO system.public.transaction_activity
Expand Down
22 changes: 22 additions & 0 deletions pkg/sql/sql_activity_update_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ func TestSqlActivityUpdateJob(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 0, count, "statement_statistics: expect:0, actual:%d", count)

row = db.QueryRowContext(ctx, "SELECT count_rows() FROM crdb_internal.transaction_activity")
err = row.Scan(&count)
require.NoError(t, err)
require.Equal(t, 0, count, "crdb_internal.transaction_activity: expect:0, actual:%d", count)

row = db.QueryRowContext(ctx, "SELECT count_rows() FROM crdb_internal.statement_activity")
err = row.Scan(&count)
require.NoError(t, err)
require.Equal(t, 0, count, "crdb_internal.statement_activity: expect:0, actual:%d", count)

execCfg := srv.ExecutorConfig().(ExecutorConfig)
st := cluster.MakeTestingClusterSettings()
updater := newSqlActivityUpdater(st, execCfg.InternalDB)
Expand Down Expand Up @@ -164,6 +174,18 @@ func TestSqlActivityUpdateJob(t *testing.T) {
err = row.Scan(&count)
require.NoError(t, err)
require.Equal(t, count, 1, "statement_activity after transfer: expect:1, actual:%d", count)

row = db.QueryRowContext(ctx, "SELECT count_rows() "+
"FROM crdb_internal.transaction_activity WHERE app_name = $1", appName)
err = row.Scan(&count)
require.NoError(t, err)
require.Equal(t, count, 1, "transaction_activity after transfer: expect:1, actual:%d", count)

row = db.QueryRowContext(ctx, "SELECT count_rows() "+
"FROM crdb_internal.statement_activity WHERE app_name = $1", appName)
err = row.Scan(&count)
require.NoError(t, err)
require.Equal(t, count, 1, "statement_activity after transfer: expect:1, actual:%d", count)
}

// TestSqlActivityUpdateJob verifies that the
Expand Down

0 comments on commit f66e662

Please sign in to comment.