<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="885799">
  <date_last_updated>2011-11-03 18:03:31.963407+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/885799</bug_api_link>
    <bug_owner_link>https://api.launchpad.net/1.0/~sergefp</bug_owner_link>
    <milestone_link></milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/885799/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/885799/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/885799</bug_web_link>
  <owner>Sergey Petrunia</owner>
  <assignee></assignee>
  <milestone_title></milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>No &quot;Impossible WHERE&quot; for false constant conds when expensive const cond is present</title>
  <status>New</status>
  <importance>Undecided</importance>
  <created>2011-11-03 18:03:31.963407+00:00</created>
  <description>
<![CDATA[If we have a query which has 
- regular ("cheap") constant condition that evaluates to FALSE
- an expensive constant condition (doesn't matter what it evaluates to)
then "Impossible WHERE" will not be generated. 

Example:
create table t1 (a int);
insert into t1 values (1),(2),(3);

create table t2 as select * from t1;

create table t_pk1 (a int primary key);
create table t_pk2 (a int primary key);

insert into t_pk1 select a from t1;
insert into t_pk2 select a from t1;

alter table t_pk1 add b int;
alter table t_pk2 add b int;

## Here t_pk1 is a constant table, and "t_pk1.b> 3" is a cheap constant
condition that evaluates to FALSE:

MariaDB [j10]> explain select * from t_pk1, t2 where t_pk1.a=2 and t_pk1.b> 3 ;
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                                               |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Impossible WHERE noticed after reading const tables |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
1 row in set (0.00 sec)

# Now, let's add an expensive constant condition, and observe that we won't be getting "Impossible WHERE" anymore:

MariaDB [j10]> explain select * from t_pk1, t2 where t_pk1.a=2 and t_pk1.b> 3 and 2 > (select max(a) from t1);
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
|  1 | PRIMARY     | t_pk1 | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
|  1 | PRIMARY     | t2    | ALL   | NULL          | NULL    | NULL    | NULL  |    3 |       |
|  2 | SUBQUERY    | t1    | ALL   | NULL          | NULL    | NULL    | NULL  |    3 |       |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
3 rows in set (0.00 sec)]]>  </description>
  <activities>
    <activity datechanged="2011-11-03T18:03:31.963407+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Sergey Petrunia</person>
      <message>added bug</message>
    </activity>
  </activities>
</launchpad-bug>
