mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed bug #21698: erroneously a field could be replaced by an
equal constant under any circumstances. In fact this substitution can be allowed if the field is not of a type string or if the field reference serves as an argument of a comparison predicate. mysql-test/r/func_str.result: Added test cases for bug #21698. mysql-test/r/heap_hash.result: Adjusted results after the fix for bug #21198. mysql-test/t/func_str.test: Added test cases for bug #21698. sql/item.cc: Fixed bug #21198. Added a method to check whether a field reference can be substituted for a constant equal to the field. This substitution is allowed if the field is not of a type string or if the field reference serves as an argument of a comparison predicate. sql/item.h: Fixed bug #21698. Added a new virtual transformation method for a item 'compile' with two callback function parameters. Added a new virtual method 'subst_argument_checker' to be used as an amnalyzer method. This method is supposed to set its in/out argument to NULL for the nodes where substitution of a string field for a constant is not valid. sql/item_cmpfunc.cc: Fixed bug #21698. Added an implementation of the compile method for class Item_cond. First it processes the Item_cond node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/item_cmpfunc.h: Fixed bug #21698. Added the implementations of 'subst_argument_checker' for the Item_func and Item_cond classes. This method is supposed to set its in/out argument to NULL for the nodes where substitution of a string field for a constant is not valid. Added the declaration of an implementation of the compile method for class Item_cond. First it processes the Item_cond node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/item_func.cc: Fixed bug #21698. Added an implementation of the compile method for class Item_func. First it processes the Item_func node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/item_func.h: Fixed bug #21698. Added the declaration of the implementation of the compile method for class Item_func. First it processes the Item_func node with a callback function and if the latter returns TRUE it proceeds with a transformation performed by another callback function. sql/sql_select.cc: Fixed bug #21698. Limited the conditions at which a field can be substituted a for an equal constant in a formula. This substitution is allowed if the field is not of a type string or if the field reference serves as an argument of a comparison predicate.
This commit is contained in:
@ -1113,4 +1113,39 @@ conv("18383815659218730760",10,10) + 0
|
||||
select "18383815659218730760" + 0;
|
||||
"18383815659218730760" + 0
|
||||
1.8383815659219e+19
|
||||
CREATE TABLE t1 (code varchar(10));
|
||||
INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13');
|
||||
SELECT ASCII(code), code FROM t1 WHERE code='A12';
|
||||
ASCII(code) code
|
||||
97 a12
|
||||
65 A12
|
||||
SELECT ASCII(code), code FROM t1 WHERE code='A12' AND ASCII(code)=65;
|
||||
ASCII(code) code
|
||||
65 A12
|
||||
INSERT INTO t1 VALUES ('a12 '), ('A12 ');
|
||||
SELECT LENGTH(code), code FROM t1 WHERE code='A12';
|
||||
LENGTH(code) code
|
||||
3 a12
|
||||
3 A12
|
||||
4 a12
|
||||
5 A12
|
||||
SELECT LENGTH(code), code FROM t1 WHERE code='A12' AND LENGTH(code)=5;
|
||||
LENGTH(code) code
|
||||
5 A12
|
||||
ALTER TABLE t1 ADD INDEX (code);
|
||||
CREATE TABLE t2 (id varchar(10) PRIMARY KEY);
|
||||
INSERT INTO t2 VALUES ('a11'), ('a12'), ('a13'), ('a14');
|
||||
SELECT * FROM t1 INNER JOIN t2 ON t1.code=t2.id
|
||||
WHERE t2.id='a12' AND (code < 'a00' OR LENGTH(code)=5);
|
||||
code id
|
||||
A12 a12
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 INNER JOIN t2 ON code=id
|
||||
WHERE id='a12' AND (code < 'a00' OR LENGTH(code)=5);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ref code code 13 const 3 Using where; Using index
|
||||
1 SIMPLE t2 ref PRIMARY PRIMARY 12 const 1 Using where; Using index
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (`test`.`t2`.`id` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5))
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.0 tests
|
||||
|
@ -354,7 +354,7 @@ t3 1 a 2 b NULL 13 NULL NULL HASH
|
||||
explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ref heap_idx heap_idx 22 const 7 Using where
|
||||
1 SIMPLE t3 ref a a 44 const,const 7 Using where
|
||||
1 SIMPLE t3 ref a a 44 func,const 7 Using where
|
||||
drop table t1, t2, t3;
|
||||
create temporary table t1 ( a int, index (a) ) engine=memory;
|
||||
insert into t1 values (1),(2),(3),(4),(5);
|
||||
|
@ -753,4 +753,31 @@ select cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2));
|
||||
select conv("18383815659218730760",10,10) + 0;
|
||||
select "18383815659218730760" + 0;
|
||||
|
||||
#
|
||||
# Bug #21698: substitution of a string field for a constant under a function
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (code varchar(10));
|
||||
INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13');
|
||||
|
||||
SELECT ASCII(code), code FROM t1 WHERE code='A12';
|
||||
SELECT ASCII(code), code FROM t1 WHERE code='A12' AND ASCII(code)=65;
|
||||
|
||||
INSERT INTO t1 VALUES ('a12 '), ('A12 ');
|
||||
|
||||
SELECT LENGTH(code), code FROM t1 WHERE code='A12';
|
||||
SELECT LENGTH(code), code FROM t1 WHERE code='A12' AND LENGTH(code)=5;
|
||||
|
||||
ALTER TABLE t1 ADD INDEX (code);
|
||||
CREATE TABLE t2 (id varchar(10) PRIMARY KEY);
|
||||
INSERT INTO t2 VALUES ('a11'), ('a12'), ('a13'), ('a14');
|
||||
|
||||
SELECT * FROM t1 INNER JOIN t2 ON t1.code=t2.id
|
||||
WHERE t2.id='a12' AND (code < 'a00' OR LENGTH(code)=5);
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 INNER JOIN t2 ON code=id
|
||||
WHERE id='a12' AND (code < 'a00' OR LENGTH(code)=5);
|
||||
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
--echo End of 5.0 tests
|
||||
|
Reference in New Issue
Block a user