Skip to content

Commit f904a99

Browse files
craig[bot]OriSavir
andcommitted
Merge #148403
148403: rttanalysis: add benchmarks for `SHOW CREATE ALL TRIGGERS` r=OriSavir a=OriSavir There were previously no benchmarks to confirm the performance of `SHOW CREATE ALL TRIGGERS` queries. It is important to have these benchmarks, particularly as the virtual table for create trigger statements is indexed by TableID, and a benchmark could help to confirm that the index helps performance in some sense. Epic: CRDB-49582 Release note: None Co-authored-by: Oriel Savir <[email protected]>
2 parents 449f097 + 42b4279 commit f904a99

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

pkg/bench/rttanalysis/orm_queries_bench_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,30 @@ func buildNFunctions(n int) string {
10351035
return b.String()
10361036
}
10371037

1038+
func buildNTablesWithTriggers(n int) string {
1039+
b := strings.Builder{}
1040+
b.WriteString(`
1041+
CREATE OR REPLACE FUNCTION trigger_func()
1042+
RETURNS TRIGGER AS $$
1043+
BEGIN
1044+
RAISE NOTICE 'Trigger fired for NEW row: %', NEW;
1045+
RETURN NEW;
1046+
END;
1047+
$$ LANGUAGE plpgsql;
1048+
`)
1049+
for i := 0; i < n; i++ {
1050+
b.WriteString(fmt.Sprintf(`
1051+
CREATE TABLE t%d (a INT, b INT);
1052+
1053+
CREATE TRIGGER trigger_%d
1054+
AFTER INSERT ON t%d
1055+
FOR EACH ROW
1056+
EXECUTE FUNCTION trigger_func();
1057+
`, i, i, i))
1058+
}
1059+
return b.String()
1060+
}
1061+
10381062
func buildNTypes(n int) string {
10391063
b := strings.Builder{}
10401064
for i := 0; i < n; i++ {

pkg/bench/rttanalysis/testdata/benchmark_expectations

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,6 @@ exp,benchmark
132132
1,VirtualTableQueries/select_crdb_internal.invalid_objects_with_1_fk
133133
1,VirtualTableQueries/select_crdb_internal.tables_with_1_fk
134134
0,VirtualTableQueries/show_create_all_routines
135+
0,VirtualTableQueries/show_create_all_triggers
135136
5,VirtualTableQueries/virtual_table_cache_with_point_lookups
136137
10,VirtualTableQueries/virtual_table_cache_with_schema_change

pkg/bench/rttanalysis/virtual_table_bench_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ SELECT * FROM t2;`,
6666
{
6767
Name: "show_create_all_routines",
6868
Setup: buildNFunctions(100),
69-
Stmt: `SHOW CREATE ALL ROUTINES`,
69+
Stmt: `SHOW CREATE ALL ROUTINES;`,
70+
},
71+
// This test checks the performance of the crdb_internal virtual tables used by
72+
// SHOW CREATE ALL TRIGGERS.
73+
{
74+
Name: "show_create_all_triggers",
75+
Setup: buildNTablesWithTriggers(100),
76+
Stmt: `SHOW CREATE ALL TRIGGERS;`,
7077
},
7178
})
7279
}

pkg/sql/sem/builtins/show_create_all_triggers_builtin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type tableTriggerPair struct {
2626

2727
func getTriggerIds(
2828
ctx context.Context, evalPlanner eval.Planner, txn *kv.Txn, dbName string, acc *mon.BoundAccount,
29-
) (triggerIds []tableTriggerPair, retErr error) { //TODO: Check up on ID field names etc
29+
) (triggerIds []tableTriggerPair, retErr error) {
3030
query := fmt.Sprintf(`
3131
SELECT trigger_id, table_id
3232
FROM %s.crdb_internal.create_trigger_statements

0 commit comments

Comments
 (0)