Commit f6b65232 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-4429: fixed another place where selectivity == 0 requires

a special handling.
parent 5051793e
......@@ -1128,4 +1128,41 @@ Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a`
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4429: join with range condition whose selectivity == 0
# when optimizer_use_condition_selectivity=3
#
CREATE TABLE language (lang_group INT, lang VARCHAR(16) PRIMARY KEY);
INSERT INTO language VALUES
(1,'Chinese'),(6,'English'),(1,'French'),
(1,'German'),(1,'Italian'),(0,'Japanese');
CREATE TABLE country (code varchar(3) PRIMARY KEY,
country_group INT DEFAULT NULL);
INSERT INTO country VALUES ('USA',3),('FRA',5);
CREATE TABLE continent (cont_group INT, cont varchar(16) PRIMARY KEY);
INSERT INTO continent VALUES
(1,'N.America'),(1,'S.America'),(3,'Australia'),
(4,'Africa'),(5,'Antarctica'),(6,'Eurasia');
SET use_stat_tables=PREFERABLY;
ANALYZE TABLE country, language, continent;
Table Op Msg_type Msg_text
test.country analyze status OK
test.language analyze status OK
test.continent analyze status OK
FLUSH TABLES;
SET optimizer_use_condition_selectivity=3;
SELECT * FROM language, country, continent
WHERE country_group = lang_group AND lang_group IS NULL;
lang_group lang code country_group cont_group cont
EXPLAIN EXTENDED
SELECT * FROM language, country, continent
WHERE country_group = lang_group AND lang_group IS NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE country ALL NULL NULL NULL NULL 2 0.00 Using where
1 SIMPLE language ALL NULL NULL NULL NULL 6 0.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE continent ALL NULL NULL NULL NULL 6 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`language`.`lang_group` AS `lang_group`,`test`.`language`.`lang` AS `lang`,`test`.`country`.`code` AS `code`,`test`.`country`.`country_group` AS `country_group`,`test`.`continent`.`cont_group` AS `cont_group`,`test`.`continent`.`cont` AS `cont` from `test`.`language` join `test`.`country` join `test`.`continent` where ((`test`.`language`.`lang_group` = `test`.`country`.`country_group`) and isnull(`test`.`country`.`country_group`))
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table language, country, continent;
set use_stat_tables=@save_use_stat_tables;
......@@ -798,7 +798,7 @@ explain extended
select * from t1 where a in ( select b from t2 ) AND ( a > 3 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 0.00 Using where
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 0 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 0.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` > 3))
select * from t1 where a in ( select b from t2 ) AND ( a > 3 );
......@@ -1136,6 +1136,43 @@ Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a`
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4429: join with range condition whose selectivity == 0
# when optimizer_use_condition_selectivity=3
#
CREATE TABLE language (lang_group INT, lang VARCHAR(16) PRIMARY KEY);
INSERT INTO language VALUES
(1,'Chinese'),(6,'English'),(1,'French'),
(1,'German'),(1,'Italian'),(0,'Japanese');
CREATE TABLE country (code varchar(3) PRIMARY KEY,
country_group INT DEFAULT NULL);
INSERT INTO country VALUES ('USA',3),('FRA',5);
CREATE TABLE continent (cont_group INT, cont varchar(16) PRIMARY KEY);
INSERT INTO continent VALUES
(1,'N.America'),(1,'S.America'),(3,'Australia'),
(4,'Africa'),(5,'Antarctica'),(6,'Eurasia');
SET use_stat_tables=PREFERABLY;
ANALYZE TABLE country, language, continent;
Table Op Msg_type Msg_text
test.country analyze status OK
test.language analyze status OK
test.continent analyze status OK
FLUSH TABLES;
SET optimizer_use_condition_selectivity=3;
SELECT * FROM language, country, continent
WHERE country_group = lang_group AND lang_group IS NULL;
lang_group lang code country_group cont_group cont
EXPLAIN EXTENDED
SELECT * FROM language, country, continent
WHERE country_group = lang_group AND lang_group IS NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE country ALL NULL NULL NULL NULL 2 0.00 Using where
1 SIMPLE language ALL NULL NULL NULL NULL 6 0.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE continent ALL NULL NULL NULL NULL 6 100.00 Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select `test`.`language`.`lang_group` AS `lang_group`,`test`.`language`.`lang` AS `lang`,`test`.`country`.`code` AS `code`,`test`.`country`.`country_group` AS `country_group`,`test`.`continent`.`cont_group` AS `cont_group`,`test`.`continent`.`cont` AS `cont` from `test`.`language` join `test`.`country` join `test`.`continent` where ((`test`.`language`.`lang_group` = `test`.`country`.`country_group`) and isnull(`test`.`country`.`country_group`))
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table language, country, continent;
set use_stat_tables=@save_use_stat_tables;
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
SET SESSION STORAGE_ENGINE=DEFAULT;
......@@ -708,4 +708,40 @@ drop table t1;
set use_stat_tables=@save_use_stat_tables;
--echo #
--echo # Bug mdev-4429: join with range condition whose selectivity == 0
--echo # when optimizer_use_condition_selectivity=3
--echo #
CREATE TABLE language (lang_group INT, lang VARCHAR(16) PRIMARY KEY);
INSERT INTO language VALUES
(1,'Chinese'),(6,'English'),(1,'French'),
(1,'German'),(1,'Italian'),(0,'Japanese');
CREATE TABLE country (code varchar(3) PRIMARY KEY,
country_group INT DEFAULT NULL);
INSERT INTO country VALUES ('USA',3),('FRA',5);
CREATE TABLE continent (cont_group INT, cont varchar(16) PRIMARY KEY);
INSERT INTO continent VALUES
(1,'N.America'),(1,'S.America'),(3,'Australia'),
(4,'Africa'),(5,'Antarctica'),(6,'Eurasia');
SET use_stat_tables=PREFERABLY;
ANALYZE TABLE country, language, continent;
FLUSH TABLES;
SET optimizer_use_condition_selectivity=3;
SELECT * FROM language, country, continent
WHERE country_group = lang_group AND lang_group IS NULL;
EXPLAIN EXTENDED
SELECT * FROM language, country, continent
WHERE country_group = lang_group AND lang_group IS NULL;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table language, country, continent;
set use_stat_tables=@save_use_stat_tables;
......@@ -7174,6 +7174,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
{
if (!(next_field->table->map & rem_tables) && next_field->table != table)
{
if (field->cond_selectivity > 0)
sel/= field->cond_selectivity;
break;
}
......
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