Get-DbaHelpIndex - Bad joins based on Index Name instead of Index ID when Indexes in same DB named the same #9447 #9473
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.
Type of Change
.\tests\manual.pester.ps1
)Purpose
Fix #9447
Approach
Changed the sql code by adding a new where condition
Added a new unit test
Commands to test
.\tests\manual.pester.ps1 -Path .\tests\Get-DbaHelpIndex.Tests.ps1 -TestIntegration
The original function will fail the following new unit test.
Context Result is correct for tables having the indexes with the same names
[+] Table t1 has correct index key columns and included columns 7ms
[+] Table t2 has correct index key columns and included columns 12ms
Screenshots
Here is a simple reproducible test.
create a test database with tables having an index each with the same name.
create database test1;
go
use test1;
go
create table t1(c1 int,c2 int,c3 int,c4 int);
create nonclustered index idx_1 on t1(c1) include(c3);
create table t2(c1 int,c2 int,c3 int,c4 int);
create nonclustered index idx_1 on t2(c1,c2) include(c3,c4);
go
Run get-dbahelpindex to check.
For example:
get-dbahelpindex -sqlinstance 'localhost,14330' -database test1|out-gridview
The existing version returns the following result, which is wrong for both tables.
The proposed version returns the following result, which is correct.
Learning