Commit 09a1f410 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-4406.

This bug in the code of get_column_range_cardinality() could lead to
wrong estimates of number of records in ranges for non-nullable columns.  
parent 9441e536
...@@ -1094,4 +1094,38 @@ f1 f2 f2 ...@@ -1094,4 +1094,38 @@ f1 f2 f2
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1,t2; DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4406: range condition for non-nullable column
# when optimizer_use_condition_selectivity=3
#
create table t1 (a int not null);
insert into t1 values
(7), (6), (4), (9), (1), (5), (2), (1), (3), (8);
set use_stat_tables='preferably';
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
set optimizer_use_condition_selectivity=3;
select count(*) from t1 where a between 5 and 7;
count(*)
3
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
alter table t1 change column a a int;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
set use_stat_tables=@save_use_stat_tables;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
...@@ -1102,6 +1102,40 @@ f1 f2 f2 ...@@ -1102,6 +1102,40 @@ f1 f2 f2
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1,t2; DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4406: range condition for non-nullable column
# when optimizer_use_condition_selectivity=3
#
create table t1 (a int not null);
insert into t1 values
(7), (6), (4), (9), (1), (5), (2), (1), (3), (8);
set use_stat_tables='preferably';
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
set optimizer_use_condition_selectivity=3;
select count(*) from t1 where a between 5 and 7;
count(*)
3
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
alter table t1 change column a a int;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
set use_stat_tables=@save_use_stat_tables;
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 optimizer_switch=@save_optimizer_switch_for_selectivity_test;
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -676,5 +676,36 @@ DROP TABLE t1,t2; ...@@ -676,5 +676,36 @@ DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
--echo #
--echo # Bug mdev-4406: range condition for non-nullable column
--echo # when optimizer_use_condition_selectivity=3
--echo #
create table t1 (a int not null);
insert into t1 values
(7), (6), (4), (9), (1), (5), (2), (1), (3), (8);
set use_stat_tables='preferably';
analyze table t1;
flush table t1;
set optimizer_use_condition_selectivity=3;
select count(*) from t1 where a between 5 and 7;
explain extended select * from t1 where a between 5 and 7;
alter table t1 change column a a int;
analyze table t1;
flush table t1;
explain extended select * from t1 where a between 5 and 7;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
set use_stat_tables=@save_use_stat_tables;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
...@@ -3520,7 +3520,7 @@ double get_column_range_cardinality(Field *field, ...@@ -3520,7 +3520,7 @@ double get_column_range_cardinality(Field *field,
{ {
double sel, min_mp_pos, max_mp_pos; double sel, min_mp_pos, max_mp_pos;
if (min_endp && !min_endp->key[0]) if (min_endp && !(field->null_ptr && min_endp->key[0]))
{ {
store_key_image_to_rec(field, (uchar *) min_endp->key, store_key_image_to_rec(field, (uchar *) min_endp->key,
min_endp->length); min_endp->length);
......
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