mirror of
https://github.com/MariaDB/server.git
synced 2025-07-05 12:42:17 +03:00
Fixed bug mdev-4418.
After single row substitutions there might appear new equalities. They should be properly propagated to all AND/OR levels the WHERE condition. It's done now with an additional call of remove_eq_conds().
This commit is contained in:
@ -1649,7 +1649,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where
|
||||
2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(<in_optimizer>(6,<exists>(select `test`.`t3`.`a` from `test`.`t3` where (6 = `test`.`t3`.`a`)))) where 1
|
||||
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(<in_optimizer>(6,<exists>(select `test`.`t3`.`a` from `test`.`t3` where (6 = `test`.`t3`.`a`))))
|
||||
DROP TABLE t1,t2,t3;
|
||||
#
|
||||
# LP bug #817384 Wrong result with outer join + subquery in ON
|
||||
|
@ -1660,7 +1660,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 100.00 Using where
|
||||
2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(<in_optimizer>(6,<exists>(select `test`.`t3`.`a` from `test`.`t3` where (6 = `test`.`t3`.`a`)))) where 1
|
||||
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(<in_optimizer>(6,<exists>(select `test`.`t3`.`a` from `test`.`t3` where (6 = `test`.`t3`.`a`))))
|
||||
DROP TABLE t1,t2,t3;
|
||||
#
|
||||
# LP bug #817384 Wrong result with outer join + subquery in ON
|
||||
|
@ -5217,4 +5217,22 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`
|
||||
SELECT * FROM t1 WHERE (b = 1 OR a = 5) AND (b = 5 AND a = 5 OR 1 != 1);
|
||||
a b
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug mdev-4418: impossible multiple equality in OR formula
|
||||
# after row substitution
|
||||
#
|
||||
CREATE TABLE t1 (a int, b varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (0,'j'), (8,'v');
|
||||
CREATE TABLE t2 (c varchar(1), d varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('k','k');
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,'k' AS `c`,'k' AS `d` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`b` = 'k') and (`test`.`t1`.`a` = 136))
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
a b c d
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.3 tests
|
||||
|
@ -5228,6 +5228,24 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`
|
||||
SELECT * FROM t1 WHERE (b = 1 OR a = 5) AND (b = 5 AND a = 5 OR 1 != 1);
|
||||
a b
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug mdev-4418: impossible multiple equality in OR formula
|
||||
# after row substitution
|
||||
#
|
||||
CREATE TABLE t1 (a int, b varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (0,'j'), (8,'v');
|
||||
CREATE TABLE t2 (c varchar(1), d varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('k','k');
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,'k' AS `c`,'k' AS `d` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`b` = 'k') and (`test`.`t1`.`a` = 136))
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
a b c d
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.3 tests
|
||||
set join_cache_level=default;
|
||||
show variables like 'join_cache_level';
|
||||
|
@ -5217,4 +5217,22 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`
|
||||
SELECT * FROM t1 WHERE (b = 1 OR a = 5) AND (b = 5 AND a = 5 OR 1 != 1);
|
||||
a b
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug mdev-4418: impossible multiple equality in OR formula
|
||||
# after row substitution
|
||||
#
|
||||
CREATE TABLE t1 (a int, b varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (0,'j'), (8,'v');
|
||||
CREATE TABLE t2 (c varchar(1), d varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('k','k');
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,'k' AS `c`,'k' AS `d` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`b` = 'k') and (`test`.`t1`.`a` = 136))
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
a b c d
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.3 tests
|
||||
|
@ -1322,7 +1322,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
Warnings:
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
INSERT INTO t1 (pseudo) VALUES ('test1');
|
||||
SELECT 0 IN (SELECT 1 FROM t1 a);
|
||||
0 IN (SELECT 1 FROM t1 a)
|
||||
|
@ -1329,7 +1329,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
Warnings:
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
INSERT INTO t1 (pseudo) VALUES ('test1');
|
||||
SELECT 0 IN (SELECT 1 FROM t1 a);
|
||||
0 IN (SELECT 1 FROM t1 a)
|
||||
|
@ -1325,7 +1325,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
Warnings:
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
INSERT INTO t1 (pseudo) VALUES ('test1');
|
||||
SELECT 0 IN (SELECT 1 FROM t1 a);
|
||||
0 IN (SELECT 1 FROM t1 a)
|
||||
|
@ -1328,7 +1328,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
Warnings:
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
INSERT INTO t1 (pseudo) VALUES ('test1');
|
||||
SELECT 0 IN (SELECT 1 FROM t1 a);
|
||||
0 IN (SELECT 1 FROM t1 a)
|
||||
|
@ -1325,7 +1325,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
Warnings:
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
|
||||
INSERT INTO t1 (pseudo) VALUES ('test1');
|
||||
SELECT 0 IN (SELECT 1 FROM t1 a);
|
||||
0 IN (SELECT 1 FROM t1 a)
|
||||
|
@ -17,7 +17,7 @@ explain extended select t1.a from t1 left join t2 on t2.a=t1.a;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1`
|
||||
select t1.a from t1 left join t2 on t2.a=t1.a;
|
||||
a
|
||||
0
|
||||
@ -62,7 +62,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t0 ALL NULL NULL NULL NULL 4 100.00
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using where
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t0` left join (`test`.`t1`) on((`test`.`t1`.`a` = `test`.`t0`.`a`)) where 1
|
||||
Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t0` left join (`test`.`t1`) on((`test`.`t1`.`a` = `test`.`t0`.`a`))
|
||||
# Elimination with aggregate functions
|
||||
explain select count(*) from t1 left join t2 on t2.a=t1.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
|
@ -4300,7 +4300,7 @@ WHERE f1<>0 OR f2<>0 AND f4='v' AND (f2<>0 OR f3<>0 AND f5<>0 OR f4 LIKE '%b%');
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00
|
||||
Warnings:
|
||||
Note 1003 select 'r' AS `f4` from `test`.`t1` where ((20 <> 0) or 0)
|
||||
Note 1003 select 'r' AS `f4` from `test`.`t1` where (20 <> 0)
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
#
|
||||
|
@ -4372,4 +4372,21 @@ SELECT * FROM t1 WHERE (b = 1 OR a = 5) AND (b = 5 AND a = 5 OR 1 != 1);
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # Bug mdev-4418: impossible multiple equality in OR formula
|
||||
--echo # after row substitution
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (a int, b varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (0,'j'), (8,'v');
|
||||
|
||||
CREATE TABLE t2 (c varchar(1), d varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('k','k');
|
||||
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
SELECT * FROM t1, t2 WHERE c=b AND (1=2 OR ((b='h' OR a=136) AND d=b));
|
||||
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
--echo End of 5.3 tests
|
||||
|
@ -1210,6 +1210,23 @@ JOIN::optimize()
|
||||
/* Handle the case where we have an OUTER JOIN without a WHERE */
|
||||
conds=new Item_int((longlong) 1,1); // Always true
|
||||
}
|
||||
|
||||
if (const_tables && conds)
|
||||
{
|
||||
conds= remove_eq_conds(thd, conds, &cond_value);
|
||||
if (cond_value == Item::COND_FALSE)
|
||||
{
|
||||
zero_result_cause=
|
||||
"Impossible WHERE noticed after reading const tables";
|
||||
select_lex->mark_const_derived(zero_result_cause);
|
||||
if (select_options & SELECT_DESCRIBE)
|
||||
{
|
||||
conds=new Item_int((longlong) 0,1);
|
||||
}
|
||||
goto setup_subq_exit;
|
||||
}
|
||||
}
|
||||
|
||||
select= make_select(*table, const_table_map,
|
||||
const_table_map, conds, 1, &error);
|
||||
if (error)
|
||||
|
Reference in New Issue
Block a user