mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-15306: Wrong/Unexpected result with the value optimizer_use_condition_selectivity set to 4
Currently for selectivity calculation we perform range analysis for a column even when we don't have any statistics(EITS). This makes less sense but is used to catch contradiction for WHERE condition. So the solution is to not perform range analysis for selectivity calculation for columns that do not have statistics.
This commit is contained in:
@ -789,9 +789,9 @@ set optimizer_use_condition_selectivity=3;
|
||||
explain extended
|
||||
select * from t1 where a < 1 and a > 7;
|
||||
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
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` < 1) and (`test`.`t1`.`a` > 7))
|
||||
select * from t1 where a < 1 and a > 7;
|
||||
a
|
||||
drop table t1;
|
||||
@ -1604,6 +1604,46 @@ drop table t1,t0;
|
||||
set histogram_size=@save_histogram_size;
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
set use_stat_tables=@save_use_stat_tables;
|
||||
#
|
||||
# MDEV-15306: Wrong/Unexpected result with the value
|
||||
# optimizer_use_condition_selectivity set to 4
|
||||
#
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
|
||||
CREATE FUNCTION f1() RETURNS INT DETERMINISTIC
|
||||
BEGIN
|
||||
SET @cnt := @cnt + 1;
|
||||
RETURN 1;
|
||||
END;|
|
||||
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
|
||||
set @save_use_stat_tables= @@use_stat_tables;
|
||||
set @@use_stat_tables='complementary';
|
||||
set @@optimizer_use_condition_selectivity=4;
|
||||
SET @cnt= 0;
|
||||
SELECT * FROM t1 WHERE a = f1();
|
||||
a
|
||||
1
|
||||
SELECT @cnt;
|
||||
@cnt
|
||||
1
|
||||
set @@use_stat_tables='preferably';
|
||||
analyze table t1 persistent for all;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Engine-independent statistics collected
|
||||
test.t1 analyze status OK
|
||||
SET @cnt := 0;
|
||||
set @@optimizer_use_condition_selectivity=4;
|
||||
SELECT * FROM t1 WHERE a = f1();
|
||||
a
|
||||
1
|
||||
SELECT @cnt;
|
||||
@cnt
|
||||
2
|
||||
alter table t1 force;
|
||||
set @@use_stat_tables= @save_use_stat_tables;
|
||||
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
drop table t1;
|
||||
drop function f1;
|
||||
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
|
||||
set @tmp_ust= @@use_stat_tables;
|
||||
set @tmp_oucs= @@optimizer_use_condition_selectivity;
|
||||
|
Reference in New Issue
Block a user