Skip to content

sp_IndexCleanup: fix #721 unique constraint subset + replace ISNULL schema join#722

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/indexcleanup-uc-subset-and-schema-join
Mar 25, 2026
Merged

sp_IndexCleanup: fix #721 unique constraint subset + replace ISNULL schema join#722
erikdarlingdata merged 1 commit intodevfrom
fix/indexcleanup-uc-subset-and-schema-join

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Summary

Bug fix (#721): Unique constraints can now serve as the superset target in Key Subset detection. Previously both sides were excluded from the rule, so a NC index with keys that were a prefix of a UC's keys was never flagged.

Schema join: Replaced LEFT JOIN sys.tables + LEFT JOIN sys.views + ISNULL(t.schema_id, v.schema_id) with JOIN sys.objects in all 4 query locations. Eliminates non-SARGable predicate.

Test plan

Closes #721

🤖 Generated with Claude Code

…ULL schema join

Issue #721: Unique constraints were excluded from both sides of the
Key Subset rule, so a NC index that was a prefix of a UC's keys was
never flagged. Removed the NOT EXISTS check on the wider (target) side
so UCs can serve as the superset target. The narrower-side check stays
to prevent disabling UCs themselves.

Schema join: Replaced LEFT JOIN sys.tables + LEFT JOIN sys.views +
ISNULL(t.schema_id, v.schema_id) with a single JOIN sys.objects in
all 4 query locations. Eliminates the non-SARGable ISNULL predicate
that caused late filtering in the optimizer.

Also scoped #usage_stats staging to #filtered_objects.

Tested on SQL2022 (repro from #721 confirmed fixed) and SQL2016.

Closes #721

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit c05bce1 into dev Mar 25, 2026
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.

1 participant