sp_HumanEventsBlockViewer: resolve the contended object from wait_resource#812
Merged
Merged
Conversation
…ource
contentious_object was ~99% "Unresolved: ... object_id: N" because it resolved
OBJECT_NAME() against the blocked_process_report event's object_id field, which is
unreliable for KEY/PAGE/RID lock waits (it reports 0 or a non-object id). Decode the
lock resource string instead:
KEY -> hobt_id via [db].sys.partitions -> object_id (per contended database)
OBJECT -> object_id directly
PAGE/RID -> sys.dm_db_page_info (2019+, VIEW DATABASE STATE) -> object_id
Non-object locks (DATABASE / XACT / METADATA / ...) and anything that can't resolve
keep the "Unresolved" sentinel the findings + output logic depends on. Resolved values
stay plain schema.object so the @object_name filter still matches. The event object_id
is kept as a COALESCE fallback so nothing that resolved before regresses.
Adds @product_version (PARSENAME of ProductVersion, matching the QuickieStore idiom) to
gate dm_db_page_info; cross-db lookups are per-database dynamic SQL (QUOTENAME'd,
parameterized via sp_executesql), guarded by DB-online checks and TRY/CATCH for the
page-info permission. Compound waitresources ("XACT: ... KEY: ...") resolve off the
embedded KEY/PAGE token. TRY_CONVERT makes the string parse unthrowable.
Validated on SQL Server 2025 (HammerDB workload): contentious_object resolution ~0.3%
-> ~97% on the full history; end-to-end through the proc, KEY locks resolve to
dbo.district / new_order / order_line / customer, PAGE locks that can't resolve are
labeled honestly.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
contentious_objectwas ~99%"Unresolved: ... object_id: N"because it resolvedOBJECT_NAME()against the blocked-process-report event'sobject_idfield, which is unreliable for KEY/PAGE/RID lock waits (reports 0 or a non-object id). This decodes the lock resource fromwait_resourceinstead:hobt_idvia[db].sys.partitions->object_id(per contended database, dynamic SQL)object_iddirectlysys.dm_db_page_info(2019+ or Azure SQL DB;VIEW DATABASE STATE) ->object_idNon-object locks (DATABASE / XACT / METADATA / ...) and anything that can't resolve keep the
Unresolvedsentinel the findings + output logic depends on. Resolved values stay plainschema.objectso the@object_namefilter still matches. The eventobject_idis kept as aCOALESCEfallback so nothing that resolved before regresses. Compound waitresources (XACT: ... KEY: ...) resolve off the embedded token.Adds
@product_version(PARSENAME of ProductVersion, matching the QuickieStore idiom) to gatedm_db_page_info; cross-db lookups are per-database dynamic SQL (QUOTENAME'd, parameterized viasp_executesql, withTRY/CATCHfor the page-info permission and DB-online guards).TRY_CONVERTmakes the string parse unthrowable;lock_typeisvarchar(32)so long resource tokens (APPLICATION / ALLOCATION_UNIT) can't overflow.Validated on SQL Server 2025 (HammerDB):
contentious_objectresolution ~0.3% -> ~97% on the full history; end-to-end, KEY locks resolve todbo.district/new_order/order_line/customer, unresolvable PAGE/non-object locks labeled honestly.Known follow-up (not in this change): the
bpr_with_leadchain-lead rollup still derivescontentious_objectfrom the eventobject_idfor its@object_namefilter -- moot unless@object_nameis explicitly passed, and not a regression.🤖 Generated with Claude Code