Skip to content

perf: Update CaseToCoalesceRule to ignore irrelevant casts.#18400

Open
gianm wants to merge 2 commits intoapache:masterfrom
gianm:fix-json-value-coalesce
Open

perf: Update CaseToCoalesceRule to ignore irrelevant casts.#18400
gianm wants to merge 2 commits intoapache:masterfrom
gianm:fix-json-value-coalesce

Conversation

@gianm
Copy link
Copy Markdown
Contributor

@gianm gianm commented Aug 13, 2025

Previously, CaseToCoalesceRule ignored nullability casts when deciding if "x" and "y" in "CASE WHEN x IS NOT NULL THEN y" match and could therefore form the basis of a COALESCE. This was too strict, since it considered a cast from VARCHAR to VARCHAR(2000), which can happen after applying JSON_VALUE, to be relevant. It is not relevant, because it does not affect how we execute the query.

This patch updates the logic to ignore nullability casts and also casts that change irrelevant properties of the type. ("Irrelevant" being defined as "properties that do not affect how the query executes".)

This change speeds up queries, because generally COALESCE runs faster than CASE. Note that one of the test cases is now vectorizable, where it wasn't previously. The new tests are also both vectorizable.

Previously, CaseToCoalesceRule ignored nullability casts when deciding
if "x" and "y" in "CASE WHEN x IS NOT NULL THEN y" match and could
therefore form the basis of a COALESCE. This was too strict, since it
considered a cast from VARCHAR to VARCHAR(2000), which can happen after
applying JSON_VALUE, to be relevant. It is not relevant, because it does
not affect how we execute the query.

This patch updates the logic to ignore nullability casts and also casts
that change irrelevant properties of the type. ("Irrelevant" being defined
as "properties that do not affect how the query executes".)
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the dev@druid.apache.org list.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 14, 2025
@gianm gianm removed the stale label Oct 30, 2025
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the dev@druid.apache.org list.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 30, 2025
@gianm gianm removed the stale label Jan 16, 2026
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity.
It will be closed in 4 weeks if no further activity occurs. If you think
that's incorrect or this pull request should instead be reviewed, please simply
write any comment. Even if closed, you can still revive the PR at any time or
discuss it on the dev@druid.apache.org list.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 18, 2026
@gianm gianm removed the stale label Mar 18, 2026
@gianm gianm changed the title SQL: Update CaseToCoalesceRule to ignore irrelevant casts. perf: Update CaseToCoalesceRule to ignore irrelevant casts. Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants