mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-19600: The optimizer should be able to produce rows=1 estimate for unique index with NULLable columns
Modify best_access_path() to produce rows=1 estimate for null-rejecting lookups on unique NULL keys.
This commit is contained in:
@ -2285,16 +2285,66 @@ INSERT INTO t1 VALUES
|
||||
(1,2),(2,1),(3,3),(4,2),(5,5),
|
||||
(6,3),(7,1),(8,4),(9,3),(10,2);
|
||||
|
||||
CREATE TABLE t2 ( c INT, d INT, UNIQUE KEY(c) );
|
||||
CREATE TABLE t2 ( c INT, d INT, KEY(c) );
|
||||
INSERT INTO t2 VALUES
|
||||
(1,2),(2,1),(3,3),(4,2),(5,5),(6,3),(7,1);
|
||||
|
||||
analyze table t1,t2;
|
||||
explain
|
||||
SELECT a, b, d FROM t1, t2
|
||||
WHERE ( b, d ) IN
|
||||
( SELECT b, d FROM t1, t2 WHERE b = c );
|
||||
SELECT a, b, d FROM t1, t2
|
||||
WHERE ( b, d ) IN
|
||||
( SELECT b, d FROM t1, t2 WHERE b = c );
|
||||
|
||||
DROP TABLE t1, t2;
|
||||
|
||||
--echo # Another testcase for the above that still uses LooseScan:
|
||||
|
||||
create table t0(a int primary key);
|
||||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||
|
||||
create table t10(a int primary key);
|
||||
insert into t10 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C;
|
||||
|
||||
create table t1 (
|
||||
pk int primary key auto_increment,
|
||||
kp1 int,
|
||||
kp2 int,
|
||||
filler char(100),
|
||||
key (kp1, kp2)
|
||||
);
|
||||
|
||||
# 10 groups, each has 10 elements.
|
||||
insert into t1 (kp1, kp2, filler)
|
||||
select
|
||||
A.a, B.a, 'filler-data'
|
||||
from t0 A, t0 B;
|
||||
|
||||
create table t2 (a int, filler char(100), key(a));
|
||||
|
||||
create table t3 (a int);
|
||||
insert into t3 values (1),(2);
|
||||
|
||||
insert into t2
|
||||
select (A.a+1000*B.a)/20, 'filler_data' from t10 A, t0 B;
|
||||
|
||||
analyze table t1,t2,t3;
|
||||
delete from t1 where kp2 in (1,3);
|
||||
|
||||
--echo # Ref + LooseScan on t1:
|
||||
explain select sum(t2.a)
|
||||
from t2,t3
|
||||
where (t3.a,t2.a) in (select kp1,kp2 from t1,t0 where t0.a=2);
|
||||
|
||||
select sum(t2.a)
|
||||
from t2,t3
|
||||
where (t3.a,t2.a) in (select kp1,kp2 from t1,t0 where t0.a=2);
|
||||
|
||||
drop table t0,t10;
|
||||
drop table t1,t2,t3;
|
||||
|
||||
--echo #
|
||||
--echo # BUG#920713: Wrong result (missing rows) with firstmatch+BNL, IN subquery, ...
|
||||
--echo #
|
||||
|
Reference in New Issue
Block a user