Description
The StripUnusedJoins logic strips a view reference when only 1 column remains after column stripping (case 1 when options.StripUnusedJoins in DatabaseViewInliner.cs). However, it doesn't distinguish between:
- A join where the remaining column is only used in the ON clause (correct to strip)
- A view where the remaining column is actively selected (incorrect to strip)
Example
-- Inner view
CREATE VIEW dbo.VItems AS SELECT a.Id, a.Name FROM dbo.A a INNER JOIN dbo.B b ON a.BId = b.Id
-- Outer view: selects v.Id — this IS selected data
CREATE VIEW dbo.VTest AS SELECT v.Id FROM dbo.VItems v
After column stripping, VItems has 1 column (Id). The 1-column rule adds VItems to toRemove and skips toReplace, so VItems ends up neither inlined nor removed in the output.
Expected behavior
VItems should be inlined normally since its remaining column is used in the SELECT, not just in a join condition.
Priority
Low — unlikely to occur in production since views typically have 2+ useful columns.
Possible fix
Check whether the remaining column is referenced in the outer SELECT (not just in a JOIN ON clause) before applying the strip rule.
Description
The
StripUnusedJoinslogic strips a view reference when only 1 column remains after column stripping (case 1 when options.StripUnusedJoinsinDatabaseViewInliner.cs). However, it doesn't distinguish between:Example
After column stripping, VItems has 1 column (
Id). The 1-column rule adds VItems totoRemoveand skipstoReplace, so VItems ends up neither inlined nor removed in the output.Expected behavior
VItems should be inlined normally since its remaining column is used in the SELECT, not just in a join condition.
Priority
Low — unlikely to occur in production since views typically have 2+ useful columns.
Possible fix
Check whether the remaining column is referenced in the outer SELECT (not just in a JOIN ON clause) before applying the strip rule.