A web development/programming blog providing info, tips, and tricks on programming languages, scripting, Linux, MySQL and more
What does “Impossible WHERE noticed after reading const tables” mean?
When it comes to basic query optimization and analysis, in my opinion, there is no better tool than the MySQL EXPLAIN command. It can prove to be an invaluable tool for deciphering the MySQL query execution plan, or the way that MySQL is optimizing and executing the query. It will show you the type of SELECT being made on the table, the join type, possible keys, used keys, rows analyzed and more. I won’t get into the nitty gritty of EXPLAIN in this post, but if you are using it, on occasion you may get the following output:
+-----------------------------------------------------+ | Extra | +-----------------------------------------------------+ | Impossible WHERE noticed after reading const tables | +-----------------------------------------------------+
There are two things to know in order to decipher this. First off, what is a “const table”. The “type” column refers to the join type made on the tables. The “const” type is the bets type of join type you can make, after a “system” type, which is a special case of the “const” join type when the table has only 1 row in it. According to the MySQL manual:
The table has at most one matching row, which is read at the start of the query. Because there is only one row, values from the column in this row can be regarded as constants by the rest of the optimizer. const tables are very fast because they are read only once.
(source: MySQL :: MySQL 5.0 Reference Manual :: 7.2.1 Optimizing Queries with EXPLAIN)
A “const” join type occurs when you run a very specific WHERE clause in your query that matches at most, one row from the referenced table.
The second thing to know is the “Impossible WHERE noticed”. This does not mean that your WHERE clause is wrong, it simple means “MySQL has read all const (and system) tables and notice that the WHERE clause is always false” (source: MySQL :: MySQL 5.0 Reference Manual :: 7.2.1 Optimizing Queries with EXPLAIN).
So in summation, the statement “Impossible WHERE noticed after reading const tables” simply means, that your query returned an empty result set (0 rows). You won’t always get this error on an EXPLAIN command when 0 rows are returned, but when you do get it, that’s what it means. I hope this helps

