MDEV-37713/MDEV-37714 Fold boolean literals in SELECT-list#4754
MDEV-37713/MDEV-37714 Fold boolean literals in SELECT-list#4754jaeheonshim wants to merge 1 commit intoMariaDB:mainfrom
Conversation
eba7fae to
8acdfc3
Compare
The order of evaluation of the expressions that appear in a SELECT-list is undefined. This change exploits this fact by recursively folding TRUE/FALSE literals in OR/AND expressions which may allow for skipping evaluation of some parts of the expression or even the whole expression.
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
Please also add a test case.
And, the jira mentions one optimization you're not really doing:
SELECT (a > 0 AND a < 0) FROM t1;
SELECT (a > 0 OR a <=0) FROM t1;
Would you consider doing this too? Or, if you wont, we'll need to open a sub-task Jira instead of using the current one.
| li2.remove(); | ||
| } | ||
| } | ||
| if (list.is_empty()) |
There was a problem hiding this comment.
Can the list ever be empty, given that you're removing one of the branches only if another branch exists?
I'd say no. And then this is dead code. And should be turned into an assert.
| If item is a SELECT-list COND_ITEM, rewrite it on the first time this | ||
| query is optimized to fold boolean expressions | ||
| */ | ||
| if (thd->lex->current_select->context_analysis_place == SELECT_LIST && |
There was a problem hiding this comment.
Any specific reason why you're doing this only for the SELECT list expressions?
Why not do this during fix_fields for all Item_conds for example?
There was a problem hiding this comment.
Forgot to mention one thing: When doing the optimization you are doing you need to check for NULL-ness!
SELECT true AND NULL FROM t1
should return NULL and not true.
The order of evaluation of the expressions that appear in a SELECT-list is undefined. This change exploits this fact by recursively folding TRUE/FALSE literals in OR/AND expressions which may allow for skipping evaluation of some parts of the expression or even the whole expression.
Example
Setup
Before
After