Skip to content

Conversation

@kyle-a-wong
Copy link
Contributor

@kyle-a-wong kyle-a-wong commented Nov 5, 2025

commit 1/2

sql,*: record UDF stats
Updates the UDF routine generators to pass down
the necessary information in order to generate
and record RecordedStmtStats structs

Epic: CRDB-55081
Release note: None


commit 2/2

sql: Add latency recordings to udf sub statement calls
Adds RoutineStatementLatencyRecorder struct that implements
sqlstats.StatementLatencyRecorder. Now statement latencies
are recorded

Epic: CRDB-55081
Release note: None


note this is a stacked PR, so only the last 2 commits need to be reviewed

@blathers-crl
Copy link

blathers-crl bot commented Nov 5, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@cockroach-teamcity
Copy link
Member

🔴 Sysbench [SQL, 3node, oltp_read_write]
Metric Old Commit New Commit Delta Note
sec/op 10.95m ±2% 11.03m ±2% ~ p=0.486 n=15
🔴 allocs/op 8.122k ±2% 8.182k ±2% +0.74% p=0.019 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/90c89be/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/90c89be2b2b315abae3bf254c0aeb79a9e67b0f6/bin/pkg_sql_tests benchdiff/90c89be/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/90c89be/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/SQL/3node/oltp_read_write$ --old=d669516 --new=90c89be ./pkg/sql/tests
⚪ Sysbench [KV, 3node, oltp_read_only]
Metric Old Commit New Commit Delta Note
sec/op 3.281m ±1% 3.299m ±1% ~ p=0.074 n=15
allocs/op 2.080k ±0% 2.081k ±0% ~ p=0.198 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/90c89be/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/90c89be2b2b315abae3bf254c0aeb79a9e67b0f6/bin/pkg_sql_tests benchdiff/90c89be/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/90c89be/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/3node/oltp_read_only$ --old=d669516 --new=90c89be ./pkg/sql/tests
⚪ Sysbench [KV, 3node, oltp_write_only]
Metric Old Commit New Commit Delta Note
sec/op 3.568m ±0% 3.575m ±0% ~ p=0.250 n=15
allocs/op 4.195k ±0% 4.196k ±0% ~ p=0.390 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/90c89be/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/90c89be2b2b315abae3bf254c0aeb79a9e67b0f6/bin/pkg_sql_tests benchdiff/90c89be/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/90c89be/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/3node/oltp_write_only$ --old=d669516 --new=90c89be ./pkg/sql/tests
Artifacts

download:

mkdir -p new
gcloud storage cp gs://cockroach-microbench-ci/artifacts/90c89be2b2b315abae3bf254c0aeb79a9e67b0f6/19086808714-1/\* new/
mkdir -p old
gcloud storage cp gs://cockroach-microbench-ci/artifacts/d6695166a4ec91179d1e48cf31c3d821cac6d955/19086808714-1/\* old/

built with commit: 90c89be2b2b315abae3bf254c0aeb79a9e67b0f6

@cockroach-teamcity cockroach-teamcity added the X-perf-check Microbenchmarks CI: Added to a PR if a performance regression is detected and should be checked label Nov 5, 2025
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Potential Bug(s) Detected

The three-stage Claude Code analysis has identified potential bug(s) in this PR that may warrant investigation.

Next Steps:
Please review the detailed findings in the workflow run.

Note: When viewing the workflow output, scroll to the bottom to find the Final Analysis Summary.

After you review the findings, please tag the issue as follows:

  • If the detected issue is real or was helpful in any way, please tag the issue with O-AI-Review-Real-Issue-Found
  • If the detected issue was not helpful in any way, please tag the issue with O-AI-Review-Not-Helpful

@github-actions github-actions bot added the o-AI-Review-Potential-Issue-Detected AI reviewer found potential issue. Never assign manually—auto-applied by GH action only. label Nov 5, 2025
A new RecordedStatementStatsBuilder was added to the sql package to make building a RecordedStmtStats struct easier.

New interfaces were also added to sqlstats to make make building RecordedStmtStats easier.

These new interfaces and builders should help to decouple Recording statement stats from the conn executor, allowing them to be recorded in other places as well

Epic: CRDB-55081
Release note: None
@cockroach-teamcity
Copy link
Member

⚪ Sysbench [SQL, 3node, oltp_read_write]
Metric Old Commit New Commit Delta Note
sec/op 11.54m ±2% 11.60m ±3% ~ p=0.486 n=15
allocs/op 8.246k ±1% 8.257k ±0% ~ p=0.036 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/6be68d3/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/6be68d3ebb8d8a2e17b6fe8709722dbbd4c1580c/bin/pkg_sql_tests benchdiff/6be68d3/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/6be68d3/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/SQL/3node/oltp_read_write$ --old=d669516 --new=6be68d3 ./pkg/sql/tests
⚪ Sysbench [KV, 3node, oltp_read_only]
Metric Old Commit New Commit Delta Note
sec/op 3.331m ±1% 3.325m ±0% ~ p=0.512 n=15
allocs/op 2.081k ±0% 2.080k ±0% ~ p=0.805 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/6be68d3/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/6be68d3ebb8d8a2e17b6fe8709722dbbd4c1580c/bin/pkg_sql_tests benchdiff/6be68d3/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/6be68d3/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/3node/oltp_read_only$ --old=d669516 --new=6be68d3 ./pkg/sql/tests
⚪ Sysbench [KV, 3node, oltp_write_only]
Metric Old Commit New Commit Delta Note
sec/op 3.617m ±0% 3.599m ±1% ~ p=0.539 n=15
allocs/op 4.191k ±0% 4.192k ±0% ~ p=0.659 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/6be68d3/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/6be68d3ebb8d8a2e17b6fe8709722dbbd4c1580c/bin/pkg_sql_tests benchdiff/6be68d3/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/6be68d3/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/3node/oltp_write_only$ --old=d669516 --new=6be68d3 ./pkg/sql/tests
Artifacts

download:

mkdir -p new
gcloud storage cp gs://cockroach-microbench-ci/artifacts/6be68d3ebb8d8a2e17b6fe8709722dbbd4c1580c/19111167798-1/\* new/
mkdir -p old
gcloud storage cp gs://cockroach-microbench-ci/artifacts/d6695166a4ec91179d1e48cf31c3d821cac6d955/19111167798-1/\* old/

built with commit: 6be68d3ebb8d8a2e17b6fe8709722dbbd4c1580c

@cockroach-teamcity
Copy link
Member

⚪ Sysbench [SQL, 3node, oltp_read_write]
Metric Old Commit New Commit Delta Note
sec/op 11.52m ±1% 11.48m ±1% ~ p=0.233 n=15
allocs/op 8.259k ±0% 8.251k ±0% ~ p=0.228 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/27aa535/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/27aa535f2caf971d0cbd53ff76f04af4b8a69b87/bin/pkg_sql_tests benchdiff/27aa535/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/27aa535/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/SQL/3node/oltp_read_write$ --old=d669516 --new=27aa535 ./pkg/sql/tests
⚪ Sysbench [KV, 3node, oltp_read_only]
Metric Old Commit New Commit Delta Note
sec/op 3.418m ±1% 3.409m ±1% ~ p=0.595 n=15
allocs/op 2.081k ±0% 2.080k ±0% ~ p=0.048 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/27aa535/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/27aa535f2caf971d0cbd53ff76f04af4b8a69b87/bin/pkg_sql_tests benchdiff/27aa535/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/27aa535/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/3node/oltp_read_only$ --old=d669516 --new=27aa535 ./pkg/sql/tests
⚪ Sysbench [KV, 3node, oltp_write_only]
Metric Old Commit New Commit Delta Note
sec/op 3.670m ±2% 3.654m ±2% ~ p=0.325 n=15
allocs/op 4.188k ±0% 4.188k ±0% ~ p=0.767 n=15
Reproduce

benchdiff binaries:

mkdir -p benchdiff/27aa535/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/27aa535f2caf971d0cbd53ff76f04af4b8a69b87/bin/pkg_sql_tests benchdiff/27aa535/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/27aa535/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
mkdir -p benchdiff/d669516/bin/1058449141
gcloud storage cp gs://cockroach-microbench-ci/builds/d6695166a4ec91179d1e48cf31c3d821cac6d955/bin/pkg_sql_tests benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests
chmod +x benchdiff/d669516/bin/1058449141/cockroachdb_cockroach_pkg_sql_tests

benchdiff command:

benchdiff --run=^BenchmarkSysbench/KV/3node/oltp_write_only$ --old=d669516 --new=27aa535 ./pkg/sql/tests
Artifacts

download:

mkdir -p new
gcloud storage cp gs://cockroach-microbench-ci/artifacts/27aa535f2caf971d0cbd53ff76f04af4b8a69b87/19115259300-1/\* new/
mkdir -p old
gcloud storage cp gs://cockroach-microbench-ci/artifacts/d6695166a4ec91179d1e48cf31c3d821cac6d955/19115259300-1/\* old/

built with commit: 27aa535f2caf971d0cbd53ff76f04af4b8a69b87

@kyle-a-wong kyle-a-wong removed the X-perf-check Microbenchmarks CI: Added to a PR if a performance regression is detected and should be checked label Nov 5, 2025
Updates the UDF routine generators to pass down
the necessary information in order to generate
and record RecordedStmtStats structs

Epic: CRDB-55081
Release note: None
Adds RoutineStatementLatencyRecorder struct that implements
sqlstats.StatementLatencyRecorder. Now statement latencies
are recorded

Epic: CRDB-55081
Release note: None
@kyle-a-wong kyle-a-wong changed the title Udf sql stats sql: Record statement stats for statements executed in UDFs / SPs Nov 5, 2025
Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgartner reviewed 2 of 8 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball and @michae2)


-- commits line 8 at r1:
nit: break commit lines at 80 characters https://cockroachlabs.atlassian.net/wiki/spaces/CRDB/pages/73072807/Git+Commit+Messages


pkg/sql/sqlstats/ssprovider.go line 179 at r1 (raw file):

}

func NewRecordedStatementStatsBuilder[L StatementLatencyRecorder, Q QueryStats, P PlanInfo](

I like the idea of cleaning up and narrowing the API. This use of interfaces and generics might be over-complicating things, though. Could this all be replaced by a struct(s) and a constructor(s) defined in the sqlstats package and a function(s) in the sql package to call those constructors with the data it has gathered from it's sources? What are the pros/cons of a simpler design?

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball, @kyle-a-wong, and @michae2)


-- commits line 18 at r2:
nit: end sentence with a period


pkg/sql/routine.go line 386 at r2 (raw file):

					stmt.StmtType, stmt.AppName,
					PlanInfo{
						planFlags: g.p.curPlan.flags, // TODO: Is this right?

I don't think this is right. g.p is the top-level planner. It is copied inside runPlanInsidePlan and the copy is given a new curPlan representing the routine. We'll need to access that plan's flags, which should be plan.(*planComponents).flags.


pkg/sql/sem/tree/routine.go line 40 at r2 (raw file):

	AppName        string
	FingerprintId  uint64
}

I don't understand the need to pass all this information into the routine execution code, just to construct a builder there. It looks like we only need to attach plan flags and record the statement within execution. Can we instead pass a pointer to a struct that has all this information already, and call a method to attach the plan flags and record the statement? Another option would be passing a closure recordStats func(flags planFlags) that the routine execution code can call with the generated plan flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

o-AI-Review-Potential-Issue-Detected AI reviewer found potential issue. Never assign manually—auto-applied by GH action only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants