-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: do not consider TCL stmts in sql stats tracing #138041
Conversation
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. |
443406e
to
6da47a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! LGTM
pkg/sql/instrumentation_test.go
Outdated
@@ -251,10 +252,11 @@ func TestSampledStatsCollectionOnNewFingerprint(t *testing.T) { | |||
|
|||
require.Equal(t, len(queries), len(collectedTxnStats)) | |||
|
|||
// We should have collected stats for each of the queries. | |||
for i := range collectedTxnStats { | |||
// We should have collected stats for each of the first 4 queries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe change this to "each of the queries, except the last" or something, since more queries could be added in the future
For SQL stats we trace every new fingerprint in an application container in order to populate statistics that are only available via tracing for each fingerprint. This sampling logic worked by tracking the SQL fingerprint strings encountered by each application but did not factor in fingerprints that are not tracked by SQL stats, such as TCL statements (BEGIN, COMMIT, ROLLBACK), were being treated as new fingerprints on each execution which resulted in tracing being turned on. This commit ensures that we don't consider TCL statements in this sampling strategy. TestSampledStatsCollectionOnNewFingerprint is also fixed as it was assuming that previously seen statements in new transactions would trigger this sampling behaviour when it should not - this was being erronneously triggered by `BEGIN`. ``` name old time/op new time/op delta Sysbench/SQL/3node/oltp_read_write-10 5.61ms ± 3% 5.69ms ± 4% ~ (p=0.167 n=8+9) name old alloc/op new alloc/op delta Sysbench/SQL/3node/oltp_read_write-10 2.15MB ± 2% 2.12MB ± 2% -1.24% (p=0.029 n=10+10) name old allocs/op new allocs/op delta Sysbench/SQL/3node/oltp_read_write-10 10.7k ± 1% 10.5k ± 0% -1.69% (p=0.000 n=10+9) ``` Epic: none Part of: cockroachdb#133307 Release note: None
6da47a8
to
8f86503
Compare
TFTR! |
Nice, thank you! |
For SQL stats we trace every new fingerprint in an application
container in order to populate statistics that are only available
via tracing for each fingerprint. This sampling logic worked by
tracking the SQL fingerprint strings encountered by each application
but did not factor in fingerprints that are not tracked by SQL stats,
such as TCL statements (BEGIN, COMMIT, ROLLBACK), were being treated
as new fingerprints on each execution which resulted in tracing being
turned on. This commit ensures that we don't consider TCL statements
in this sampling strategy. TestSampledStatsCollectionOnNewFingerprint
is also fixed as it was assuming that previously seen statements in
new transactions would trigger this sampling behaviour when it should
not - this was being erronneously triggered by
BEGIN
.Epic: none
Part of: #133307
Release note: None