diff options
author | Igor Babaev <igor@askmonty.org> | 2013-04-05 13:01:46 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2013-04-05 13:01:46 -0700 |
commit | 503731d80f732a3a790443cc530fea2c3721b869 (patch) | |
tree | 25387182582cd5d2e53913a567dbde17b2907cae | |
parent | daaa5834c9fb567924c21d467983c1ec3401f832 (diff) | |
download | mariadb-git-503731d80f732a3a790443cc530fea2c3721b869.tar.gz |
Fixed bug mdev-4371.
Avoid possible division by 0.
-rw-r--r-- | mysql-test/r/selectivity.result | 28 | ||||
-rw-r--r-- | mysql-test/r/selectivity_innodb.result | 29 | ||||
-rw-r--r-- | mysql-test/t/selectivity.test | 33 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 |
4 files changed, 91 insertions, 1 deletions
diff --git a/mysql-test/r/selectivity.result b/mysql-test/r/selectivity.result index ed8e7f8bd36..5de454ba58c 100644 --- a/mysql-test/r/selectivity.result +++ b/mysql-test/r/selectivity.result @@ -822,4 +822,32 @@ DROP TABLE t1; set histogram_size=@save_histogram_size; set histogram_type=@save_histogram_type; set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4371: Join with condition supported by index on an empty table +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a int, b int, INDEX(a)); +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select NULL AS `a`,NULL AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where 0 +SELECT * FROM t1, t2 WHERE a > 9; +a b c +set optimizer_switch=@save_optimizer_switch; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; 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 256b93d8cb5..6d0c8434051 100644 --- a/mysql-test/r/selectivity_innodb.result +++ b/mysql-test/r/selectivity_innodb.result @@ -829,6 +829,35 @@ DROP TABLE t1; set histogram_size=@save_histogram_size; set histogram_type=@save_histogram_type; set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4371: Join with condition supported by index on an empty table +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a int, b int, INDEX(a)); +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 1 0.00 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` > 9) +SELECT * FROM t1, t2 WHERE a > 9; +a b c +set optimizer_switch=@save_optimizer_switch; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; 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 aab8c504f3c..5bce7f50e0d 100644 --- a/mysql-test/t/selectivity.test +++ b/mysql-test/t/selectivity.test @@ -412,4 +412,37 @@ set histogram_size=@save_histogram_size; set histogram_type=@save_histogram_type; set use_stat_tables=@save_use_stat_tables; +--echo # +--echo # Bug mdev-4371: Join with condition supported by index on an empty table +--echo # with optimizer_use_condition_selectivity=3 +--echo # + +set use_stat_tables=PREFERABLY; + +CREATE TABLE t1 (a int, b int, INDEX(a)); + +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); + +ANALYZE TABLE t1, t2; +FLUSH TABLES; + +set optimizer_use_condition_selectivity=3; + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; + +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +SELECT * FROM t1, t2 WHERE a > 9; + +set optimizer_switch=@save_optimizer_switch; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2; + +set use_stat_tables=@save_use_stat_tables; + + set use_stat_tables=@save_use_stat_tables; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 109c7f22edc..368844c2379 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7030,7 +7030,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, /* Discount the selectivity of the access method used to join table s */ if (s->quick && s->quick->index != MAX_KEY) { - if (pos->key == 0) + if (pos->key == 0 && table_records > 0) { sel*= table->quick_rows[s->quick->index]/table_records; } |