Skip to content

opt: transform some of the expressions into equivalent CASE expressions #77799

@yuzefovich

Description

@yuzefovich

In the vectorized execution engine we use the CASE operator to support several expressions. We do so during the vectorized planning, but it seems more appropriate to do the transformation during the normalization stage of the optimization.

I believe that the execution in the row-by-row engine will not suffer performance-wise, so we'll be able to remove the implementations of Eval methods for the corresponding expressions.

In particular, the following constructs are implemented in the vectorized planning:

  • WHERE a OR b
    • into WHERE CASE WHEN a THEN true WHEN b THEN true ELSE false END
  • COALESCE(a, b, ...)
    • into CASE WHEN a IS DISTINCT FROM NULL THEN a WHEN b IS DISTINCT FROM NULL THEN b ... END
      - IF(a, b, c)
      - into CASE WHEN a THEN b ELSE c END
      - NULLIF(a, b)
      - into CASE WHEN a = b THEN NULL ELSE a END.

Jira issue: CRDB-13769

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupTech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.E-quick-winLikely to be a quick win for someone experienced.E-starterMight be suitable for a starter project for new employees or team members.T-sql-queriesSQL Queries Team

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions