Skip to content

Commit

Permalink
Ignore hypothetical indexes (now with test!) (#20707)
Browse files Browse the repository at this point in the history
Ignore hypothetical indexes (now with test!)

fixes #20705
  • Loading branch information
ErikEJ committed Apr 22, 2020
1 parent b449924 commit 09cfc31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,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 @@ -872,6 +873,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 @@ -1890,6 +1890,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

0 comments on commit 09cfc31

Please sign in to comment.