Commit 1c30fb2a authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-4372.

Range analysis of non-indexed columns should handle properly range trees
with type == SEL_TREE::MAYBE.
parent b2d0a33e
......@@ -867,4 +867,32 @@ a
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4372: exists subquery in WHERE
# with optimizer_use_condition_selectivity=3
#
set use_stat_tables = PREFERABLY;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES
(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8);
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2);
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;
EXPLAIN EXTENDED
SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 14 100.00 Using where; Using join buffer (flat, BNL join)
2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((exists(select 1 from `test`.`t1` join `test`.`t2`) and (`test`.`t1`.`a` <> `test`.`t2`.`b`)) or (`test`.`t1`.`a` <= 4))
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;
......@@ -875,6 +875,34 @@ a
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4372: exists subquery in WHERE
# with optimizer_use_condition_selectivity=3
#
set use_stat_tables = PREFERABLY;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES
(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8);
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2);
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;
EXPLAIN EXTENDED
SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 14 100.00 Using where; Using join buffer (flat, BNL join)
2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00
2 SUBQUERY t1 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((exists(select 1 from `test`.`t1` join `test`.`t2`) and (`test`.`t1`.`a` <> `test`.`t2`.`b`)) or (`test`.`t1`.`a` <= 4))
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;
......@@ -467,5 +467,32 @@ DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;
--echo #
--echo # Bug mdev-4372: exists subquery in WHERE
--echo # with optimizer_use_condition_selectivity=3
--echo #
set use_stat_tables = PREFERABLY;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES
(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8);
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2);
ANALYZE TABLE t1, t2;
FLUSH TABLES;
SET optimizer_use_condition_selectivity=3;
EXPLAIN EXTENDED
SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4;
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;
......@@ -3368,7 +3368,12 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond)
rows= 0;
table->reginfo.impossible_range= 1;
goto free_alloc;
}
}
else if (tree->type == SEL_TREE::MAYBE)
{
rows= table_records;
goto free_alloc;
}
for (key= tree->keys, end= key + param.keys; key != end; key++, idx++)
{
......
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