Skip to content

Commit

Permalink
sql: fix crdb_internal statment_activity and transaction_activity tables
Browse files Browse the repository at this point in the history
The virtual table is selecting the wrong columns from the system
table causing it to fail. This fixes the column names and adds tests.

Release note: None
Part of #98882
Epic: None
  • Loading branch information
j82w committed Apr 21, 2023
1 parent a0a3b07 commit e15a439
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 e15a439

Please sign in to comment.