List:Commits« Previous MessageNext Message »
From:eugene Date:March 7 2007 7:45pm
Subject:bk commit into 5.0 tree (evgen:1.2411) BUG#22331
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-03-07 21:44:58+03:00, evgen@stripped +8 -0
  Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
  away.
  
  During optimization stage the WHERE conditions can be changed or even
  be removed at all if they know for sure to be true of false. Thus they aren't
  showed in the EXPLAIN EXTENDED which prints conditions after optimization.
  
  Now if all elements of an Item_cond were removed this Item_cond is substituted
  for an Item_int with the int value of the Item_cond.
  If there were conditions that were totally optimized away then values of the
  saved cond_value and having_value will be printed instead.

  mysql-test/r/explain.result@stripped, 2007-03-07 21:31:36+03:00, evgen@stripped +29 -0
    Added a test case for the bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all
expressions were optimized away.

  mysql-test/r/func_test.result@stripped, 2007-03-07 21:31:34+03:00, evgen@stripped +1
-1
    Corrected test case result after fix for bug#22331.

  mysql-test/r/subselect.result@stripped, 2007-03-07 21:31:33+03:00, evgen@stripped +8
-8
    Corrected test case result after fix for bug#22331.

  mysql-test/t/explain.test@stripped, 2007-03-07 21:31:28+03:00, evgen@stripped +14 -0
    Added a test case for the bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all
expressions were optimized away.

  sql/sql_lex.cc@stripped, 2007-03-07 21:43:19+03:00, evgen@stripped +1 -0
    Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
    away.
    The initialization of the cond_value and the having_value variables.

  sql/sql_lex.h@stripped, 2007-03-07 21:42:15+03:00, evgen@stripped +2 -0
    Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
    away.
    The cond_value and the having_value variables are
    added to the SELECT_LEX class.

  sql/sql_select.cc@stripped, 2007-03-07 21:40:05+03:00, evgen@stripped +18 -5
    Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
    away.
    Now if all elements of an Item_cond were removed this Item_cond is substituted
    for an Item_int with the int value of the Item_cond.
    If there were conditions that were totally optimized away then values of the
    saved cond_value and having_value will be printed instead.

  sql/sql_select.h@stripped, 2007-03-07 21:44:25+03:00, evgen@stripped +1 -1
    Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were optimized
    away.
    Now having_value is also stored in the JOIN class.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	evgen
# Host:	moonbone.local
# Root:	/mnt/gentoo64/work/22331-bug-5.0-opt-mysql

--- 1.211/sql/sql_lex.cc	2007-02-09 23:59:09 +03:00
+++ 1.212/sql/sql_lex.cc	2007-03-07 21:43:19 +03:00
@@ -1192,6 +1192,7 @@
   is_correlated= 0;
   cur_pos_in_select_list= UNDEF_POS;
   non_agg_fields.empty();
+  cond_value= having_value= Item::COND_UNDEF;
 }
 
 /*

--- 1.240/sql/sql_lex.h	2007-01-31 17:12:41 +03:00
+++ 1.241/sql/sql_lex.h	2007-03-07 21:42:15 +03:00
@@ -487,6 +487,8 @@
   Item *where, *having;                         /* WHERE & HAVING clauses */
   Item *prep_where; /* saved WHERE clause for prepared statement processing */
   Item *prep_having;/* saved HAVING clause for prepared statement processing */
+  /* Saved values of the WHERE and HAVING clauses*/
+  Item::cond_result cond_value, having_value;
   /* point on lex in which it was created, used in view subquery detection */
   st_lex *parent_lex;
   enum olap_type olap;

--- 1.490/sql/sql_select.cc	2007-02-13 10:10:29 +03:00
+++ 1.491/sql/sql_select.cc	2007-03-07 21:40:05 +03:00
@@ -681,7 +681,6 @@
   }
 
   {
-    Item::cond_result having_value;
     having= optimize_cond(this, having, join_list, &having_value);
     if (thd->net.report_error)
     {
@@ -689,6 +688,10 @@
       DBUG_PRINT("error",("Error from optimize_cond"));
       DBUG_RETURN(1);
     }
+    if (select_lex->where)
+      select_lex->cond_value= cond_value;
+    if (select_lex->having)
+      select_lex->having_value= having_value;
 
     if (cond_value == Item::COND_FALSE || having_value == Item::COND_FALSE || 
         (!unit->select_limit_cnt && !(select_options &
OPTION_FOUND_ROWS)))
@@ -829,6 +832,7 @@
     conds->update_used_tables();
     DBUG_EXECUTE("where", print_where(conds, "after substitute_best_equal"););
   }
+
   /*
     Permorm the the optimization on fields evaluation mentioned above
     for all on expressions.
@@ -7535,6 +7539,9 @@
           break;
       }
     }
+    if (!((Item_cond*)cond)->argument_list()->elements)
+      cond= new Item_int(cond->val_bool());
+
   }
   else if (cond->type() == Item::FUNC_ITEM && 
            ((Item_cond*) cond)->functype() == Item_func::MULT_EQUAL_FUNC)
@@ -15259,10 +15266,13 @@
   Item *cur_where= where;
   if (join)
     cur_where= join->conds;
-  if (cur_where)
+  if (cur_where || cond_value != Item::COND_UNDEF)
   {
     str->append(STRING_WITH_LEN(" where "));
-    cur_where->print(str);
+    if (cur_where)
+      cur_where->print(str);
+    else
+      str->append(cond_value != Item::COND_FALSE ? "1" : "0");
   }
 
   // group by & olap
@@ -15288,10 +15298,13 @@
   if (join)
     cur_having= join->having;
 
-  if (cur_having)
+  if (cur_having || having_value != Item::COND_UNDEF)
   {
     str->append(STRING_WITH_LEN(" having "));
-    cur_having->print(str);
+    if (cur_having)
+      cur_having->print(str);
+    else
+      str->append(having_value != Item::COND_FALSE ? "1" : "0");
   }
 
   if (order_list.elements)

--- 1.115/sql/sql_select.h	2007-01-12 23:22:37 +03:00
+++ 1.116/sql/sql_select.h	2007-03-07 21:44:25 +03:00
@@ -292,7 +292,7 @@
 
   bool need_tmp, hidden_group_fields;
   DYNAMIC_ARRAY keyuse;
-  Item::cond_result cond_value;
+  Item::cond_result cond_value, having_value;
   List<Item> all_fields; // to store all fields that used in query
   //Above list changed to use temporary table
   List<Item> tmp_all_fields1, tmp_all_fields2, tmp_all_fields3;

--- 1.172/mysql-test/r/subselect.result	2007-01-26 08:01:25 +03:00
+++ 1.173/mysql-test/r/subselect.result	2007-03-07 21:31:33 +03:00
@@ -421,7 +421,7 @@
 3	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	
 Warnings:
-Note	1003	select 1 AS `1` from `test`.`t1`
+Note	1003	select 1 AS `1` from `test`.`t1` where 1
 drop table t1;
 CREATE TABLE `t1` (
 `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
@@ -1180,7 +1180,7 @@
 1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
 Warnings:
-Note	1003	select <in_optimizer>(0,<exists>(select 1 AS `Not_used` from
`test`.`t1` `a`)) AS `0 IN (SELECT 1 FROM t1 a)`
+Note	1003	select <in_optimizer>(0,<exists>(select 1 AS `Not_used` from
`test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
 INSERT INTO t1 (pseudo) VALUES ('test1');
 SELECT 0 IN (SELECT 1 FROM t1 a);
 0 IN (SELECT 1 FROM t1 a)
@@ -1190,7 +1190,7 @@
 1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
 Warnings:
-Note	1003	select <in_optimizer>(0,<exists>(select 1 AS `Not_used` from
`test`.`t1` `a`)) AS `0 IN (SELECT 1 FROM t1 a)`
+Note	1003	select <in_optimizer>(0,<exists>(select 1 AS `Not_used` from
`test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
 drop table t1;
 CREATE TABLE `t1` (
 `i` int(11) NOT NULL default '0',
@@ -1532,7 +1532,7 @@
 1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
 2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	const row not found
 Warnings:
-Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3`
+Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 select * from t3 where NULL >= any (select b from t2 group by 1);
 a
 explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
@@ -1540,7 +1540,7 @@
 1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
 2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	const row not found
 Warnings:
-Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3`
+Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 select * from t3 where NULL >= some (select b from t2);
 a
 explain extended select * from t3 where NULL >= some (select b from t2);
@@ -1548,7 +1548,7 @@
 1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
 2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	const row not found
 Warnings:
-Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3`
+Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 select * from t3 where NULL >= some (select b from t2 group by 1);
 a
 explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
@@ -1556,7 +1556,7 @@
 1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
 2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	const row not found
 Warnings:
-Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3`
+Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
 insert into t2 values (2,2), (2,1), (3,3), (3,1);
 select * from t3 where a > all (select max(b) from t2 group by a);
 a
@@ -1618,7 +1618,7 @@
 3	UNION	t1	system	NULL	NULL	NULL	NULL	1	
 NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	
 Warnings:
-Note	1003	select `test`.`t1`.`s1` AS `s1` from `test`.`t1`
+Note	1003	select `test`.`t1`.`s1` AS `s1` from `test`.`t1` where 1
 drop table t1;
 CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
 INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');

--- 1.17/mysql-test/r/explain.result	2006-06-01 04:39:05 +04:00
+++ 1.18/mysql-test/r/explain.result	2007-03-07 21:31:36 +03:00
@@ -57,3 +57,32 @@
 explain select 3 into @v1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+create table t1(f1 int, f2 int);
+insert into t1 values (1,1);
+create view v1 as select * from t1 where f1=1;
+explain extended select * from v1 where f2=1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	
+Warnings:
+Note	1003	select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` where
1
+explain extended select * from t1 where 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` where
0
+explain extended select * from t1 where 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	
+Warnings:
+Note	1003	select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` where
1
+explain extended select * from t1 having 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible HAVING
+Warnings:
+Note	1003	select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1`
having 0
+explain extended select * from t1 having 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	
+Warnings:
+Note	1003	select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1`
having 1
+drop table t1;

--- 1.33/mysql-test/r/func_test.result	2006-11-07 07:02:38 +03:00
+++ 1.34/mysql-test/r/func_test.result	2007-03-07 21:31:34 +03:00
@@ -79,7 +79,7 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
 Warnings:
-Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1`
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
 select - a from t1;
 - a
 -1

--- 1.10/mysql-test/t/explain.test	2006-06-01 04:39:06 +04:00
+++ 1.11/mysql-test/t/explain.test	2007-03-07 21:31:28 +03:00
@@ -51,4 +51,18 @@
 select 3 into @v1;
 explain select 3 into @v1;
 
+#
+# Bug#22331: Wrong WHERE in EXPLAIN EXTENDED when all expressions were
+#            optimized away.
+#
+create table t1(f1 int, f2 int);
+insert into t1 values (1,1);
+create view v1 as select * from t1 where f1=1;
+explain extended select * from v1 where f2=1;
+explain extended select * from t1 where 0;
+explain extended select * from t1 where 1;
+explain extended select * from t1 having 0;
+explain extended select * from t1 having 1;
+drop table t1;
+
 # End of 5.0 tests.
Thread
bk commit into 5.0 tree (evgen:1.2411) BUG#22331eugene7 Mar