1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Fixed bug mdev-4366.

When performing the range analysis for a conjunction the function
calculate_cond_selectivity_for_table should take in to account that
the analysis of some conjuncts may return SEL_ARG::IMPOSSIBLE.
This commit is contained in:
Igor Babaev
2013-04-04 14:11:31 -07:00
parent 50d4d1ca18
commit 4079a5dc3f
4 changed files with 102 additions and 11 deletions

View File

@ -751,10 +751,10 @@ set histogram_size=@save_histogram_size;
set histogram_type=@save_histogram_type;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-4367: join of a merged empty derived table
# Bug mdev-4367: 2-way join with an empty table
# when optimizer_use_condition_selectivity=3
#
SET optimizer_use_condition_selectivity=3;
set optimizer_use_condition_selectivity=3;
CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('j'),('k');
CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM;
@ -764,4 +764,34 @@ SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z');
a b c
DROP TABLE t1,t2,t3;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-4366: impossible condition on an indexed column discovered after
# substitution of constant tables
# with optimizer_use_condition_selectivity=3
#
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES
(1,4), (2,6), (3,3), (4,5);
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES (1), (7);
set optimizer_use_condition_selectivity=1;
EXPLAIN EXTENDED
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
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
Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
1
set optimizer_use_condition_selectivity=3;
EXPLAIN EXTENDED
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
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
Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
1
DROP TABLE t1,t2;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;

View File

@ -758,10 +758,10 @@ set histogram_size=@save_histogram_size;
set histogram_type=@save_histogram_type;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-4367: join of a merged empty derived table
# Bug mdev-4367: 2-way join with an empty table
# when optimizer_use_condition_selectivity=3
#
SET optimizer_use_condition_selectivity=3;
set optimizer_use_condition_selectivity=3;
CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('j'),('k');
CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM;
@ -771,6 +771,36 @@ SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z');
a b c
DROP TABLE t1,t2,t3;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-4366: impossible condition on an indexed column discovered after
# substitution of constant tables
# with optimizer_use_condition_selectivity=3
#
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES
(1,4), (2,6), (3,3), (4,5);
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES (1), (7);
set optimizer_use_condition_selectivity=1;
EXPLAIN EXTENDED
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
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
Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
1
set optimizer_use_condition_selectivity=3;
EXPLAIN EXTENDED
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
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
Warnings:
Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
1
DROP TABLE t1,t2;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
SET SESSION STORAGE_ENGINE=DEFAULT;

View File

@ -337,11 +337,11 @@ set histogram_type=@save_histogram_type;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
--echo #
--echo # Bug mdev-4367: join of a merged empty derived table
--echo # Bug mdev-4367: 2-way join with an empty table
--echo # when optimizer_use_condition_selectivity=3
--echo #
SET optimizer_use_condition_selectivity=3;
set optimizer_use_condition_selectivity=3;
CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('j'),('k');
@ -357,5 +357,32 @@ DROP TABLE t1,t2,t3;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
--echo #
--echo # Bug mdev-4366: impossible condition on an indexed column discovered after
--echo # substitution of constant tables
--echo # with optimizer_use_condition_selectivity=3
--echo #
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES
(1,4), (2,6), (3,3), (4,5);
CREATE TABLE t2 (b int);
INSERT INTO t2 VALUES (1), (7);
set optimizer_use_condition_selectivity=1;
EXPLAIN EXTENDED
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
set optimizer_use_condition_selectivity=3;
EXPLAIN EXTENDED
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
DROP TABLE t1,t2;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;