Skip to content

KL-7b: the KL-7 table-collision drop generalizes to any same-named table anywhere in the procedure #17

Description

@devops-den

What it does wrong — confirms KL-7 generalizes beyond the obvious case

A CTE that collides in name with a physical table drops that table anywhere in the procedure, even in a completely unrelated statement that never references the CTE at all.

;WITH Product AS (SELECT c.CaseId FROM dbo.CaseFile c)
SELECT p.CaseId FROM Product p;

SELECT sp.Id FROM dbo.Product sp;

The Product CTE is built from an entirely different table (dbo.CaseFile). A second, totally separate statement directly queries the real dbo.Product — never through the CTE. dbo.Product still vanishes from the report.

Why it matters

This confirms the root cause behind KL-7 (see that issue) is not a narrow edge case — the exclusion check (base in cte_names) is a blunt, procedure-wide set-membership test with no locality. It drops every table sharing that bare name anywhere in the procedure, regardless of whether it has any relationship to the colliding CTE.

Test

Pinned as a strict-xfail: tests/test_known_limitations.py::test_KL7b_collision_drops_unrelated_same_named_table_anywhere_in_procedure.

Likely same fix as KL-7 — see that issue. Filed separately because each has its own pinned regression test and its own fixture (tests/fixtures/cte_table_collision_variant.sql).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededknown-limitationA documented, pinned parser limitation (see tests/test_known_limitations.py)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions