Commit 887a210f authored by Igor Babaev's avatar Igor Babaev

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.
parent b3529691
......@@ -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;
......@@ -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;
......@@ -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;
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment