[MDEV-8553] Impossible WHERE a!=a Created: 2015-07-28 Updated: 2019-05-10 Resolved: 2019-05-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Fix Version/s: | 10.4.5 |
| Type: | Task | Priority: | Minor |
| Reporter: | Daniel Black | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | upstream-fixed | ||
| Description |
|
from 5.5.44
Queries like this should end up as 'Impossible Where' the same as 'WHERE 0' is used. Same with > or < as an operator.
I came across this and was potentially generated from the depths of an ORM (sqlalchemy) |
| Comments |
| Comment by Jabbar Memon [ 2017-03-12 ] | |||||||||||||||||||||||||
|
hello sir, I am postgraduate at Dhirubhai Ambani Institute of Information and Communication technology,Ahmedabad.I'd like to contribute to this project in the GSOC 2017. I have a good knowledge about Sql,Postgresql and little bit about mariadb..I want more details about this issue.. Thanks | |||||||||||||||||||||||||
| Comment by Daniel Black [ 2017-03-12 ] | |||||||||||||||||||||||||
|
In SQL terms the condition col1!=col1 will always be false. The same with col1<col1 and col1>col1. Rather than have mariadb engine look through the entire table to validate this, the optimizer can include the code that checks for these impossible conditions and generate the "Impossible Where" warning as well as effectively replace the condition with FALSE. Like wise a col1=col1 condition is almost always true. Requiring the mariadb server to fetch all rows to validate this would be a waste of time. Replacing this with TRUE would enable the query optimiser to choose a better plan. Using your SQL knowledge, when is col1=col1 false? | |||||||||||||||||||||||||
| Comment by Jabbar Memon [ 2017-03-13 ] | |||||||||||||||||||||||||
|
Hello sir, Thank You | |||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-03-15 ] | |||||||||||||||||||||||||
|
Points to consider:
| |||||||||||||||||||||||||
| Comment by Daniel Black [ 2017-03-15 ] | |||||||||||||||||||||||||
|
I suspect the comparison of the two sides of the expression to see if they are the same table/column will be simple leaving the longer case of doing the >, <, and != (to be handled the same) and the = case which requires checking if the column can be NULL checks to determine which simplification is needed. | |||||||||||||||||||||||||
| Comment by Jabbar Memon [ 2017-03-18 ] | |||||||||||||||||||||||||
|
thank you for the help but if the table is same then we dont have to check == and if the column is null so we can make that column primary key so that will reduce the error i think... Thank You | |||||||||||||||||||||||||
| Comment by Daniel Black [ 2017-03-23 ] | |||||||||||||||||||||||||
|
Given the number of other proposals being received, the lower importance of this task, and the limited mentor resources I'm removing the gsoc label for this year. Thanks for your interest and apologies for changing my mind on this task. | |||||||||||||||||||||||||
| Comment by Daniel Black [ 2018-12-16 ] | |||||||||||||||||||||||||
|
psergey as it turns out this is very easy and virtually no impact for reasons described on https://github.com/MariaDB/server/pull/1027 | |||||||||||||||||||||||||
| Comment by Daniel Black [ 2018-12-16 ] | |||||||||||||||||||||||||
|
Fixed in MySQL-8.0
| |||||||||||||||||||||||||
| Comment by Igor Babaev [ 2018-12-17 ] | |||||||||||||||||||||||||
|
Daniel,
There is no wonder, because the MySQL code that processes a<a is practically the same as in MariaDB | |||||||||||||||||||||||||
| Comment by Daniel Black [ 2018-12-18 ] | |||||||||||||||||||||||||
|
Quite right MySQL and MariaDB are behaving identical. I was getting confused on table definitions too. Remove the `NOT NULL` from the column definition is where the 'Impossible WHERE' is no longer detected. Adding an index just changes plan to 'Using index'. Also the `WHERE not (a!=a)` is a condition that doesn't result in 'Select tables optimized away'. The updated PR corrects both of these to use the more optimal query plan. Summary of existing MariaDB behaviour (and can switch to MySQL-8.0.13 quickly): | |||||||||||||||||||||||||
| Comment by Igor Babaev [ 2019-04-04 ] | |||||||||||||||||||||||||
|
Hi Daniel, | |||||||||||||||||||||||||
| Comment by Sergey Vojtovich [ 2019-05-10 ] | |||||||||||||||||||||||||
|
PR have been applied. |