Skip to content

Improve performance of queries of the form SELECT *, CASE ... END #18056

Description

@pepijnve

Is your feature request related to a problem or challenge?

A query of the form SELECT *, CASE ... END adds an extra column to an existing relation. The current implementation of case will take the entire input relation (i.e. all columns) and filter the entire records batch and all its columns for each when branch. This is done regardless of whether the when, then or else expressions use any of these columns or not. The implication is that the implementation may end up needlessly filtering columns that will never be read. For wide queries with many columns this has a significant impact on case evaluation.

As an example assume a query SELECT *, CASE c1 WHEN 1 THEN 'foo' WHEN 2 THEN 'bar' ELSE 'baz' END FROM t where t has 100 columns named c1 to c100. Since the case expression is only dependent on c1 it is pointless and wasteful to filter columns c2 through c100.

Describe the solution you'd like

Investigate if there are ways to optimize case evaluation.

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. added theissue type on Oct 14, 2025
  2. pepijnve commented on Oct 14, 2025

    @pepijnve
    ContributorAuthor

    take

  3. rluvaton commented on Oct 20, 2025

    @rluvaton
    Member

    Can you please add more to the description, I'm not sure I understand

  4. pepijnve commented on Oct 20, 2025

    @pepijnve
    ContributorAuthor

    @rluvaton add some more detail. The PR (which I'm afraid has stalled a bit on my end) gives some ideas on how I think we could improve this.

  5. added a commit that references this issue on Oct 31, 2025
    c3e49fb
  6. added a commit that references this issue on Nov 2, 2025
    c0efa37
  7. added a commit that references this issue on Nov 11, 2025
    3323552
  8. added a commit that references this issue on Feb 4, 2026
    33d16a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions