diff options
author | Igor Babaev <igor@askmonty.org> | 2014-03-22 12:44:39 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2014-03-22 12:44:39 -0700 |
commit | 887a210ffc5c38cf9623ad308b68094510f1bfbb (patch) | |
tree | a85969eab11e043ec288a9b5f75be924897a2f3b | |
parent | b35296911886143267ea471530e701169e5f7f56 (diff) | |
download | mariadb-git-887a210ffc5c38cf9623ad308b68094510f1bfbb.tar.gz |
Fixed bug mdev-5931.
After constant table row substitution the where condition may be converted
to always true. The function calculate_cond_selectivity_for_table() should
take into account this possibility.
-rw-r--r-- | mysql-test/r/selectivity.result | 22 | ||||
-rw-r--r-- | mysql-test/r/selectivity_innodb.result | 22 | ||||
-rw-r--r-- | mysql-test/t/selectivity.test | 23 | ||||
-rw-r--r-- | sql/opt_range.cc | 2 |
4 files changed, 68 insertions, 1 deletions
diff --git a/mysql-test/r/selectivity.result b/mysql-test/r/selectivity.result index 2c96ae4ae90..10d39eb174e 100644 --- a/mysql-test/r/selectivity.result +++ b/mysql-test/r/selectivity.result @@ -1320,4 +1320,26 @@ drop table t1, t2; set histogram_type=@save_histogram_type; set histogram_size=@save_histogram_size; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-5931: no where condition after constant table row substitution +# with optimizer_use_condition_selectivity=3 +# +CREATE TABLE t1 (a varchar(3), b varchar(3)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo', 'foo'); +CREATE TABLE t2 (c INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1), (2); +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 select 'foo' AS `a`,'foo' AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where 1 +SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ; +a b c +foo foo 1 +foo foo 2 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/selectivity_innodb.result b/mysql-test/r/selectivity_innodb.result index 70ce55b50c4..1af01855952 100644 --- a/mysql-test/r/selectivity_innodb.result +++ b/mysql-test/r/selectivity_innodb.result @@ -1330,6 +1330,28 @@ drop table t1, t2; set histogram_type=@save_histogram_type; set histogram_size=@save_histogram_size; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-5931: no where condition after constant table row substitution +# with optimizer_use_condition_selectivity=3 +# +CREATE TABLE t1 (a varchar(3), b varchar(3)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo', 'foo'); +CREATE TABLE t2 (c INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1), (2); +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 select 'foo' AS `a`,'foo' AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where 1 +SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ; +a b c +foo foo 1 +foo foo 2 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; set use_stat_tables=@save_use_stat_tables; set optimizer_switch=@save_optimizer_switch_for_selectivity_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/selectivity.test b/mysql-test/t/selectivity.test index 8b7dfdff09f..8774afdc554 100644 --- a/mysql-test/t/selectivity.test +++ b/mysql-test/t/selectivity.test @@ -889,4 +889,27 @@ set histogram_type=@save_histogram_type; set histogram_size=@save_histogram_size; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +--echo # +--echo # Bug mdev-5931: no where condition after constant table row substitution +--echo # with optimizer_use_condition_selectivity=3 +--echo # + +CREATE TABLE t1 (a varchar(3), b varchar(3)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo', 'foo'); + +CREATE TABLE t2 (c INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1), (2); + +set optimizer_use_condition_selectivity=3; + +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ; + +SELECT * FROM t1, t2 WHERE c >= 0 OR a = b ; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2; + set use_stat_tables=@save_use_stat_tables; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index dc8a5475162..cbc3d285d0a 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3409,7 +3409,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond) table->cond_selectivity= 1.0; - if (table_records == 0) + if (!cond || table_records == 0) DBUG_RETURN(FALSE); if (table->pos_in_table_list->schema_table) |