BUG in usp_AdaptiveIndexDefrag: When dbScope is set, a new scan is done every time.
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
Research direction
Start by locating usp_AdaptiveIndexDefrag and the scope-check query referencing dbo.tbl_AdaptiveIndexDefrag_Working and dbo.tbl_AdaptiveIndexDefrag_Stats_Working. Compare the quoted @dbScope value with the database-name values used in the NOT IN subquery. Done means a scoped database does not trigger a rescan on every execution, while forced rescans still behave as intended.
Written by the indexing model from the issue text.
Description
In this piece of code, the query checks if the QUOTED dbScope is NOT in the list of UNQUOTED dbNames that are in the dbo.tbl_AdaptiveIndexDefrag_Working or dbo.tbl_AdaptiveIndexDefrag_Stats_Working tables, and of cause this will never be true. The effect is the
script does a rescan whenever you set the @dbScope parameter.
/* Check if database scope has changed, if rescan is not being forced */
IF @forceRescan = 0 AND @dbScope IS NOT NULL -- Specific scope was set
BEGIN
IF (SELECT COUNT(DISTINCT [dbID]) FROM dbo.tbl_AdaptiveIndexDefrag_Working) > 1
OR **QUOTENAME(LOWER(@dbScope)) NOT IN (SELECT DISTINCT LOWER([dbName]) FROM dbo.tbl_AdaptiveIndexDefrag_Working UNION SELECT DISTINCT LOWER(dbName) FROM dbo.tbl_AdaptiveIndexDefrag_Stats_Working**)
BEGIN
SET @forceRescan = 1
RAISERROR('Scope has changed. Forcing rescan of single database in scope...', 0, 42) WITH NOWAIT;
END;
END;
Suggested fix: add Quotename to the selects in the NOT IN () term:
QUOTENAME(LOWER(@dbScope)) NOT IN (SELECT DISTINCT QUOTENAME(LOWER([dbName])) FROM dbo.tbl_AdaptiveIndexDefrag_Working UNION SELECT DISTINCT QUOTENAME(LOWER(dbName)) FROM dbo.tbl_AdaptiveIndexDefrag_Stats_Working)
BEGIN
- Dominant language
- Jupyter Notebook
- Stars
- 1.6k
- Forks
- 749
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/tigertoolbox
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
microsoft/tigertoolbox#199 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
microsoft/tigertoolbox#319 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
microsoft/tigertoolbox#312 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
microsoft/tigertoolbox#311 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
microsoft/tigertoolbox#307 ·
All issues in microsoft/tigertoolbox
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
OpenLiberty/open-liberty#35839 ·
-
affects-9.0 found-by-ai may-affects-25.10 may-affects-26.3 may-affects-26.9 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
antlr/grammars-v4#5014 · 1 comment ·
-
comp-query-execution fuzz
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121303 · 3 comments ·