Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore hypothetical indexes (now with test!) #20707

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ FROM [sys].[indexes] AS [i]
JOIN [sys].[tables] AS [t] ON [i].[object_id] = [t].[object_id]
JOIN [sys].[index_columns] AS [ic] ON [i].[object_id] = [ic].[object_id] AND [i].[index_id] = [ic].[index_id]
JOIN [sys].[columns] AS [c] ON [ic].[object_id] = [c].[object_id] AND [ic].[column_id] = [c].[column_id]
WHERE "
WHERE [i].[is_hypothetical] = 0
AND "
+ tableFilter;

if (SupportsTemporalTable())
Expand All @@ -867,6 +868,7 @@ FROM [sys].[indexes] i

commandText += @"
AND [c].[is_hidden] = 1
AND [i].[is_hypothetical] = 0
)";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,26 @@ CREATE TABLE FilteredIndexTable (
"DROP TABLE FilteredIndexTable;");
}

[ConditionalFact]
public void Ignore_hypothetical_index()
{
Test(
@"
CREATE TABLE HypotheticalIndexTable (
Id1 int,
Id2 int NULL,
);

CREATE INDEX ixHypo ON HypotheticalIndexTable ( Id1 ) WITH STATISTICS_ONLY = -1;",
Enumerable.Empty<string>(),
Enumerable.Empty<string>(),
dbModel =>
{
Assert.Empty(dbModel.Tables.Single().Indexes);
},
"DROP TABLE HypotheticalIndexTable;");
}

#endregion

#region ForeignKeyFacets
Expand Down