Skip to content

Unify SQL planning for ORDER BY, HAVING, DISTINCT, etc #10326

Open

Description

@alamb

Is your feature request related to a problem or challenge?

As @jonahgao points out in #10234:

select x from foo order by y can is covered by add_missing_columns, by blindly adding columns into the descendant projection node. Another issue is that we should not run add_missing_columns for other SetExprs except SELECT.

In #10234 @jonahgao added a more general solution to use the merged schema from the select list and the FROM clause to handle resolving HAVING and set operations

However, both codepaths now exist, which makes for fairly complicated planning process

Describe the solution you'd like

I think that we should handle ORDER BY similarly to HAVING, use the merged schema, add the missing columns directly in the select list, instead of traversing the plan looking for projection node. Their processing logic may be reusable. I agree it might be good to have a broader discussion about this.

@jonahgao in #10234 (comment)

Describe alternatives you've considered

One alternative might be add_missing_columns and using the new order_by_to_sort_expr options added in #10234

Additional context

No response

Activity

  1. lichuang commented on Jan 17, 2025

    @lichuang

    @alamb Is this issue still on going? If so, let me have a try.

  2. alamb commented on Jan 17, 2025

    @alamb
    ContributorAuthor

    👋 @lichuang -- I don't know anyone working on it, but maybe @jonahgao knows of something.

    THank you!

  3. jonahgao commented on Jan 17, 2025

    @jonahgao
    Member

    I haven't started working on it yet. Feel free to take it. Thanks @lichuang

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

    enhancementNew feature or requestsqlSQL Planner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions