Skip to content

Commit 7331b39

Browse files
craig[bot]mgartnerrickystewartajstorm
committed
158708: opt: route descriptor lookups for AFTER triggers through cache r=mgartner a=mgartner #### bench/rttananlysis: document directions for running tests These tests have a non-conventional construction that make it hard to determine how they can be run. Each subset of tests is not a typical Go function like `func TestAThing(t *testing.T) { ... }` that can be easily searched for. A few comments have been added to explain how the tests can be run. Release note: None #### bench/rttanalysis: add test case with an after trigger Release note: None #### opt: route descriptor lookups for AFTER triggers through cache This commit applies the fix in #144217 for `BEFORE` triggers to `AFTER` triggers. See that PR for more details. Fixes #144211 Release note (performance improvement): After triggers now perform the descriptor lookup for `TG_TABLE_SCHEMA` against a cache. This can significantly reduce trigger planning latency. #### opt: warn about performance of (*optCatalog).FullyQualifiedName Release note: None 158803: gen-cockroachdb-metrics: remove excessive logging r=rail,Abhinav1299 a=rickystewart This tool is unnecessarily noisy and always prints even when successful. Guard this behavior behind a --verbose command-line flag. Also use the `flag` library for command-line flags. Release note: none Epic: none 158899: ci: skip AI review for draft PRs r=rickystewart a=ajstorm ## Summary - Skip Claude Code PR Review workflow for draft PRs - Draft PRs are work-in-progress and not ready for review, so running AI review wastes resources - The workflow will still trigger when a PR is marked ready for review via the `ready_for_review` event Release note: None Epic: None 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Marcus Gartner <[email protected]> Co-authored-by: Ricky Stewart <[email protected]> Co-authored-by: Adam Storm <[email protected]>
4 parents f90025c + e01b2d3 + 34912a3 + bbaaaff commit 7331b39

File tree

7 files changed

+55
-23
lines changed

7 files changed

+55
-23
lines changed

.github/workflows/pr-analyzer-threestage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
claude-code-pr-review:
99
runs-on: ubuntu-latest
1010
timeout-minutes: 60
11-
if: "!startsWith(github.base_ref, 'release-') && !contains(github.event.pull_request.labels.*.name, 'O-No-AI-Review') && github.event.pull_request.merged == false"
11+
if: "!startsWith(github.base_ref, 'release-') && !contains(github.event.pull_request.labels.*.name, 'O-No-AI-Review') && !github.event.pull_request.merged && !github.event.pull_request.draft"
1212
permissions:
1313
contents: read
1414
pull-requests: write

build/tools/gen-cockroachdb-metrics/main.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
package main
3737

3838
import (
39+
"flag"
3940
"fmt"
4041
"io"
4142
"os"
@@ -106,6 +107,9 @@ var (
106107

107108
// Regex to convert CRDB metric names to Prometheus format
108109
prometheusNameRegex = regexp.MustCompile(`[^a-zA-Z0-9]`)
110+
111+
datadogOnly = flag.Bool("datadog-only", false, "generate metrics in datadog-only mode")
112+
verbose = flag.Bool("verbose", false, "print diagnostic logs")
109113
)
110114

111115
// YAML template for generating the cockroachdb_metrics.yaml file
@@ -458,20 +462,19 @@ func printUsage() {
458462
}
459463

460464
func main() {
461-
if len(os.Args) < 2 {
462-
printUsage()
463-
os.Exit(1)
464-
}
465+
flag.Parse()
465466

467+
args := flag.Args()
468+
466469
// Check if running in datadog-only mode
467-
if os.Args[1] == "--datadog-only" {
468-
if len(os.Args) < 4 {
470+
if *datadogOnly {
471+
if len(flag.Args()) < 2 {
469472
printUsage()
470473
os.Exit(1)
471474
}
472475

473-
datadogMappingsPath := os.Args[2]
474-
outputPath := os.Args[3]
476+
datadogMappingsPath := args[0]
477+
outputPath := args[1]
475478

476479
datadogMappings, err := loadDatadogMappings(datadogMappingsPath)
477480
if err != nil {
@@ -484,27 +487,27 @@ func main() {
484487
os.Exit(1)
485488
}
486489

487-
if !strings.Contains(outputPath, "-exec-") && !strings.Contains(outputPath, "for tool") {
490+
if *verbose {
488491
fmt.Printf("Generated %d raw Datadog metric mappings\n", len(datadogMappings))
489492
fmt.Printf("Output written to: %s\n", outputPath)
490493
}
491494
return
492495
}
493496

494497
// Normal mode: generate cockroachdb_metrics.yaml
495-
if len(os.Args) < 4 {
498+
if len(args) < 3 {
496499
printUsage()
497500
os.Exit(1)
498501
}
499502

500-
metricsYamlPath := os.Args[1]
501-
outputPath := os.Args[2]
502-
datadogMappingsPath := os.Args[3]
503+
metricsYamlPath := args[0]
504+
outputPath := args[1]
505+
datadogMappingsPath := args[2]
503506

504507
// Optional fourth argument: base YAML file with extra and legacy metrics
505508
basePath := ""
506-
if len(os.Args) >= 5 {
507-
basePath = os.Args[4]
509+
if len(args) >= 4 {
510+
basePath = args[3]
508511
}
509512

510513
datadogMappings, err := loadDatadogMappings(datadogMappingsPath)
@@ -534,9 +537,7 @@ func main() {
534537
os.Exit(1)
535538
}
536539

537-
// Only print summary if not in exec/tool configuration to avoid duplicate logs.
538-
// Bazel builds the tool in both target and exec configurations, causing duplicate output.
539-
if !strings.Contains(outputPath, "-exec-") && !strings.Contains(outputPath, "for tool") {
540+
if *verbose {
540541
fmt.Printf("Generated %d metric mappings:\n", len(finalMappings))
541542
fmt.Printf(" - %d from metrics.yaml\n", len(allMetrics)-len(baseMetrics.RuntimeConditionalMetrics))
542543
fmt.Printf(" - %d runtime conditional metrics\n", len(baseMetrics.RuntimeConditionalMetrics))

pkg/bench/rttanalysis/registry.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ import (
2424
// This structure facilitates a registry concept without needing to rename
2525
// existing benchmarks.
2626
//
27+
// All registered benchmark tests can be run with the command:
28+
//
29+
// ./dev test pkg/bench/rttanalysis -f TestBenchmarkExpectation
30+
//
31+
// A specific benchmark test can be run by adding its registered name as a suffix to the filter:
32+
//
33+
// ./dev test pkg/bench/rttanalysis -f TestBenchmarkExpectation/CreateRole
34+
//
2735
// The expectation is that there should be a single registry per package and
2836
// that tests are registered to it during initialization.
2937
type Registry struct {

pkg/bench/rttanalysis/testdata/benchmark_expectations

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ exp,benchmark
119119
1,SystemDatabaseQueries/select_system.users_with_empty_database_Name
120120
1,SystemDatabaseQueries/select_system.users_with_schema_Name
121121
1,SystemDatabaseQueries/select_system.users_without_schema_Name
122-
1,TriggerResolution/insert_into_table_with_trigger
122+
1,TriggerResolution/insert_into_table_with_before_trigger
123+
1,TriggerResolution/insert_into_table_with_after_trigger
123124
18,Truncate/truncate_1_column_0_rows
124125
17,Truncate/truncate_1_column_1_row
125126
17,Truncate/truncate_1_column_2_rows

pkg/bench/rttanalysis/trigger_resolution_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,32 @@ package rttanalysis
77

88
import "testing"
99

10+
// BenchmarkTriggerResolution benchmarks the KV round-trips taken to
11+
// execute statements with triggers.
12+
//
13+
// This benchmark can be run with the command:
14+
//
15+
// ./dev test pkg/bench/rttanalysis -f TestBenchmarkExpectation/TriggerResolution
1016
func BenchmarkTriggerResolution(b *testing.B) {
1117
reg.Run(b)
1218
}
1319
func init() {
1420
reg.Register("TriggerResolution", []RoundTripBenchTestCase{
1521
{
16-
Name: "insert into table with trigger",
22+
Name: "insert into table with before trigger",
1723
Setup: `
1824
CREATE TABLE trigger_table (a INT);
1925
CREATE FUNCTION trigger_fn() RETURNS TRIGGER LANGUAGE PLpgSQL AS $$ BEGIN RETURN NEW; END $$;
2026
CREATE TRIGGER tr BEFORE INSERT ON trigger_table FOR EACH ROW EXECUTE FUNCTION trigger_fn();`,
2127
Stmt: `INSERT INTO trigger_table VALUES (100);`,
2228
},
29+
{
30+
Name: "insert into table with after trigger",
31+
Setup: `
32+
CREATE TABLE trigger_table (a INT);
33+
CREATE FUNCTION trigger_fn() RETURNS TRIGGER LANGUAGE PLpgSQL AS $$ BEGIN RETURN NEW; END $$;
34+
CREATE TRIGGER tr AFTER INSERT ON trigger_table FOR EACH ROW EXECUTE FUNCTION trigger_fn();`,
35+
Stmt: `INSERT INTO trigger_table VALUES (100);`,
36+
},
2337
})
2438
}

pkg/sql/opt/optbuilder/trigger.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,13 @@ func (tb *rowLevelAfterTriggerBuilder) Build(
660660
tgLevel := tree.NewDString("ROW")
661661
tgRelID := tree.NewDOid(oid.Oid(tb.mutatedTable.ID()))
662662
tgTableName := tree.NewDString(string(tb.mutatedTable.Name()))
663-
fqName, err := b.catalog.FullyQualifiedName(ctx, tb.mutatedTable)
663+
schema, err := b.catalog.ResolveSchemaByID(
664+
b.ctx, cat.Flags{}, cat.StableID(tb.mutatedTable.GetSchemaID()),
665+
)
664666
if err != nil {
665667
panic(err)
666668
}
667-
tgTableSchema := tree.NewDString(fqName.Schema())
669+
tgTableSchema := tree.NewDString(schema.Name().Schema())
668670
var tgOp opt.ScalarExpr
669671
switch tb.mutation {
670672
case opt.InsertOp:

pkg/sql/opt_catalog.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ func (oc *optCatalog) UserHasGlobalPrivilegeOrRoleOption(
530530
}
531531

532532
// FullyQualifiedName is part of the cat.Catalog interface.
533+
//
534+
// Note that:
535+
// - this call may involve a database operation so it shouldn't be used in
536+
// performance sensitive paths;
537+
// - the fully qualified name of a data source object can change without the
538+
// object itself changing (e.g. when a database is renamed).
533539
func (oc *optCatalog) FullyQualifiedName(
534540
ctx context.Context, ds cat.DataSource,
535541
) (cat.DataSourceName, error) {

0 commit comments

Comments
 (0)