Skip to content

SQL: lower ORDER BY on a qualified column after a join (ambiguous names are rejected now) #652

Description

@zzylol

Found in the #539 review.

Problem

SELECT a.k, b.k FROM a JOIN b ON a.id = b.id ORDER BY b.k used to sort by a.k without any error. The SQL lowering emits the Project above the join with qualifier: None, so its output schema loses each column's source table. The resolver then failed to find b.k by (table, name) and fell back to the first column named k.

Status

#539 makes this fallback safe: it now applies only when exactly one column has that name. Otherwise resolution fails. The query above is now rejected instead of being lowered wrongly.

Follow-up

Make such queries lower correctly. The obstacle is that the IR's Project has a single qualifier for all of its output columns (#573 §4.2.2 relies on this), so a pass-through column cannot keep its own source table. Options:

  • per-column qualifiers on Project;
  • resolving ORDER BY against the pre-projection scope in the frontend.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions