microsoft / microsoft/sqlmanagementobjects

Obtaining Table SMO object causes table scan to be recorded

Open
#151 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
143
Forks
28
PR merge metrics
No merged PRs in 30d

Description

I'm not sure what the fix is here, but, that CASE statement does not short-circuit. Even if the IF condition is true, it still executes the subquery in the ELSE clause.

This means a table scan on one of the indexes (or heap) is recorded.

In most cases, this is probably not a big deal...but if you're using SMO objects to create backup scripts for unused indexes you are getting ready to drop...it's kind of a problem when all of a sudden SMO starts using those unused indexes, causing them to be excluded from the unused index detection queries.

https://github.com/microsoft/sqlmanagementobjects/blob/d6f3e68fe6fae09d22355a160baa525d8032fd64/src/Microsoft/SqlServer/Management/SqlEnum/PostProcessTable.cs#L81-L83

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Microsoft/SqlServer/Management/SqlEnum/PostProcessTable.cs around lines 81-83 and inspect the query path used when obtaining a Table SMO object. Reproduce or trace the table-scan recording behavior, then verify that unused-index detection no longer treats this metadata lookup as index usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.