diff options
author | unknown <evgen@moonbone.local> | 2007-03-07 22:23:08 +0300 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2007-03-07 22:23:08 +0300 |
commit | d7738740449fc83ec348529314b22673cdbada76 (patch) | |
tree | bf4ccc7025c7e9746a49aa45f634d7e877a8e27e | |
parent | e4cdb5801325acf72dbbe197c3c2eb2f7c7244b7 (diff) | |
parent | 6f18c39265f4a9037d8212c5113891f5833745d3 (diff) | |
download | mariadb-git-d7738740449fc83ec348529314b22673cdbada76.tar.gz |
Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into moonbone.local:/mnt/gentoo64/work/25373-bug-5.0-opt-mysql
sql/sql_select.cc:
Auto merged
-rw-r--r-- | mysql-test/r/explain.result | 29 | ||||
-rw-r--r-- | mysql-test/r/func_test.result | 2 | ||||
-rw-r--r-- | mysql-test/r/sp.result | 13 | ||||
-rw-r--r-- | mysql-test/r/subselect.result | 16 | ||||
-rw-r--r-- | mysql-test/t/explain.test | 14 | ||||
-rw-r--r-- | mysql-test/t/sp.test | 15 | ||||
-rw-r--r-- | sql/item_func.cc | 9 | ||||
-rw-r--r-- | sql/sql_lex.cc | 1 | ||||
-rw-r--r-- | sql/sql_lex.h | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 23 | ||||
-rw-r--r-- | sql/sql_select.h | 2 |
11 files changed, 109 insertions, 17 deletions
diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index 3bd7b2ccc15..221a8695f60 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -57,3 +57,32 @@ select 3 into @v1; 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; diff --git a/mysql-test/r/func_test.result b/mysql-test/r/func_test.result index 43832bdbccc..c3fbdb3b3bf 100644 --- a/mysql-test/r/func_test.result +++ b/mysql-test/r/func_test.result @@ -79,7 +79,7 @@ explain extended select * from t1 where 1 xor 1; 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 diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 8e3c057cc62..81e2db70357 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5741,4 +5741,17 @@ END| CALL bug24117()| DROP PROCEDURE bug24117| DROP TABLE t3| +DROP FUNCTION IF EXISTS bug25373| +CREATE FUNCTION bug25373(p1 INTEGER) RETURNS INTEGER +LANGUAGE SQL DETERMINISTIC +RETURN p1;| +CREATE TABLE t3 (f1 INT, f2 FLOAT)| +INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)| +SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP| +SUM(f2) bug25373(f1) +6.3000000715256 1 +15 2 +21.300000071526 NULL +DROP FUNCTION bug25373| +DROP TABLE t3| drop table t1,t2; diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 7177b4e4432..373d49c29d2 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -421,7 +421,7 @@ id select_type table type possible_keys key key_len ref rows Extra 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 @@ id select_type table type possible_keys key key_len ref rows Extra 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 @@ id select_type table type possible_keys key key_len ref rows Extra 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 @@ id select_type table type possible_keys key key_len ref rows Extra 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 @@ id select_type table type possible_keys key key_len ref rows Extra 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 @@ id select_type table type possible_keys key key_len ref rows Extra 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 @@ id select_type table type possible_keys key key_len ref rows Extra 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 @@ id select_type table type possible_keys key key_len ref rows Extra 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'); diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test index efce0cdf3b5..85bbbfea154 100644 --- a/mysql-test/t/explain.test +++ b/mysql-test/t/explain.test @@ -51,4 +51,18 @@ set names latin1; 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. diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index cfa4937e050..5da29454b08 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -6715,6 +6715,21 @@ DROP PROCEDURE bug24117| DROP TABLE t3| # +# Bug#25373: Stored functions wasn't compared correctly which leads to a wrong +# result. +# +--disable_warnings +DROP FUNCTION IF EXISTS bug25373| +--disable_warnings +CREATE FUNCTION bug25373(p1 INTEGER) RETURNS INTEGER +LANGUAGE SQL DETERMINISTIC +RETURN p1;| +CREATE TABLE t3 (f1 INT, f2 FLOAT)| +INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)| +SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP| +DROP FUNCTION bug25373| +DROP TABLE t3| +# # NOTE: The delimiter is `|`, and not `;`. It is changed to `;` # at the end of the file! # diff --git a/sql/item_func.cc b/sql/item_func.cc index 638d8903dcb..c8c0671ae1d 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -409,8 +409,13 @@ bool Item_func::eq(const Item *item, bool binary_cmp) const if (item->type() != FUNC_ITEM) return 0; Item_func *item_func=(Item_func*) item; - if (arg_count != item_func->arg_count || - func_name() != item_func->func_name()) + Item_func::Functype func_type; + if ((func_type= functype()) != item_func->functype() || + arg_count != item_func->arg_count || + (func_type != Item_func::FUNC_SP && + func_name() != item_func->func_name()) || + (func_type == Item_func::FUNC_SP && + my_strcasecmp(system_charset_info, func_name(), item_func->func_name()))) return 0; for (uint i=0; i < arg_count ; i++) if (!args[i]->eq(item_func->args[i], binary_cmp)) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index cd4d2e85316..7c87d955e84 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1195,6 +1195,7 @@ void st_select_lex::init_select() is_correlated= 0; cur_pos_in_select_list= UNDEF_POS; non_agg_fields.empty(); + cond_value= having_value= Item::COND_UNDEF; inner_refs_list.empty(); } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 86d01675c2a..784bf885e69 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -488,6 +488,8 @@ public: 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; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index af393471b64..fc67ffac2fb 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -760,7 +760,6 @@ JOIN::optimize() } { - Item::cond_result having_value; having= optimize_cond(this, having, join_list, &having_value); if (thd->net.report_error) { @@ -768,6 +767,10 @@ JOIN::optimize() 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))) @@ -908,6 +911,7 @@ JOIN::optimize() 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. @@ -7617,6 +7621,9 @@ static COND* substitute_for_best_equal_field(COND *cond, 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) @@ -15335,10 +15342,13 @@ void st_select_lex::print(THD *thd, String *str) 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 @@ -15364,10 +15374,13 @@ void st_select_lex::print(THD *thd, String *str) 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) diff --git a/sql/sql_select.h b/sql/sql_select.h index a17d7fcb362..27ca633fdb5 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -292,7 +292,7 @@ public: 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; |