Skip to content

sql/contention: add blocking statement to contention event tables#172178

Closed
parkerswy wants to merge 2 commits into
cockroachdb:masterfrom
parkerswy:branching-stmt-fingerprint-id
Closed

sql/contention: add blocking statement to contention event tables#172178
parkerswy wants to merge 2 commits into
cockroachdb:masterfrom
parkerswy:branching-stmt-fingerprint-id

Conversation

@parkerswy

Copy link
Copy Markdown

The contention event tables identify the blocking transaction (txn_id) but not the statement within that transaction that held the lock. This plumbs a blocking statement fingerprint through to the transaction contention event surface.

Plumbing only:

  • Adds blocking_stmt_fingerprint_id to the ContentionEvent proto.
  • Adds a blocking_stmt_fingerprint_id column to crdb_internal.transaction_contention_events.

Epic: CRDB-65143
Fixes: #172008
Release note: None

The contention event tables identify the blocking transaction (txn_id) but
not the statement within that transaction that held the lock. This plumbs a
blocking statement fingerprint through to the transaction contention event
surface.

Plumbing only:
- Adds `blocking_stmt_fingerprint_id` to the `ContentionEvent` proto.
- Adds a `blocking_stmt_fingerprint_id` column to
  `crdb_internal.transaction_contention_events`.

Epic: CRDB-65143
Fixes: cockroachdb#172008
Release note: None
@parkerswy parkerswy requested review from a team as code owners July 1, 2026 19:48
@parkerswy parkerswy requested review from angles-n-daemons, himanshu-shrivastava-crl and kyle-a-wong and removed request for a team July 1, 2026 19:48
@parkerswy parkerswy requested a review from dhartunian July 1, 2026 20:36
@parkerswy parkerswy closed this Jul 1, 2026

@kyle-a-wong kyle-a-wong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that you have a second commit to fix some lint issues. Typically we want commits in a PR to land as atomically, so if there is a bug, lint error, etc., you should fix that commit instead of creating a new commit on top of it to fix it. To do this, you would make the fix, and then do a git commit --amend, which amends the staged changes to the HEAD of your branch. One thing to note about this is that it replaces the old commit, so doing a git push fork branching-stmt-fingerprint-id will be rejected and you will need to do a force push (include the -f flag.

expected gosql.NullString
}{
{
name: "non-null",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: lets name these something like "blocking_stmt_fingerprint_not_exists" and "blocking_stmt_fingerprint_exists"

Comment on lines +1934 to +1936
srv, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{
DefaultTestTenant: base.TestIsSpecificToStorageLayerAndNeedsASystemTenant,
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: im not sure if this DefaultTestTenant is needed. I think you can just do serverutils.StartServer(t, base.TestServerArgs{})

Comment thread pkg/sql/crdb_internal.go
tree.DBytes(sqlstatsutil.EncodeUint64ToBytes(uint64(resp.Events[i].BlockingTxnFingerprintID))))

blockingStmtFingerprintID := tree.DNull
if resp.Events[i].BlockingEvent.BlockingStmtFingerprintID != 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: you can pull this out into a variable to make the if block a little more readable

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql/contention: add blocking statement to contention event tables

2 participants