Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: optimize CASE statement - remove conditions that are never hit #18935

Closed
maumar opened this issue Nov 15, 2019 · 2 comments · Fixed by #34175
Closed

Query: optimize CASE statement - remove conditions that are never hit #18935

maumar opened this issue Nov 15, 2019 · 2 comments · Fixed by #34175
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Nov 15, 2019

CASE
        WHEN CAST(0 AS bit) THEN x
        ELSE y
    END

we can simply remove the WHEN block since it's condition is never met so the result would be just y

If all the WHEN blocks have been removed and there is no ELSE condition we can return NULL

@smitpatel
Copy link
Contributor

@maumar - Is this already done?

@ranma42
Copy link
Contributor

ranma42 commented Jun 23, 2024

Yes, this should already be optimized by

else if (IsFalse(testCondition))
{
// if test evaluates to 'false' we can remove the WhenClause
RestoreNonNullableColumnsList(currentNonNullableColumnsCount);
RestoreNullValueColumnsList(currentNullValueColumnsCount);
continue;
}

EDIT: clauses whose test is NULL instead of FALSE are currently left in; I'm working on it.

@maumar maumar modified the milestones: Backlog, 9.0.0-preview7 Jul 12, 2024
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 12, 2024
@roji roji modified the milestones: 9.0.0-preview7, 9.0.0 Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants