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

Impossible WHERE for a!=a, a<a, a>a #234

Closed
wants to merge 1 commit into from

Conversation

grooverdan
Copy link

For a table column a, the above expressions logically
equate to false in all cases.

With this patch the optimizer knows about this and queries
like:

SELECT * FROM t1 WHERE a!=a

no longer need to evaluate a!=a for every row.

The same applies if the expression was a<a, or a>a

An EXPLAIN SELECT COUNT(*) FROM t1 WHERE a<a will show:

EXPLAIN SELECT COUNT(*) FROM t1 WHERE a<a;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE

Similarly NOT (a!=a) is always true.

EXPLAIN SELECT COUNT() FROM t1 WHERE not (a!=a);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
Warnings:
Note 1003 /
select#1 */ select count(0) AS COUNT(*) from test.t1 where 1

For a table column `a`, the above expressions logically
equate to false in all cases.

With this patch the optimizer knows about this and queries
like:

SELECT * FROM t1 WHERE a!=a

no longer need to evaluate a!=a for every row.

The same applies if the expression was `a<a`, or `a>a`

An `EXPLAIN SELECT COUNT(*) FROM t1 WHERE a<a` will show:

EXPLAIN SELECT COUNT(*) FROM t1 WHERE a<a;
id     select_type     table   partitions      type    possible_keys   key     key_len ref     rows    filtered        Extra
1      SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE

Similarly `NOT (a!=a)` is always true.

EXPLAIN SELECT COUNT(*) FROM t1 WHERE not (a!=a);
id     select_type     table   partitions      type    possible_keys   key     key_len ref     rows    filtered        Extra
1      SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Select tables optimized away
Warnings:
Note   1003    /* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t1` where 1
@grooverdan
Copy link
Author

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=93642 for updates.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants