Skip to content

Commit 06e5d64

Browse files
committed
builtins: remove crdb_internal.reset_insights_tables
This commit removes the crdb_internal.reset_insights_tables builtin and its related interface method on the sql stats controller, as these tables are never populated. Epic: none Release note: None
1 parent 615456f commit 06e5d64

File tree

5 files changed

+2
-180
lines changed

5 files changed

+2
-180
lines changed

pkg/sql/sem/builtins/builtins.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7617,32 +7617,6 @@ table's zone configuration this will return NULL.`,
76177617
Volatility: volatility.Volatile,
76187618
},
76197619
),
7620-
"crdb_internal.reset_insights_tables": makeBuiltin(
7621-
tree.FunctionProperties{
7622-
Category: builtinconstants.CategorySystemInfo,
7623-
DistsqlBlocklist: true, // applicable only on the gateway
7624-
},
7625-
tree.Overload{
7626-
Types: tree.ParamTypes{},
7627-
ReturnType: tree.FixedReturnType(types.Bool),
7628-
Fn: func(ctx context.Context, evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) {
7629-
if err := evalCtx.SessionAccessor.CheckPrivilege(
7630-
ctx, syntheticprivilege.GlobalPrivilegeObject, privilege.REPAIRCLUSTER,
7631-
); err != nil {
7632-
return nil, err
7633-
}
7634-
if evalCtx.SQLStatsController == nil {
7635-
return nil, errors.AssertionFailedf("sql stats controller not set")
7636-
}
7637-
if err := evalCtx.SQLStatsController.ResetInsightsTables(ctx); err != nil {
7638-
return nil, err
7639-
}
7640-
return tree.MakeDBool(true), nil
7641-
},
7642-
Info: `This function is used to clear the statement and transaction insights statistics.`,
7643-
Volatility: volatility.Volatile,
7644-
},
7645-
),
76467620
// Deletes the underlying spans backing a table, only
76477621
// if the user provides explicit acknowledgement of the
76487622
// form "I acknowledge this will irrevocably delete all revisions

pkg/sql/sem/builtins/fixed_oids.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,8 @@ var builtinOidsArray = []string{
24702470
2507: `text(refcursor: refcursor) -> string`,
24712471
2508: `varchar(refcursor: refcursor) -> varchar`,
24722472
2509: `crdb_internal.unsafe_revert_tenant_to_timestamp(tenant_name: string, ts: decimal) -> decimal`,
2473-
2510: `crdb_internal.reset_insights_tables() -> bool`,
2473+
// Previously crdb_internal.reset_insights_tables() -> bool.
2474+
2510: ``,
24742475
2511: `merge_stats_metadata(arg1: jsonb) -> jsonb`,
24752476
2512: `merge_statement_stats(arg1: jsonb) -> jsonb`,
24762477
2513: `merge_transaction_stats(arg1: jsonb) -> jsonb`,

pkg/sql/sem/eval/deps.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ type GossipOperator interface {
711711
type SQLStatsController interface {
712712
ResetClusterSQLStats(ctx context.Context) error
713713
ResetActivityTables(ctx context.Context) error
714-
ResetInsightsTables(ctx context.Context) error
715714
CreateSQLStatsCompactionSchedule(ctx context.Context) error
716715
}
717716

pkg/sql/sqlstats/persistedsqlstats/controller.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ func (s *Controller) ResetActivityTables(ctx context.Context) error {
7878
return s.resetSysTableStats(ctx, "system.transaction_activity")
7979
}
8080

81-
// ResetInsightsTables implements the tree.SQLStatsController interface. This
82-
// method reset the {statement|transaction}_execution_insights tables.
83-
func (s *Controller) ResetInsightsTables(ctx context.Context) error {
84-
if err := s.resetSysTableStats(ctx, "system.statement_execution_insights"); err != nil {
85-
return err
86-
}
87-
88-
return s.resetSysTableStats(ctx, "system.transaction_execution_insights")
89-
}
90-
9181
func (s *Controller) resetSysTableStats(ctx context.Context, tableName string) (err error) {
9282
ex := s.db.Executor()
9383
_, err = ex.ExecEx(

pkg/sql/sqlstats/persistedsqlstats/controller_test.go

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -253,148 +253,6 @@ func TestActivityTablesReset(t *testing.T) {
253253
require.Equal(t, 0 /* expected */, count)
254254
}
255255

256-
func TestInsightsTablesReset(t *testing.T) {
257-
defer leaktest.AfterTest(t)()
258-
defer log.Scope(t).Close(t)
259-
260-
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{})
261-
sqlDB := sqlutils.MakeSQLRunner(db)
262-
defer s.Stopper().Stop(context.Background())
263-
264-
// Give the query runner privilege to insert into the insights tables.
265-
sqlDB.Exec(t, "INSERT INTO system.users VALUES ('node', NULL, true, 3)")
266-
sqlDB.Exec(t, "GRANT node TO root")
267-
268-
// Insert into system.statement_execution_insights table
269-
sqlDB.Exec(t, `
270-
INSERT INTO system.public.statement_execution_insights (
271-
session_id,
272-
transaction_id,
273-
transaction_fingerprint_id,
274-
statement_id,
275-
statement_fingerprint_id,
276-
problem,
277-
causes,
278-
query,
279-
status,
280-
start_time,
281-
end_time,
282-
full_scan,
283-
user_name,
284-
app_name,
285-
user_priority,
286-
database_name,
287-
plan_gist,
288-
retries,
289-
last_retry_reason,
290-
execution_node_ids,
291-
index_recommendations,
292-
implicit_txn,
293-
cpu_sql_nanos,
294-
error_code,
295-
contention_time,
296-
contention_info,
297-
details
298-
)
299-
VALUES (
300-
'178b8f4d507072200000000000000001',
301-
'14a07bbc-dfdb-41df-9231-b6235943847d',
302-
'\xd98ea7ce7040ab94',
303-
'178b8f50ab40d8680000000000000001',
304-
'\x125167e869920859',
305-
1,
306-
'{}',
307-
'SELECT a.balance, b.balance FROM insights_workload_table_0 AS a LEFT JOIN insights_workload_table_1 AS b ON a.shared_key = b.shared_key WHERE a.balance < _',
308-
1,
309-
'2023-10-06 15:47:41',
310-
'2023-10-06 15:47:42',
311-
't',
312-
'root',
313-
'insights_tables_reset',
314-
'normal',
315-
'insights',
316-
'AgHmAQIACgAAAAHkAQIACgAAAAMJAgICAAAFBAYE',
317-
0,
318-
null,
319-
'{}',
320-
'{"creation : CREATE INDEX ON insights.public.insights_workload_table_0 (balance) STORING (shared_key);"}',
321-
't',
322-
0,
323-
'XXUUU',
324-
null,
325-
null,
326-
'{}'
327-
)
328-
`)
329-
//Insert into system.transaction_execution_insights table
330-
sqlDB.Exec(t, `
331-
INSERT INTO system.public.transaction_execution_insights (
332-
session_id,
333-
transaction_id,
334-
transaction_fingerprint_id,
335-
stmt_execution_ids,
336-
problems,
337-
causes,
338-
query_summary,
339-
status,
340-
start_time,
341-
end_time,
342-
user_name,
343-
app_name,
344-
user_priority,
345-
retries,
346-
last_retry_reason,
347-
implicit_txn,
348-
cpu_sql_nanos,
349-
last_error_code,
350-
contention_time,
351-
contention_info,
352-
details
353-
354-
)
355-
VALUES (
356-
'178b8f4d507072200000000000000001',
357-
'14a07bbc-dfdb-41df-9231-b6235943847d',
358-
'\xd98ea7ce7040ab94',
359-
'{"178b8f50ab40d8680000000000000001"}',
360-
'{1}',
361-
'{}',
362-
'SELECT a.balance, b.balance FROM insights_workload_table_0 AS a LEFT JOIN insights_workload_table_1 AS b ON a.shared_key = b.shared_key WHERE a.balance < _',
363-
1,
364-
'2023-10-06 15:47:41',
365-
'2023-10-06 15:47:42',
366-
'root',
367-
'insights_tables_reset',
368-
'normal',
369-
0,
370-
null,
371-
't',
372-
0,
373-
'XXUUU',
374-
null,
375-
null,
376-
'{}'
377-
)
378-
`)
379-
380-
// Check that system.{statement|transaction}_execution_insights tables both have 1 row.
381-
var count int
382-
sqlDB.QueryRow(t, "SELECT count(*) FROM system.statement_execution_insights").Scan(&count)
383-
require.Equal(t, 1 /* expected */, count)
384-
385-
sqlDB.QueryRow(t, "SELECT count(*) FROM system.transaction_execution_insights").Scan(&count)
386-
require.Equal(t, 1 /* expected */, count)
387-
388-
// Flush the tables.
389-
sqlDB.QueryRow(t, "SELECT crdb_internal.reset_insights_tables()")
390-
391-
sqlDB.QueryRow(t, "SELECT count(*) FROM system.statement_execution_insights").Scan(&count)
392-
require.Equal(t, 0 /* expected */, count)
393-
394-
sqlDB.QueryRow(t, "SELECT count(*) FROM system.transaction_execution_insights").Scan(&count)
395-
require.Equal(t, 0 /* expected */, count)
396-
}
397-
398256
func TestStmtStatsEnable(t *testing.T) {
399257
defer leaktest.AfterTest(t)()
400258
defer log.Scope(t).Close(t)

0 commit comments

Comments
 (0)