2003-01-06 00:48:59 +01:00
|
|
|
|
# Initialise
|
|
|
|
|
--disable_warnings
|
BUG#15872: Don't run the range analyzer on "t1.keypart NOT IN (const1, ..., )", as that consumes
too much memory. Instead, either create the equvalent SEL_TREE manually, or create only two ranges that
strictly include the area to scan
(Note: just to re-iterate: increasing NOT_IN_IGNORE_THRESHOLD will make optimization run slower for big
IN-lists, but the server will not run out of memory. O(N^2) memory use has been eliminated)
mysql-test/r/func_in.result:
Testcase for BUG#15872
mysql-test/t/func_in.test:
Testcase for BUG#15872
sql/item.cc:
BUG#15872: Added Item_decimal::set_decimal_value()
sql/item.h:
UG#15872: Added Item_decimal::set_decimal_value()
sql/item_cmpfunc.h:
BUG#15872: Added in_vector::create_item(), in_vector::value_to_item() and their implementations in concrete
classes.
sql/opt_range.cc:
BUG#15872: Don't run the range analyzer on "t1.keypart NOT IN (const1, ..., )", as that
consumes too much memory. Instead, either
A) create the equivalent SEL_TREE manually, making use of the fact that item_not_in->array
has an ordered IN-list, or
B) create only two ranges: (-inf|NULL) < X < min_value_from_in_list, max_value_from_in_list < X
(Choose #B if the IN-list has > 10K elements)
2006-04-25 21:33:31 +02:00
|
|
|
|
drop table if exists t1, t2;
|
2003-01-06 00:48:59 +01:00
|
|
|
|
--enable_warnings
|
2000-12-28 02:56:38 +01:00
|
|
|
|
#
|
|
|
|
|
# test of IN (NULL)
|
|
|
|
|
#
|
|
|
|
|
|
2002-12-06 20:55:53 +01:00
|
|
|
|
select 1 in (1,2,3);
|
|
|
|
|
select 10 in (1,2,3);
|
|
|
|
|
select NULL in (1,2,3);
|
|
|
|
|
select 1 in (1,NULL,3);
|
|
|
|
|
select 3 in (1,NULL,3);
|
|
|
|
|
select 10 in (1,NULL,3);
|
|
|
|
|
select 1.5 in (1.5,2.5,3.5);
|
|
|
|
|
select 10.5 in (1.5,2.5,3.5);
|
|
|
|
|
select NULL in (1.5,2.5,3.5);
|
|
|
|
|
select 1.5 in (1.5,NULL,3.5);
|
|
|
|
|
select 3.5 in (1.5,NULL,3.5);
|
|
|
|
|
select 10.5 in (1.5,NULL,3.5);
|
2003-01-06 00:48:59 +01:00
|
|
|
|
|
2002-12-06 20:55:53 +01:00
|
|
|
|
CREATE TABLE t1 (a int, b int, c int);
|
|
|
|
|
insert into t1 values (1,2,3), (1,NULL,3);
|
|
|
|
|
select 1 in (a,b,c) from t1;
|
|
|
|
|
select 3 in (a,b,c) from t1;
|
|
|
|
|
select 10 in (a,b,c) from t1;
|
|
|
|
|
select NULL in (a,b,c) from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
CREATE TABLE t1 (a float, b float, c float);
|
|
|
|
|
insert into t1 values (1.5,2.5,3.5), (1.5,NULL,3.5);
|
|
|
|
|
select 1.5 in (a,b,c) from t1;
|
|
|
|
|
select 3.5 in (a,b,c) from t1;
|
|
|
|
|
select 10.5 in (a,b,c) from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
CREATE TABLE t1 (a varchar(10), b varchar(10), c varchar(10));
|
|
|
|
|
insert into t1 values ('A','BC','EFD'), ('A',NULL,'EFD');
|
|
|
|
|
select 'A' in (a,b,c) from t1;
|
|
|
|
|
select 'EFD' in (a,b,c) from t1;
|
|
|
|
|
select 'XSFGGHF' in (a,b,c) from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2000-12-28 02:56:38 +01:00
|
|
|
|
CREATE TABLE t1 (field char(1));
|
|
|
|
|
INSERT INTO t1 VALUES ('A'),(NULL);
|
|
|
|
|
SELECT * from t1 WHERE field IN (NULL);
|
|
|
|
|
SELECT * from t1 WHERE field NOT IN (NULL);
|
|
|
|
|
SELECT * from t1 where field = field;
|
|
|
|
|
SELECT * from t1 where field <=> field;
|
|
|
|
|
DELETE FROM t1 WHERE field NOT IN (NULL);
|
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
create table t1 (id int(10) primary key);
|
|
|
|
|
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
|
|
|
select * from t1 where id in (2,5,9);
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2003-07-16 08:29:16 +02:00
|
|
|
|
create table t1 (
|
|
|
|
|
a char(1) character set latin1 collate latin1_general_ci,
|
|
|
|
|
b char(1) character set latin1 collate latin1_swedish_ci,
|
|
|
|
|
c char(1) character set latin1 collate latin1_danish_ci
|
|
|
|
|
);
|
|
|
|
|
insert into t1 values ('A','B','C');
|
|
|
|
|
insert into t1 values ('a','c','c');
|
After merge fixes
Added more DBUG statements
Ensure that we are comparing end space with BINARY strings
Use 'any_db' instead of '' to mean any database. (For HANDLER command)
Only strip ' ' when comparing CHAR, not other space-like characters (like \t)
BitKeeper/deleted/.del-ctype_tis620.result-old~3578ceb0b8284685:
Delete: mysql-test/r/ctype_tis620.result-old
BitKeeper/deleted/.del-ctype_tis620.test-old~ffb1bbd2935d1aba:
Delete: mysql-test/t/ctype_tis620.test-old
client/mysqlbinlog.cc:
Added DBUG statements
Added call of my_end() to free all used memory on exit
heap/hp_info.c:
After merge fixes
heap/hp_open.c:
After merge fixes
include/heap.h:
After merge fixes
include/m_ctype.h:
Use pchar instead of 'int' for character parameters.
Added 'my_binary_compare()'
include/m_string.h:
Fixed wrong define
innobase/ibuf/ibuf0ibuf.c:
After merge fixes
innobase/srv/srv0start.c:
After merge fixes
mysql-test/r/alter_table.result:
Fixed results after merge
mysql-test/r/auto_increment.result:
Fixed results after merge
mysql-test/r/bdb.result:
Fixed results after merge
mysql-test/r/binary.result:
Fixed results after merge
mysql-test/r/create.result:
Fixed results after merge
mysql-test/r/ctype_mb.result:
Fixed results after merge
mysql-test/r/ctype_tis620.result:
Fixed results after merge
mysql-test/r/ctype_utf8.result:
Fixed results after merge
mysql-test/r/delete.result:
Fixed results after merge
mysql-test/r/func_compress.result:
Fixed results after merge
mysql-test/r/func_gconcat.result:
Fixed results after merge
mysql-test/r/func_group.result:
Fixed results after merge
mysql-test/r/func_str.result:
Fixed results after merge
mysql-test/r/innodb.result:
Fixed results after merge
mysql-test/r/insert.result:
Fixed results after merge
mysql-test/r/insert_select.result:
Fixed results after merge
mysql-test/r/key.result:
Fixed results after merge
mysql-test/r/loaddata.result:
Fixed results after merge
mysql-test/r/lock.result:
Fixed results after merge
mysql-test/r/myisam.result:
Fixed results after merge
mysql-test/r/null.result:
Fixed results after merge
mysql-test/r/null_key.result:
Fixed results after merge
mysql-test/r/order_by.result:
Fixed results after merge
mysql-test/r/query_cache.result:
Fixed results after merge
mysql-test/r/range.result:
Fixed results after merge
mysql-test/r/rpl_multi_delete.result:
Fixed results after merge
mysql-test/r/rpl_until.result:
Fixed results after merge
mysql-test/r/subselect.result:
Fixed results after merge
mysql-test/r/subselect_innodb.result:
Fixed results after merge
mysql-test/r/type_blob.result:
Fixed results after merge
mysql-test/r/type_datetime.result:
Fixed results after merge
mysql-test/r/type_decimal.result:
Fixed results after merge
mysql-test/r/type_enum.result:
Fixed results after merge
mysql-test/r/type_float.result:
Fixed results after merge
mysql-test/r/type_ranges.result:
Fixed results after merge
mysql-test/r/type_time.result:
Fixed results after merge
mysql-test/r/type_timestamp.result:
Fixed results after merge
mysql-test/r/type_uint.result:
Fixed results after merge
mysql-test/r/type_year.result:
Fixed results after merge
mysql-test/r/variables.result:
Fixed results after merge
mysql-test/r/warnings.result:
Fixed results after merge
mysql-test/t/case.test:
Fixed shifted error messages
mysql-test/t/create.test:
Fixed shifted error messages
mysql-test/t/ctype_collate.test:
Fixed shifted error messages
mysql-test/t/ctype_tis620.test:
Merge with 4.0 ctype_tis620 test
mysql-test/t/delete.test:
Fixed shifted error messages
mysql-test/t/derived.test:
Fixed shifted error messages
mysql-test/t/fulltext.test:
Fixed shifted error messages
mysql-test/t/func_in.test:
Fixed shifted error messages
mysql-test/t/func_str.test:
Fixed shifted error messages
mysql-test/t/func_test.test:
Fixed shifted error messages
mysql-test/t/grant.test:
Fixed shifted error messages
mysql-test/t/innodb.test:
Change to 4.1 syntax
mysql-test/t/key_cache.test:
Fixed shifted error messages
mysql-test/t/myisam.test:
New test of blob and end space
mysql-test/t/row.test:
Fixed shifted error messages
mysql-test/t/rpl_until.test:
Fixed shifted error messages
mysql-test/t/subselect.test:
Fixed shifted error messages
mysql-test/t/subselect_innodb.test:
Fix test to take into account foreign key constraints
mysql-test/t/union.test:
Fixed shifted error messages
mysql-test/t/user_var.test:
Fixed shifted error messages
mysql-test/t/variables.test:
Fixed shifted error messages
mysys/my_handler.c:
Merge with 4.0 code
sql/ha_heap.cc:
After merge fixes
sql/handler.cc:
After merge fixes
sql/item.cc:
After merge fixes
sql/item_cmpfunc.cc:
Ensure that we are comparing end space with BINARY strings
sql/item_cmpfunc.h:
Ensure that we are comparing end space with BINARY strings
sql/log_event.cc:
More DBUG statements
Ensure that we use all options to LOAD DATA in replication
sql/opt_range.cc:
After merge fixes
sql/sql_db.cc:
After merge fixes
sql/sql_handler.cc:
After merge fixes
Use 'any_db' instead of '' to mean 'no database comparison'
sql/sql_parse.cc:
After merge fixes
sql/sql_select.cc:
After merge fixes
Added function comment for setup_group()
sql/sql_string.cc:
Added stringcmp() for binary comparison.
Added function comments for sortcmp() and stringcmp()
sql/sql_string.h:
Added stringcmp()
sql/sql_table.cc:
After merge fixes
sql/sql_update.cc:
After merge fixes
sql/sql_yacc.yy:
Use 'any_db' instead of '' to mean any database. Using "" causes a 'wrong db name' error.
strings/ctype-big5.c:
Strip only end space, not other space characters.
strings/ctype-bin.c:
Removed some not needed functions.
Added function comments
Don't remove end space in comparisons
Change my_wildcmp_bin() to be 'identical' with other similar code
strings/ctype-czech.c:
Strip only end space, not other space characters.
strings/ctype-gbk.c:
Strip only end space, not other space characters.
strings/ctype-latin1.c:
Strip only end space, not other space characters.
strings/ctype-mb.c:
Strip only end space, not other space characters.
strings/ctype-simple.c:
Strip only end space, not other space characters.
strings/ctype-sjis.c:
Strip only end space, not other space characters.
strings/ctype-tis620.c:
Added usage of my_instr_simple. This needs to be cleaned up!
strings/ctype-utf8.c:
Strip only end space, not other space characters.
strings/ctype-win1250ch.c:
Strip only end space, not other space characters.
Fixed indentation
strings/strto.c:
Code cleanup
2004-02-16 09:03:25 +01:00
|
|
|
|
--error 1267
|
2003-07-16 08:29:16 +02:00
|
|
|
|
select * from t1 where a in (b);
|
2003-08-18 23:08:08 +02:00
|
|
|
|
--error 1270
|
After merge fixes
Added more DBUG statements
Ensure that we are comparing end space with BINARY strings
Use 'any_db' instead of '' to mean any database. (For HANDLER command)
Only strip ' ' when comparing CHAR, not other space-like characters (like \t)
BitKeeper/deleted/.del-ctype_tis620.result-old~3578ceb0b8284685:
Delete: mysql-test/r/ctype_tis620.result-old
BitKeeper/deleted/.del-ctype_tis620.test-old~ffb1bbd2935d1aba:
Delete: mysql-test/t/ctype_tis620.test-old
client/mysqlbinlog.cc:
Added DBUG statements
Added call of my_end() to free all used memory on exit
heap/hp_info.c:
After merge fixes
heap/hp_open.c:
After merge fixes
include/heap.h:
After merge fixes
include/m_ctype.h:
Use pchar instead of 'int' for character parameters.
Added 'my_binary_compare()'
include/m_string.h:
Fixed wrong define
innobase/ibuf/ibuf0ibuf.c:
After merge fixes
innobase/srv/srv0start.c:
After merge fixes
mysql-test/r/alter_table.result:
Fixed results after merge
mysql-test/r/auto_increment.result:
Fixed results after merge
mysql-test/r/bdb.result:
Fixed results after merge
mysql-test/r/binary.result:
Fixed results after merge
mysql-test/r/create.result:
Fixed results after merge
mysql-test/r/ctype_mb.result:
Fixed results after merge
mysql-test/r/ctype_tis620.result:
Fixed results after merge
mysql-test/r/ctype_utf8.result:
Fixed results after merge
mysql-test/r/delete.result:
Fixed results after merge
mysql-test/r/func_compress.result:
Fixed results after merge
mysql-test/r/func_gconcat.result:
Fixed results after merge
mysql-test/r/func_group.result:
Fixed results after merge
mysql-test/r/func_str.result:
Fixed results after merge
mysql-test/r/innodb.result:
Fixed results after merge
mysql-test/r/insert.result:
Fixed results after merge
mysql-test/r/insert_select.result:
Fixed results after merge
mysql-test/r/key.result:
Fixed results after merge
mysql-test/r/loaddata.result:
Fixed results after merge
mysql-test/r/lock.result:
Fixed results after merge
mysql-test/r/myisam.result:
Fixed results after merge
mysql-test/r/null.result:
Fixed results after merge
mysql-test/r/null_key.result:
Fixed results after merge
mysql-test/r/order_by.result:
Fixed results after merge
mysql-test/r/query_cache.result:
Fixed results after merge
mysql-test/r/range.result:
Fixed results after merge
mysql-test/r/rpl_multi_delete.result:
Fixed results after merge
mysql-test/r/rpl_until.result:
Fixed results after merge
mysql-test/r/subselect.result:
Fixed results after merge
mysql-test/r/subselect_innodb.result:
Fixed results after merge
mysql-test/r/type_blob.result:
Fixed results after merge
mysql-test/r/type_datetime.result:
Fixed results after merge
mysql-test/r/type_decimal.result:
Fixed results after merge
mysql-test/r/type_enum.result:
Fixed results after merge
mysql-test/r/type_float.result:
Fixed results after merge
mysql-test/r/type_ranges.result:
Fixed results after merge
mysql-test/r/type_time.result:
Fixed results after merge
mysql-test/r/type_timestamp.result:
Fixed results after merge
mysql-test/r/type_uint.result:
Fixed results after merge
mysql-test/r/type_year.result:
Fixed results after merge
mysql-test/r/variables.result:
Fixed results after merge
mysql-test/r/warnings.result:
Fixed results after merge
mysql-test/t/case.test:
Fixed shifted error messages
mysql-test/t/create.test:
Fixed shifted error messages
mysql-test/t/ctype_collate.test:
Fixed shifted error messages
mysql-test/t/ctype_tis620.test:
Merge with 4.0 ctype_tis620 test
mysql-test/t/delete.test:
Fixed shifted error messages
mysql-test/t/derived.test:
Fixed shifted error messages
mysql-test/t/fulltext.test:
Fixed shifted error messages
mysql-test/t/func_in.test:
Fixed shifted error messages
mysql-test/t/func_str.test:
Fixed shifted error messages
mysql-test/t/func_test.test:
Fixed shifted error messages
mysql-test/t/grant.test:
Fixed shifted error messages
mysql-test/t/innodb.test:
Change to 4.1 syntax
mysql-test/t/key_cache.test:
Fixed shifted error messages
mysql-test/t/myisam.test:
New test of blob and end space
mysql-test/t/row.test:
Fixed shifted error messages
mysql-test/t/rpl_until.test:
Fixed shifted error messages
mysql-test/t/subselect.test:
Fixed shifted error messages
mysql-test/t/subselect_innodb.test:
Fix test to take into account foreign key constraints
mysql-test/t/union.test:
Fixed shifted error messages
mysql-test/t/user_var.test:
Fixed shifted error messages
mysql-test/t/variables.test:
Fixed shifted error messages
mysys/my_handler.c:
Merge with 4.0 code
sql/ha_heap.cc:
After merge fixes
sql/handler.cc:
After merge fixes
sql/item.cc:
After merge fixes
sql/item_cmpfunc.cc:
Ensure that we are comparing end space with BINARY strings
sql/item_cmpfunc.h:
Ensure that we are comparing end space with BINARY strings
sql/log_event.cc:
More DBUG statements
Ensure that we use all options to LOAD DATA in replication
sql/opt_range.cc:
After merge fixes
sql/sql_db.cc:
After merge fixes
sql/sql_handler.cc:
After merge fixes
Use 'any_db' instead of '' to mean 'no database comparison'
sql/sql_parse.cc:
After merge fixes
sql/sql_select.cc:
After merge fixes
Added function comment for setup_group()
sql/sql_string.cc:
Added stringcmp() for binary comparison.
Added function comments for sortcmp() and stringcmp()
sql/sql_string.h:
Added stringcmp()
sql/sql_table.cc:
After merge fixes
sql/sql_update.cc:
After merge fixes
sql/sql_yacc.yy:
Use 'any_db' instead of '' to mean any database. Using "" causes a 'wrong db name' error.
strings/ctype-big5.c:
Strip only end space, not other space characters.
strings/ctype-bin.c:
Removed some not needed functions.
Added function comments
Don't remove end space in comparisons
Change my_wildcmp_bin() to be 'identical' with other similar code
strings/ctype-czech.c:
Strip only end space, not other space characters.
strings/ctype-gbk.c:
Strip only end space, not other space characters.
strings/ctype-latin1.c:
Strip only end space, not other space characters.
strings/ctype-mb.c:
Strip only end space, not other space characters.
strings/ctype-simple.c:
Strip only end space, not other space characters.
strings/ctype-sjis.c:
Strip only end space, not other space characters.
strings/ctype-tis620.c:
Added usage of my_instr_simple. This needs to be cleaned up!
strings/ctype-utf8.c:
Strip only end space, not other space characters.
strings/ctype-win1250ch.c:
Strip only end space, not other space characters.
Fixed indentation
strings/strto.c:
Code cleanup
2004-02-16 09:03:25 +01:00
|
|
|
|
select * from t1 where a in (b,c);
|
|
|
|
|
--error 1271
|
2003-07-16 08:29:16 +02:00
|
|
|
|
select * from t1 where 'a' in (a,b,c);
|
|
|
|
|
select * from t1 where 'a' in (a);
|
|
|
|
|
select * from t1 where a in ('a');
|
|
|
|
|
select * from t1 where 'a' collate latin1_general_ci in (a,b,c);
|
|
|
|
|
select * from t1 where 'a' collate latin1_bin in (a,b,c);
|
|
|
|
|
select * from t1 where 'a' in (a,b,c collate latin1_bin);
|
2003-10-30 11:57:26 +01:00
|
|
|
|
explain extended select * from t1 where 'a' in (a,b,c collate latin1_bin);
|
2003-07-16 08:29:16 +02:00
|
|
|
|
drop table t1;
|
2003-07-18 11:03:54 +02:00
|
|
|
|
|
2004-09-01 12:39:15 +02:00
|
|
|
|
set names utf8;
|
|
|
|
|
create table t1 (a char(10) character set utf8 not null);
|
|
|
|
|
insert into t1 values ('bbbb'),(_koi8r'<27><><EFBFBD><EFBFBD>'),(_latin1'<27><><EFBFBD><EFBFBD>');
|
|
|
|
|
select a from t1 where a in ('bbbb',_koi8r'<27><><EFBFBD><EFBFBD>',_latin1'<27><><EFBFBD><EFBFBD>') order by a;
|
|
|
|
|
drop table t1;
|
2005-01-20 12:38:56 +01:00
|
|
|
|
# Bug#7834 Illegal mix of collations in IN operator
|
|
|
|
|
create table t1 (a char(10) character set latin1 not null);
|
|
|
|
|
insert into t1 values ('a'),('b'),('c');
|
|
|
|
|
select a from t1 where a IN ('a','b','c') order by a;
|
|
|
|
|
drop table t1;
|
2004-09-01 12:39:15 +02:00
|
|
|
|
set names latin1;
|
|
|
|
|
|
2003-07-18 11:03:54 +02:00
|
|
|
|
select '1.0' in (1,2);
|
|
|
|
|
select 1 in ('1.0',2);
|
|
|
|
|
select 1 in (1,'2.0');
|
|
|
|
|
select 1 in ('1.0',2.0);
|
|
|
|
|
select 1 in (1.0,'2.0');
|
|
|
|
|
select 1 in ('1.1',2);
|
|
|
|
|
select 1 in ('1.1',2.0);
|
2004-11-05 05:39:52 +01:00
|
|
|
|
|
|
|
|
|
# Test case for bug #6365
|
|
|
|
|
|
2005-10-13 16:16:19 +02:00
|
|
|
|
create table t1 (a char(2) character set binary);
|
2004-11-05 05:39:52 +01:00
|
|
|
|
insert into t1 values ('aa'), ('bb');
|
|
|
|
|
select * from t1 where a in (NULL, 'aa');
|
|
|
|
|
drop table t1;
|
2005-07-17 03:06:34 +02:00
|
|
|
|
|
2005-09-23 11:43:20 +02:00
|
|
|
|
# BUG#13419
|
|
|
|
|
create table t1 (id int, key(id));
|
|
|
|
|
insert into t1 values (1),(2),(3);
|
|
|
|
|
select count(*) from t1 where id not in (1);
|
|
|
|
|
select count(*) from t1 where id not in (1,2);
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2006-11-16 11:21:38 +01:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# BUG#17047: CHAR() and IN() can return NULL without signaling NULL
|
|
|
|
|
# result
|
|
|
|
|
#
|
|
|
|
|
# The problem was in the IN() function that ignored maybe_null flags
|
|
|
|
|
# of all arguments except the first (the one _before_ the IN
|
|
|
|
|
# keyword, '1' in the test case below).
|
|
|
|
|
#
|
|
|
|
|
--disable_warnings
|
|
|
|
|
DROP TABLE IF EXISTS t1;
|
|
|
|
|
--enable_warnings
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 SELECT 1 IN (2, NULL);
|
|
|
|
|
--echo SELECT should return NULL.
|
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--echo End of 4.1 tests
|
2006-11-16 11:25:55 +01:00
|
|
|
|
|
2005-07-28 16:09:54 +02:00
|
|
|
|
|
2005-07-17 03:06:34 +02:00
|
|
|
|
#
|
|
|
|
|
# Bug #11885: WHERE condition with NOT IN (one element)
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 (a int PRIMARY KEY);
|
|
|
|
|
INSERT INTO t1 VALUES (44), (45), (46);
|
|
|
|
|
|
|
|
|
|
SELECT * FROM t1 WHERE a IN (45);
|
|
|
|
|
SELECT * FROM t1 WHERE a NOT IN (0, 45);
|
|
|
|
|
SELECT * FROM t1 WHERE a NOT IN (45);
|
|
|
|
|
|
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a NOT IN (45);
|
|
|
|
|
SHOW CREATE VIEW v1;
|
|
|
|
|
SELECT * FROM v1;
|
|
|
|
|
|
|
|
|
|
DROP VIEW v1;
|
|
|
|
|
DROP TABLE t1;
|
BUG#15872: Don't run the range analyzer on "t1.keypart NOT IN (const1, ..., )", as that consumes
too much memory. Instead, either create the equvalent SEL_TREE manually, or create only two ranges that
strictly include the area to scan
(Note: just to re-iterate: increasing NOT_IN_IGNORE_THRESHOLD will make optimization run slower for big
IN-lists, but the server will not run out of memory. O(N^2) memory use has been eliminated)
mysql-test/r/func_in.result:
Testcase for BUG#15872
mysql-test/t/func_in.test:
Testcase for BUG#15872
sql/item.cc:
BUG#15872: Added Item_decimal::set_decimal_value()
sql/item.h:
UG#15872: Added Item_decimal::set_decimal_value()
sql/item_cmpfunc.h:
BUG#15872: Added in_vector::create_item(), in_vector::value_to_item() and their implementations in concrete
classes.
sql/opt_range.cc:
BUG#15872: Don't run the range analyzer on "t1.keypart NOT IN (const1, ..., )", as that
consumes too much memory. Instead, either
A) create the equivalent SEL_TREE manually, making use of the fact that item_not_in->array
has an ordered IN-list, or
B) create only two ranges: (-inf|NULL) < X < min_value_from_in_list, max_value_from_in_list < X
(Choose #B if the IN-list has > 10K elements)
2006-04-25 21:33:31 +02:00
|
|
|
|
|
|
|
|
|
# BUG#15872: Excessive memory consumption of range analysis of NOT IN
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
|
|
|
create table t2 (a int, filler char(200), key(a));
|
|
|
|
|
|
|
|
|
|
insert into t2 select C.a*2, 'no' from t1 A, t1 B, t1 C;
|
|
|
|
|
insert into t2 select C.a*2+1, 'yes' from t1 C;
|
|
|
|
|
|
|
|
|
|
explain
|
|
|
|
|
select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18);
|
|
|
|
|
select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18);
|
|
|
|
|
|
|
|
|
|
explain select * from t2 force index(a) where a NOT IN (2,2,2,2,2,2);
|
|
|
|
|
explain select * from t2 force index(a) where a <> 2;
|
|
|
|
|
|
|
|
|
|
drop table t2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Repeat the test for DATETIME
|
|
|
|
|
#
|
|
|
|
|
create table t2 (a datetime, filler char(200), key(a));
|
|
|
|
|
|
|
|
|
|
insert into t2 select '2006-04-25 10:00:00' + interval C.a minute,
|
|
|
|
|
'no' from t1 A, t1 B, t1 C where C.a % 2 = 0;
|
|
|
|
|
|
|
|
|
|
insert into t2 select '2006-04-25 10:00:00' + interval C.a*2+1 minute,
|
|
|
|
|
'yes' from t1 C;
|
|
|
|
|
|
|
|
|
|
explain
|
|
|
|
|
select * from t2 where a NOT IN (
|
|
|
|
|
'2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00',
|
|
|
|
|
'2006-04-25 10:06:00', '2006-04-25 10:08:00');
|
|
|
|
|
select * from t2 where a NOT IN (
|
|
|
|
|
'2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00',
|
|
|
|
|
'2006-04-25 10:06:00', '2006-04-25 10:08:00');
|
|
|
|
|
drop table t2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Repeat the test for CHAR(N)
|
|
|
|
|
#
|
|
|
|
|
create table t2 (a varchar(10), filler char(200), key(a));
|
|
|
|
|
|
|
|
|
|
insert into t2 select 'foo', 'no' from t1 A, t1 B;
|
|
|
|
|
insert into t2 select 'barbar', 'no' from t1 A, t1 B;
|
|
|
|
|
insert into t2 select 'bazbazbaz', 'no' from t1 A, t1 B;
|
|
|
|
|
|
|
|
|
|
insert into t2 values ('fon', '1'), ('fop','1'), ('barbaq','1'),
|
|
|
|
|
('barbas','1'), ('bazbazbay', '1'),('zz','1');
|
|
|
|
|
|
|
|
|
|
explain select * from t2 where a not in('foo','barbar', 'bazbazbaz');
|
|
|
|
|
|
|
|
|
|
drop table t2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Repeat for DECIMAL
|
|
|
|
|
#
|
|
|
|
|
create table t2 (a decimal(10,5), filler char(200), key(a));
|
|
|
|
|
|
|
|
|
|
insert into t2 select 345.67890, 'no' from t1 A, t1 B;
|
|
|
|
|
insert into t2 select 43245.34, 'no' from t1 A, t1 B;
|
|
|
|
|
insert into t2 select 64224.56344, 'no' from t1 A, t1 B;
|
|
|
|
|
|
|
|
|
|
insert into t2 values (0, '1'), (22334.123,'1'), (33333,'1'),
|
|
|
|
|
(55555,'1'), (77777, '1');
|
|
|
|
|
|
|
|
|
|
explain
|
|
|
|
|
select * from t2 where a not in (345.67890, 43245.34, 64224.56344);
|
|
|
|
|
select * from t2 where a not in (345.67890, 43245.34, 64224.56344);
|
|
|
|
|
|
|
|
|
|
drop table t2;
|
|
|
|
|
|
|
|
|
|
# Try a very big IN-list
|
|
|
|
|
create table t2 (a int, key(a), b int);
|
|
|
|
|
insert into t2 values (1,1),(2,2);
|
|
|
|
|
|
|
|
|
|
set @cnt= 1;
|
|
|
|
|
set @str="update t2 set b=1 where a not in (";
|
|
|
|
|
select count(*) from (
|
|
|
|
|
select @str:=concat(@str, @cnt:=@cnt+1, ",")
|
|
|
|
|
from t1 A, t1 B, t1 C, t1 D) Z;
|
|
|
|
|
|
|
|
|
|
set @str:=concat(@str, "10000)");
|
|
|
|
|
select substr(@str, 1, 50);
|
|
|
|
|
prepare s from @str;
|
|
|
|
|
execute s;
|
|
|
|
|
deallocate prepare s;
|
|
|
|
|
set @str=NULL;
|
|
|
|
|
|
|
|
|
|
drop table t2;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2006-05-15 12:18:23 +02:00
|
|
|
|
# BUG#19618: Crash in range optimizer for
|
|
|
|
|
# "unsigned_keypart NOT IN(negative_number,...)"
|
|
|
|
|
# (introduced in fix BUG#15872)
|
|
|
|
|
create table t1 (
|
|
|
|
|
some_id smallint(5) unsigned,
|
|
|
|
|
key (some_id)
|
|
|
|
|
);
|
|
|
|
|
insert into t1 values (1),(2);
|
|
|
|
|
select some_id from t1 where some_id not in(2,-1);
|
|
|
|
|
select some_id from t1 where some_id not in(-4,-1,-4);
|
|
|
|
|
select some_id from t1 where some_id not in(-4,-1,3423534,2342342);
|
2006-11-27 17:12:10 +01:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# BUG#24261: crash when WHERE contains NOT IN ('<negative value>') for unsigned column type
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
select some_id from t1 where some_id not in('-1', '0');
|
|
|
|
|
|
2006-05-15 12:18:23 +02:00
|
|
|
|
drop table t1;
|
2006-09-26 18:52:54 +02:00
|
|
|
|
|
2007-01-15 18:15:52 +01:00
|
|
|
|
#
|
2007-02-16 12:56:06 +01:00
|
|
|
|
# BUG#20420: optimizer reports wrong keys on left join with IN
|
2007-01-15 18:15:52 +01:00
|
|
|
|
#
|
2007-02-16 12:56:06 +01:00
|
|
|
|
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a));
|
|
|
|
|
INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t2 (a int, b int, PRIMARY KEY (a));
|
|
|
|
|
INSERT INTO t2 VALUES (3,2),(4,2),(100,100),(101,201),(102,102);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t3 (a int PRIMARY KEY);
|
|
|
|
|
INSERT INTO t3 VALUES (1),(2),(3),(4);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t4 (a int PRIMARY KEY,b int);
|
|
|
|
|
INSERT INTO t4 VALUES (1,1),(2,2),(1000,1000),(1001,1001),(1002,1002),
|
|
|
|
|
(1003,1003),(1004,1004);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT STRAIGHT_JOIN * FROM t3
|
|
|
|
|
JOIN t1 ON t3.a=t1.a
|
|
|
|
|
JOIN t2 ON t3.a=t2.a
|
|
|
|
|
JOIN t4 WHERE t4.a IN (t1.b, t2.b);
|
|
|
|
|
|
|
|
|
|
SELECT STRAIGHT_JOIN * FROM t3
|
|
|
|
|
JOIN t1 ON t3.a=t1.a
|
|
|
|
|
JOIN t2 ON t3.a=t2.a
|
|
|
|
|
JOIN t4 WHERE t4.a IN (t1.b, t2.b);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT STRAIGHT_JOIN
|
|
|
|
|
(SELECT SUM(t4.a) FROM t4 WHERE t4.a IN (t1.b, t2.b))
|
|
|
|
|
FROM t3, t1, t2
|
|
|
|
|
WHERE t3.a=t1.a AND t3.a=t2.a;
|
|
|
|
|
|
|
|
|
|
SELECT STRAIGHT_JOIN
|
|
|
|
|
(SELECT SUM(t4.a) FROM t4 WHERE t4.a IN (t1.b, t2.b))
|
|
|
|
|
FROM t3, t1, t2
|
|
|
|
|
WHERE t3.a=t1.a AND t3.a=t2.a;
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1,t2,t3,t4;
|
2006-11-16 11:25:55 +01:00
|
|
|
|
|
2007-03-02 15:25:56 +01:00
|
|
|
|
#
|
|
|
|
|
# BUG#19342: IN works incorrectly for BIGINT UNSIGNED values
|
|
|
|
|
#
|
|
|
|
|
CREATE TABLE t1(a BIGINT UNSIGNED);
|
|
|
|
|
INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF);
|
|
|
|
|
|
|
|
|
|
SELECT * FROM t1 WHERE a=-1 OR a=-2 ;
|
|
|
|
|
SELECT * FROM t1 WHERE a IN (-1, -2);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t2 (a BIGINT UNSIGNED);
|
|
|
|
|
insert into t2 values(13491727406643098568),
|
|
|
|
|
(0x7fffffefffffffff),
|
|
|
|
|
(0x7ffffffeffffffff),
|
|
|
|
|
(0x7fffffffefffffff),
|
|
|
|
|
(0x7ffffffffeffffff),
|
|
|
|
|
(0x7fffffffffefffff),
|
|
|
|
|
(0x7ffffffffffeffff),
|
|
|
|
|
(0x7fffffffffffefff),
|
|
|
|
|
(0x7ffffffffffffeff),
|
|
|
|
|
(0x7fffffffffffffef),
|
|
|
|
|
(0x7ffffffffffffffe),
|
|
|
|
|
(0x7fffffffffffffff),
|
|
|
|
|
(0x8000000000000000),
|
|
|
|
|
(0x8000000000000001),
|
|
|
|
|
(0x8000000000000002),
|
|
|
|
|
(0x8000000000000300),
|
|
|
|
|
(0x8000000000000400),
|
|
|
|
|
(0x8000000000000401),
|
|
|
|
|
(0x8000000000004001),
|
|
|
|
|
(0x8000000000040001),
|
|
|
|
|
(0x8000000000400001),
|
|
|
|
|
(0x8000000004000001),
|
|
|
|
|
(0x8000000040000001),
|
|
|
|
|
(0x8000000400000001),
|
|
|
|
|
(0x8000004000000001),
|
|
|
|
|
(0x8000040000000001);
|
|
|
|
|
|
2007-06-09 14:13:33 +02:00
|
|
|
|
SELECT HEX(a) FROM t2 WHERE a IN
|
|
|
|
|
(CAST(0xBB3C3E98175D33C8 AS UNSIGNED),
|
|
|
|
|
42);
|
2007-03-02 15:25:56 +01:00
|
|
|
|
|
|
|
|
|
SELECT HEX(a) FROM t2 WHERE a IN
|
2007-06-09 14:13:33 +02:00
|
|
|
|
(CAST(0xBB3C3E98175D33C8 AS UNSIGNED),
|
|
|
|
|
CAST(0x7fffffffffffffff AS UNSIGNED),
|
|
|
|
|
CAST(0x8000000000000000 AS UNSIGNED),
|
|
|
|
|
CAST(0x8000000000000400 AS UNSIGNED),
|
|
|
|
|
CAST(0x8000000000000401 AS UNSIGNED),
|
|
|
|
|
42);
|
|
|
|
|
|
|
|
|
|
SELECT HEX(a) FROM t2 WHERE a IN
|
|
|
|
|
(CAST(0x7fffffffffffffff AS UNSIGNED),
|
|
|
|
|
CAST(0x8000000000000001 AS UNSIGNED));
|
|
|
|
|
SELECT HEX(a) FROM t2 WHERE a IN
|
|
|
|
|
(CAST(0x7ffffffffffffffe AS UNSIGNED),
|
|
|
|
|
CAST(0x7fffffffffffffff AS UNSIGNED));
|
2022-06-09 05:32:51 +02:00
|
|
|
|
#view protocol generates additional warning
|
|
|
|
|
--disable_view_protocol
|
2007-06-09 14:13:33 +02:00
|
|
|
|
SELECT HEX(a) FROM t2 WHERE a IN
|
|
|
|
|
(0x7ffffffffffffffe,
|
|
|
|
|
0x7fffffffffffffff,
|
|
|
|
|
'abc');
|
2007-03-02 15:25:56 +01:00
|
|
|
|
|
|
|
|
|
CREATE TABLE t3 (a BIGINT UNSIGNED);
|
|
|
|
|
INSERT INTO t3 VALUES (9223372036854775551);
|
|
|
|
|
|
|
|
|
|
SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);
|
|
|
|
|
|
2007-03-06 17:52:00 +01:00
|
|
|
|
CREATE TABLE t4 (a DATE);
|
|
|
|
|
INSERT INTO t4 VALUES ('1972-02-06'), ('1972-07-29');
|
|
|
|
|
SELECT * FROM t4 WHERE a IN ('1972-02-06','19772-07-29');
|
|
|
|
|
|
2022-06-09 05:32:51 +02:00
|
|
|
|
--enable_view_protocol
|
|
|
|
|
|
2007-03-06 17:52:00 +01:00
|
|
|
|
DROP TABLE t1,t2,t3,t4;
|
2007-03-02 15:25:56 +01:00
|
|
|
|
|
2007-03-22 08:05:36 +01:00
|
|
|
|
#
|
|
|
|
|
# BUG#27362: IN with a decimal expression that may return NULL
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 (id int not null);
|
|
|
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
|
|
|
|
|
|
|
|
SELECT id FROM t1 WHERE id IN(4564, (SELECT IF(1=0,1,1/0)) );
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
2006-11-16 11:25:55 +01:00
|
|
|
|
--echo End of 5.0 tests
|
2006-11-16 12:13:03 +01:00
|
|
|
|
|
|
|
|
|
|
2006-09-26 18:52:54 +02:00
|
|
|
|
#
|
|
|
|
|
# Bug#18360: Type aggregation for IN and CASE may lead to a wrong result
|
|
|
|
|
#
|
|
|
|
|
create table t1(f1 char(1));
|
|
|
|
|
insert into t1 values ('a'),('b'),('1');
|
|
|
|
|
select f1 from t1 where f1 in ('a',1);
|
|
|
|
|
select f1, case f1 when 'a' then '+' when 1 then '-' end from t1;
|
|
|
|
|
create index t1f1_idx on t1(f1);
|
|
|
|
|
select f1 from t1 where f1 in ('a',1);
|
|
|
|
|
explain select f1 from t1 where f1 in ('a',1);
|
|
|
|
|
select f1 from t1 where f1 in ('a','b');
|
|
|
|
|
explain select f1 from t1 where f1 in ('a','b');
|
|
|
|
|
select f1 from t1 where f1 in (2,1);
|
|
|
|
|
explain select f1 from t1 where f1 in (2,1);
|
|
|
|
|
create table t2(f2 int, index t2f2(f2));
|
|
|
|
|
insert into t2 values(0),(1),(2);
|
|
|
|
|
select f2 from t2 where f2 in ('a',2);
|
|
|
|
|
explain select f2 from t2 where f2 in ('a',2);
|
2022-06-09 05:32:51 +02:00
|
|
|
|
#view protocol generates additional warning
|
|
|
|
|
--disable_view_protocol
|
2006-09-26 18:52:54 +02:00
|
|
|
|
select f2 from t2 where f2 in ('a','b');
|
|
|
|
|
explain select f2 from t2 where f2 in ('a','b');
|
2022-06-09 05:32:51 +02:00
|
|
|
|
--enable_view_protocol
|
2006-09-26 18:52:54 +02:00
|
|
|
|
select f2 from t2 where f2 in (1,'b');
|
|
|
|
|
explain select f2 from t2 where f2 in (1,'b');
|
|
|
|
|
drop table t1, t2;
|
2006-11-16 12:13:03 +01:00
|
|
|
|
|
2007-09-26 12:45:08 +02:00
|
|
|
|
#
|
|
|
|
|
# Bug #31075: crash in get_func_mm_tree
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
create table t1 (a time, key(a));
|
|
|
|
|
insert into t1 values (),(),(),(),(),(),(),(),(),();
|
|
|
|
|
select a from t1 where a not in (a,a,a) group by a;
|
|
|
|
|
drop table t1;
|
2006-11-16 12:13:03 +01:00
|
|
|
|
|
2008-07-14 11:06:49 +02:00
|
|
|
|
#
|
|
|
|
|
# Bug #37761: IN handles NULL differently for table-subquery and value-list
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
create table t1 (id int);
|
|
|
|
|
select * from t1 where NOT id in (select null union all select 1);
|
|
|
|
|
select * from t1 where NOT id in (null, 1);
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2008-12-31 12:55:04 +01:00
|
|
|
|
#
|
|
|
|
|
# Bug #41363: crash of mysqld on windows with aggregate in case
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1(c0 INTEGER, c1 INTEGER, c2 INTEGER);
|
|
|
|
|
INSERT INTO t1 VALUES(1, 1, 1), (1, 1, 1);
|
|
|
|
|
|
|
|
|
|
SELECT CASE AVG (c0) WHEN c1 * c2 THEN 1 END FROM t1;
|
|
|
|
|
SELECT CASE c1 * c2 WHEN SUM(c0) THEN 1 WHEN AVG(c0) THEN 2 END FROM t1;
|
|
|
|
|
SELECT CASE c1 WHEN c1 + 1 THEN 1 END, ABS(AVG(c0)) FROM t1;
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
2009-05-25 10:00:40 +02:00
|
|
|
|
#
|
|
|
|
|
# Bug #44399: crash with statement using TEXT columns, aggregates, GROUP BY,
|
|
|
|
|
# and HAVING
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1(a TEXT, b INT, c INT UNSIGNED, d DECIMAL(12,2), e REAL);
|
|
|
|
|
INSERT INTO t1 VALUES('iynfj', 1, 1, 1, 1);
|
|
|
|
|
INSERT INTO t1 VALUES('innfj', 2, 2, 2, 2);
|
|
|
|
|
SELECT SUM( DISTINCT a ) FROM t1 GROUP BY a HAVING a IN ( AVG( 1 ), 1 + a);
|
|
|
|
|
SELECT SUM( DISTINCT b ) FROM t1 GROUP BY b HAVING b IN ( AVG( 1 ), 1 + b);
|
|
|
|
|
SELECT SUM( DISTINCT c ) FROM t1 GROUP BY c HAVING c IN ( AVG( 1 ), 1 + c);
|
|
|
|
|
SELECT SUM( DISTINCT d ) FROM t1 GROUP BY d HAVING d IN ( AVG( 1 ), 1 + d);
|
|
|
|
|
SELECT SUM( DISTINCT e ) FROM t1 GROUP BY e HAVING e IN ( AVG( 1 ), 1 + e);
|
|
|
|
|
SELECT SUM( DISTINCT e ) FROM t1 GROUP BY b,c,d HAVING (b,c,d) IN
|
|
|
|
|
((AVG( 1 ), 1 + c, 1 + d), (AVG( 1 ), 2 + c, 2 + d));
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
Bug #44139: Table scan when NULL appears in IN clause
SELECT ... WHERE ... IN (NULL, ...) does full table scan,
even if the same query without the NULL uses efficient range scan.
The bugfix for the bug 18360 introduced an optimization:
if
1) all right-hand arguments of the IN function are constants
2) result types of all right argument items are compatible
enough to use the same single comparison function to
compare all of them to the left argument,
then
we can convert the right-hand list of constant items to an array
of equally-typed constant values for the further
QUICK index access etc. (see Item_func_in::fix_length_and_dec()).
The Item_null constant item objects have STRING_RESULT
result types, so, as far as Item_func_in::fix_length_and_dec()
is aware of NULLs in the right list, this improvement efficiently
optimizes IN function calls with a mixed right list of NULLs and
string constants. However, the optimization doesn't affect mixed
lists of NULLs and integers, floats etc., because there is no
unique common comparator.
New optimization has been added to ignore the result type
of NULL constants in the static analysis of mixed right-hand lists.
This is safe, because at the execution phase we care about
presence of NULLs anyway.
1. The collect_cmp_types() function has been modified to optionally
ignore NULL constants in the item list.
2. NULL-skipping code of the Item_func_in::fix_length_and_dec()
function has been modified to work not only with in_string
vectors but with in_vectors of other types.
mysql-test/r/func_in.result:
Added test case for the bug #44139.
mysql-test/t/func_in.test:
Added test case for the bug #44139.
sql/item_cmpfunc.cc:
Bug #44139: Table scan when NULL appears in IN clause
1. The collect_cmp_types() function has been modified to optionally
ignore NULL constants in the item list.
2. NULL-skipping code of the Item_func_in::fix_length_and_dec()
function has been modified to work not only with in_string
vectors but with in_vectors of other types.
2009-10-05 07:27:36 +02:00
|
|
|
|
--echo #
|
|
|
|
|
--echo # Bug #44139: Table scan when NULL appears in IN clause
|
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
--disable_warnings
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 (
|
|
|
|
|
c_int INT NOT NULL,
|
|
|
|
|
c_decimal DECIMAL(5,2) NOT NULL,
|
|
|
|
|
c_float FLOAT(5, 2) NOT NULL,
|
|
|
|
|
c_bit BIT(10) NOT NULL,
|
|
|
|
|
c_date DATE NOT NULL,
|
|
|
|
|
c_datetime DATETIME NOT NULL,
|
|
|
|
|
c_timestamp TIMESTAMP NOT NULL,
|
|
|
|
|
c_time TIME NOT NULL,
|
|
|
|
|
c_year YEAR NOT NULL,
|
|
|
|
|
c_char CHAR(10) NOT NULL,
|
|
|
|
|
INDEX(c_int), INDEX(c_decimal), INDEX(c_float), INDEX(c_bit), INDEX(c_date),
|
|
|
|
|
INDEX(c_datetime), INDEX(c_timestamp), INDEX(c_time), INDEX(c_year),
|
|
|
|
|
INDEX(c_char));
|
|
|
|
|
|
2017-02-08 21:28:00 +01:00
|
|
|
|
INSERT IGNORE INTO t1 (c_int) VALUES (1), (2), (3), (4), (5);
|
|
|
|
|
INSERT IGNORE INTO t1 (c_int) SELECT 0 FROM t1;
|
|
|
|
|
INSERT IGNORE INTO t1 (c_int) SELECT 0 FROM t1;
|
Bug #44139: Table scan when NULL appears in IN clause
SELECT ... WHERE ... IN (NULL, ...) does full table scan,
even if the same query without the NULL uses efficient range scan.
The bugfix for the bug 18360 introduced an optimization:
if
1) all right-hand arguments of the IN function are constants
2) result types of all right argument items are compatible
enough to use the same single comparison function to
compare all of them to the left argument,
then
we can convert the right-hand list of constant items to an array
of equally-typed constant values for the further
QUICK index access etc. (see Item_func_in::fix_length_and_dec()).
The Item_null constant item objects have STRING_RESULT
result types, so, as far as Item_func_in::fix_length_and_dec()
is aware of NULLs in the right list, this improvement efficiently
optimizes IN function calls with a mixed right list of NULLs and
string constants. However, the optimization doesn't affect mixed
lists of NULLs and integers, floats etc., because there is no
unique common comparator.
New optimization has been added to ignore the result type
of NULL constants in the static analysis of mixed right-hand lists.
This is safe, because at the execution phase we care about
presence of NULLs anyway.
1. The collect_cmp_types() function has been modified to optionally
ignore NULL constants in the item list.
2. NULL-skipping code of the Item_func_in::fix_length_and_dec()
function has been modified to work not only with in_string
vectors but with in_vectors of other types.
mysql-test/r/func_in.result:
Added test case for the bug #44139.
mysql-test/t/func_in.test:
Added test case for the bug #44139.
sql/item_cmpfunc.cc:
Bug #44139: Table scan when NULL appears in IN clause
1. The collect_cmp_types() function has been modified to optionally
ignore NULL constants in the item list.
2. NULL-skipping code of the Item_func_in::fix_length_and_dec()
function has been modified to work not only with in_string
vectors but with in_vectors of other types.
2009-10-05 07:27:36 +02:00
|
|
|
|
|
|
|
|
|
--enable_warnings
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_int IN (1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_int IN (NULL, 1, 2, 3);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_int IN (1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_int IN (1, NULL, 2, NULL, 3, NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_int IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_int IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (NULL, 1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_float IN (1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_float IN (NULL, 1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_float IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_float IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_bit IN (1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_bit IN (NULL, 1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_bit IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_bit IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_date
|
|
|
|
|
IN ('2009-09-01', '2009-09-02', '2009-09-03');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_date
|
|
|
|
|
IN (NULL, '2009-09-01', '2009-09-02', '2009-09-03');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_date IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_date IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_datetime
|
|
|
|
|
IN ('2009-09-01 00:00:01', '2009-09-02 00:00:01', '2009-09-03 00:00:01');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_datetime
|
|
|
|
|
IN (NULL, '2009-09-01 00:00:01', '2009-09-02 00:00:01', '2009-09-03 00:00:01');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_datetime IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_datetime IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_timestamp
|
|
|
|
|
IN ('2009-09-01 00:00:01', '2009-09-01 00:00:02', '2009-09-01 00:00:03');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_timestamp
|
|
|
|
|
IN (NULL, '2009-09-01 00:00:01', '2009-09-01 00:00:02', '2009-09-01 00:00:03');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_timestamp IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_timestamp IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_year IN (1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_year IN (NULL, 1, 2, 3);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_year IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_year IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_char IN ('1', '2', '3');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_char IN (NULL, '1', '2', '3');
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_char IN (NULL);
|
|
|
|
|
EXPLAIN SELECT * FROM t1 WHERE c_char IN (NULL, NULL);
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
2010-06-22 20:53:08 +02:00
|
|
|
|
--echo #
|
|
|
|
|
--echo # Bug#54477: Crash on IN / CASE with NULL arguments
|
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
|
|
|
INSERT INTO t1 VALUES (1), (2);
|
|
|
|
|
|
|
|
|
|
SELECT 1 IN (NULL, a) FROM t1;
|
|
|
|
|
|
|
|
|
|
SELECT a IN (a, a) FROM t1 GROUP BY a WITH ROLLUP;
|
|
|
|
|
|
|
|
|
|
SELECT CASE a WHEN a THEN a END FROM t1 GROUP BY a WITH ROLLUP;
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
2011-04-12 11:51:36 +02:00
|
|
|
|
--echo #
|
|
|
|
|
--echo # Bug #11766212 59270: NOT IN (YEAR( ... ), ... ) PRODUCES MANY VALGRIND WARNINGS
|
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
SELECT 1 IN (YEAR(FROM_UNIXTIME(NULL)) ,1);
|
|
|
|
|
|
Bug #44139: Table scan when NULL appears in IN clause
SELECT ... WHERE ... IN (NULL, ...) does full table scan,
even if the same query without the NULL uses efficient range scan.
The bugfix for the bug 18360 introduced an optimization:
if
1) all right-hand arguments of the IN function are constants
2) result types of all right argument items are compatible
enough to use the same single comparison function to
compare all of them to the left argument,
then
we can convert the right-hand list of constant items to an array
of equally-typed constant values for the further
QUICK index access etc. (see Item_func_in::fix_length_and_dec()).
The Item_null constant item objects have STRING_RESULT
result types, so, as far as Item_func_in::fix_length_and_dec()
is aware of NULLs in the right list, this improvement efficiently
optimizes IN function calls with a mixed right list of NULLs and
string constants. However, the optimization doesn't affect mixed
lists of NULLs and integers, floats etc., because there is no
unique common comparator.
New optimization has been added to ignore the result type
of NULL constants in the static analysis of mixed right-hand lists.
This is safe, because at the execution phase we care about
presence of NULLs anyway.
1. The collect_cmp_types() function has been modified to optionally
ignore NULL constants in the item list.
2. NULL-skipping code of the Item_func_in::fix_length_and_dec()
function has been modified to work not only with in_string
vectors but with in_vectors of other types.
mysql-test/r/func_in.result:
Added test case for the bug #44139.
mysql-test/t/func_in.test:
Added test case for the bug #44139.
sql/item_cmpfunc.cc:
Bug #44139: Table scan when NULL appears in IN clause
1. The collect_cmp_types() function has been modified to optionally
ignore NULL constants in the item list.
2. NULL-skipping code of the Item_func_in::fix_length_and_dec()
function has been modified to work not only with in_string
vectors but with in_vectors of other types.
2009-10-05 07:27:36 +02:00
|
|
|
|
--echo #
|
|
|
|
|
|
2012-02-24 07:23:36 +01:00
|
|
|
|
--echo #
|
|
|
|
|
--echo # Bug#13012483: EXPLAIN EXTENDED, PREPARED STATEMENT, CRASH IN CHECK_SIMPLE_EQUALITY
|
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
|
|
|
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
|
|
|
|
|
EXECUTE s;
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
|
|
--echo # End of test BUG#13012483
|
|
|
|
|
|
|
|
|
|
--echo #
|
2006-11-16 12:13:03 +01:00
|
|
|
|
--echo End of 5.1 tests
|
2011-10-13 13:44:50 +02:00
|
|
|
|
|
2012-06-23 18:12:54 +02:00
|
|
|
|
#
|
|
|
|
|
# lp:817966 int_column IN (string_constant)
|
|
|
|
|
#
|
|
|
|
|
# rather illogically, when BIGINT field is compared to a string,
|
|
|
|
|
# the string is converted to an integer, not to a double.
|
|
|
|
|
# When some other integer field (not BIGINT) is compared to a string,
|
|
|
|
|
# or when the BIGINT is not a field, but an expression, both
|
|
|
|
|
# operands are compared as doubles. The latter behavior is correct,
|
|
|
|
|
# according to the manual.
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a bigint, b int);
|
|
|
|
|
insert t1 values (1,1),(2,2),(3,3);
|
|
|
|
|
select * from t1 where a in ('2.1');
|
|
|
|
|
select * from t1 where b in ('2.1');
|
|
|
|
|
select * from t1 where a='2.1';
|
|
|
|
|
select * from t1 where b='2.1';
|
|
|
|
|
select * from t1 where IF(1,a,a)='2.1';
|
|
|
|
|
drop table t1;
|
2012-05-22 07:48:10 +02:00
|
|
|
|
--echo #
|
|
|
|
|
--echo # LP bug#992380 Crash when creating PS for a query with
|
|
|
|
|
--echo # subquery in WHERE (see also mysql bug#13012483)
|
|
|
|
|
--echo #
|
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
|
|
|
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
|
|
|
|
|
EXECUTE s;
|
|
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
2017-10-22 13:03:41 +02:00
|
|
|
|
--echo #
|
2012-06-18 20:38:11 +02:00
|
|
|
|
--echo # End of 5.3 tests
|
2017-10-22 13:03:41 +02:00
|
|
|
|
--echo #
|
2015-09-11 09:35:15 +02:00
|
|
|
|
|
2017-10-17 10:57:51 +02:00
|
|
|
|
#
|
|
|
|
|
# Bug#26361149 MYSQL SERVER CRASHES AT: COL IN(IFNULL(CONST, COL), NAME_CONST('NAME', NULL))
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert t1 values (1),(2),(3);
|
|
|
|
|
select * from t1 where 1 in (a, name_const('a', null));
|
|
|
|
|
drop table t1;
|
2016-06-28 22:01:55 +02:00
|
|
|
|
|
MDEV-10020 InnoDB NOT IN Query Crash When One Item Is NULL
The problem was that the loop in get_func_mm_tree()
accessed improperly initialized instances of String,
which resided in the bzero'ed part of the in_vector::base array.
Strings in in_vector::base are originally initialized
in Item_func_in::fix_length_and_dec(),
in in_vector::in_vector() using sql_calloc,
rather than using a String constructor, so their str_charset
members are originally equal to NULL.
Strings in in_vector::base are later initialized
to good values in Item_func_in::fix_length_and_dec(),
using array->set(), in this code:
uint j=0;
for (uint i=1 ; i < arg_count ; i++)
{
array->set(j,args[i]);
if (!args[i]->null_value) // Skip NULL values
j++;
else
have_null= 1;
}
if ((array->used_count= j))
array->sort();
NULLs are not taken into account, so at the end
array->used_count can be smaller than array->count.
This patch fixes the loop in opt_range.cc, in get_func_mm_tree(),
to access only properly initialized elements in in_vector::base,
preventing access to its bzero'ed non-initialized tail.
2016-06-20 12:11:01 +02:00
|
|
|
|
--echo #
|
2017-10-22 13:03:41 +02:00
|
|
|
|
--echo # End of 5.5 tests
|
MDEV-10020 InnoDB NOT IN Query Crash When One Item Is NULL
The problem was that the loop in get_func_mm_tree()
accessed improperly initialized instances of String,
which resided in the bzero'ed part of the in_vector::base array.
Strings in in_vector::base are originally initialized
in Item_func_in::fix_length_and_dec(),
in in_vector::in_vector() using sql_calloc,
rather than using a String constructor, so their str_charset
members are originally equal to NULL.
Strings in in_vector::base are later initialized
to good values in Item_func_in::fix_length_and_dec(),
using array->set(), in this code:
uint j=0;
for (uint i=1 ; i < arg_count ; i++)
{
array->set(j,args[i]);
if (!args[i]->null_value) // Skip NULL values
j++;
else
have_null= 1;
}
if ((array->used_count= j))
array->sort();
NULLs are not taken into account, so at the end
array->used_count can be smaller than array->count.
This patch fixes the loop in opt_range.cc, in get_func_mm_tree(),
to access only properly initialized elements in in_vector::base,
preventing access to its bzero'ed non-initialized tail.
2016-06-20 12:11:01 +02:00
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # MDEV-10020 InnoDB NOT IN Query Crash When One Item Is NULL
|
|
|
|
|
--echo #
|
|
|
|
|
CREATE TABLE t1
|
|
|
|
|
(
|
|
|
|
|
a INT(11),
|
|
|
|
|
b VARCHAR(10),
|
|
|
|
|
KEY (b)
|
|
|
|
|
);
|
|
|
|
|
INSERT INTO t1 VALUES (1,'x'),(2,'y'),(3,'z');
|
|
|
|
|
SELECT * FROM t1 WHERE b NOT IN (NULL, '', 'A');
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # End of 10.0 tests
|
2016-06-28 22:01:55 +02:00
|
|
|
|
--echo #
|
|
|
|
|
|
2015-09-11 09:35:15 +02:00
|
|
|
|
--echo #
|
|
|
|
|
--echo # MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types
|
|
|
|
|
--echo #
|
|
|
|
|
CREATE TABLE t1 (a INT);
|
|
|
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
|
|
|
--echo # Ok to propagate equalities into the left IN argument in case of a single comparison type
|
|
|
|
|
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,3);
|
|
|
|
|
--echo # Ok to propagate equalities into IN () list, even if multiple comparison types
|
|
|
|
|
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND 1 IN (1,a,'3');
|
|
|
|
|
--echo # Not Ok to propagate equalities into the left IN argument in case of multiple comparison types
|
|
|
|
|
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,'3');
|
|
|
|
|
DROP TABLE t1;
|
MDEV-11514, MDEV-11497, MDEV-11554, MDEV-11555 - IN and CASE type aggregation problems
This patch fixes a number of data type aggregation problems in IN and CASE:
- MDEV-11497 Wrong result for (int_expr IN (mixture of signed and unsigned expressions))
- MDEV-11514 IN with a mixture of TIME and DATETIME returns a wrong result
- MDEV-11554 Wrong result for CASE on a mixture of signed and unsigned expressions
- MDEV-11555 CASE with a mixture of TIME and DATETIME returns a wrong result
1. The problem reported in MDEV-11514 and MDEV-11555 was in the wrong assumption
that items having the same cmp_type() can reuse the same cmp_item instance.
So Item_func_case and Item_func_in used a static array of cmp_item*,
one element per one XXX_RESULT.
TIME and DATETIME cannot reuse the same cmp_item, because arguments of
these types are compared very differently. TIME and DATETIME must have
different instances in the cmp_item array. Reusing the same cmp_item
for TIME and DATETIME leads to unexpected result and unexpected warnings.
Note, after adding more data types soon (e.g. INET6), the problem would
become more serious, as INET6 will most likely have STRING_RESULT, but
it won't be able to reuse the same cmp_item with VARCHAR/TEXT.
This patch introduces a new class Predicant_to_list_comparator,
which maintains an array of cmp_items, one element per distinct
Type_handler rather than one element per XXX_RESULT.
2. The problem reported in MDEV-11497 and MDEV-11554 happened because
Item_func_in and Item_func_case did not take into account the fact
that UNSIGNED and SIGNED values must be compared as DECIMAL rather than INT,
because they used item_cmp_type() to aggregate the arguments.
The relevant code now resides in Predicant_to_list_comparator::add_value()
and uses Type_handler_hybrid_field_type::aggregate_for_comparison(),
like Item_func_between does.
2016-12-17 20:35:12 +01:00
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # Start of 10.3 tests
|
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # MDEV-11514 IN with a mixture of TIME and DATETIME returns a wrong result
|
|
|
|
|
--echo #
|
2022-06-09 05:32:51 +02:00
|
|
|
|
#enable after fix MDEV-27871
|
|
|
|
|
--disable_view_protocol
|
MDEV-11514, MDEV-11497, MDEV-11554, MDEV-11555 - IN and CASE type aggregation problems
This patch fixes a number of data type aggregation problems in IN and CASE:
- MDEV-11497 Wrong result for (int_expr IN (mixture of signed and unsigned expressions))
- MDEV-11514 IN with a mixture of TIME and DATETIME returns a wrong result
- MDEV-11554 Wrong result for CASE on a mixture of signed and unsigned expressions
- MDEV-11555 CASE with a mixture of TIME and DATETIME returns a wrong result
1. The problem reported in MDEV-11514 and MDEV-11555 was in the wrong assumption
that items having the same cmp_type() can reuse the same cmp_item instance.
So Item_func_case and Item_func_in used a static array of cmp_item*,
one element per one XXX_RESULT.
TIME and DATETIME cannot reuse the same cmp_item, because arguments of
these types are compared very differently. TIME and DATETIME must have
different instances in the cmp_item array. Reusing the same cmp_item
for TIME and DATETIME leads to unexpected result and unexpected warnings.
Note, after adding more data types soon (e.g. INET6), the problem would
become more serious, as INET6 will most likely have STRING_RESULT, but
it won't be able to reuse the same cmp_item with VARCHAR/TEXT.
This patch introduces a new class Predicant_to_list_comparator,
which maintains an array of cmp_items, one element per distinct
Type_handler rather than one element per XXX_RESULT.
2. The problem reported in MDEV-11497 and MDEV-11554 happened because
Item_func_in and Item_func_case did not take into account the fact
that UNSIGNED and SIGNED values must be compared as DECIMAL rather than INT,
because they used item_cmp_type() to aggregate the arguments.
The relevant code now resides in Predicant_to_list_comparator::add_value()
and uses Type_handler_hybrid_field_type::aggregate_for_comparison(),
like Item_func_between does.
2016-12-17 20:35:12 +01:00
|
|
|
|
SELECT TIME'10:20:30' IN (102030,TIME'10:20:31',TIMESTAMP'2001-01-01 10:20:32');
|
|
|
|
|
PREPARE stmt FROM "SELECT TIME'10:20:30' IN (102030,TIME'10:20:31',TIMESTAMP'2001-01-01 10:20:32')";
|
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
DEALLOCATE PREPARE stmt;
|
2022-06-09 05:32:51 +02:00
|
|
|
|
--enable_view_protocol
|
MDEV-11514, MDEV-11497, MDEV-11554, MDEV-11555 - IN and CASE type aggregation problems
This patch fixes a number of data type aggregation problems in IN and CASE:
- MDEV-11497 Wrong result for (int_expr IN (mixture of signed and unsigned expressions))
- MDEV-11514 IN with a mixture of TIME and DATETIME returns a wrong result
- MDEV-11554 Wrong result for CASE on a mixture of signed and unsigned expressions
- MDEV-11555 CASE with a mixture of TIME and DATETIME returns a wrong result
1. The problem reported in MDEV-11514 and MDEV-11555 was in the wrong assumption
that items having the same cmp_type() can reuse the same cmp_item instance.
So Item_func_case and Item_func_in used a static array of cmp_item*,
one element per one XXX_RESULT.
TIME and DATETIME cannot reuse the same cmp_item, because arguments of
these types are compared very differently. TIME and DATETIME must have
different instances in the cmp_item array. Reusing the same cmp_item
for TIME and DATETIME leads to unexpected result and unexpected warnings.
Note, after adding more data types soon (e.g. INET6), the problem would
become more serious, as INET6 will most likely have STRING_RESULT, but
it won't be able to reuse the same cmp_item with VARCHAR/TEXT.
This patch introduces a new class Predicant_to_list_comparator,
which maintains an array of cmp_items, one element per distinct
Type_handler rather than one element per XXX_RESULT.
2. The problem reported in MDEV-11497 and MDEV-11554 happened because
Item_func_in and Item_func_case did not take into account the fact
that UNSIGNED and SIGNED values must be compared as DECIMAL rather than INT,
because they used item_cmp_type() to aggregate the arguments.
The relevant code now resides in Predicant_to_list_comparator::add_value()
and uses Type_handler_hybrid_field_type::aggregate_for_comparison(),
like Item_func_between does.
2016-12-17 20:35:12 +01:00
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # MDEV-11497 Wrong result for (int_expr IN (mixture of signed and unsigned expressions))
|
|
|
|
|
--echo #
|
|
|
|
|
CREATE TABLE t1 (a BIGINT, b BIGINT UNSIGNED);
|
|
|
|
|
INSERT INTO t1 VALUES (-9223372036854775808,18446744073709551615);
|
|
|
|
|
SELECT * FROM t1 WHERE -1 IN (a,b);
|
|
|
|
|
PREPARE stmt FROM 'SELECT * FROM t1 WHERE -1 IN (a,b)';
|
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
|
DROP TABLE t1;
|
MDEV-15340 Wrong result HOUR(case_expression_with_time_and_datetime)
The problem was that Item_func_hybrid_field_type::get_date() did not
convert the result to the correct data type, so MYSQL_TIME::time_type
of the get_date() result could be not in sync with field_type().
Changes:
1. Adding two new classes Datetime and Date to store MYSQL_TIMESTAMP_DATETIME
and MYSQL_TIMESTAMP_DATE values respectively
(in addition to earlier added class Time, for MYSQL_TIMESTAMP_TIME values).
2. Adding Item_func_hybrid_field_type::time_op().
It performs the operation using TIME representation,
and always returns a MYSQL_TIME value with time_type=MYSQL_TIMESTAMP_TIME.
Implementing time_op() for all affected children classes.
3. Fixing all implementations of date_op() to perform the operation
using strictly DATETIME representation. Now they always return a MYSQL_TIME
value with time_type=MYSQL_TIMESTAMP_{DATE|DATETIME},
according to the result data type.
4. Removing assignment of ltime.time_type to mysql_timestamp_type()
from all val_xxx_from_date_op(), because now date_op() makes sure
to return a proper MYSQL_TIME value with a good time_type (and other member)
5. Adding Item_func_hybrid_field_type::val_xxx_from_time_op().
6. Overriding Type_handler_time_common::Item_func_hybrid_field_type_val_xxx()
to call val_xxx_from_time_op() instead of val_xxx_from_date_op().
7. Modified Item_func::get_arg0_date() to return strictly a TIME value
if TIME_TIME_ONLY is passed, or return strictly a DATETIME value otherwise.
If args[0] returned a value of a different temporal type,
(for example a TIME value when TIME_TIME_ONLY was not passed,
or a DATETIME value when TIME_TIME_ONLY was passed), the conversion
is automatically applied.
Earlier, get_arg0_date() did not guarantee a result in
accordance to TIME_TIME_ONLY flag.
2018-02-19 20:41:01 +01:00
|
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
|
--echo # MDEV-15340 Wrong result HOUR(case_expression_with_time_and_datetime)
|
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
|
|
# This is to make sure that TIME_FUZZY_DATE is always passed to str_to_time(),
|
|
|
|
|
# so empty strings are compared as TIME'00:00:00' all around the code:
|
|
|
|
|
# when using Arg_comparator (e.g. in binary comparison operators), and
|
|
|
|
|
# when not using it (e.g. in IN predicate).
|
|
|
|
|
|
2022-06-09 05:32:51 +02:00
|
|
|
|
#view protocol generates additional warning
|
|
|
|
|
--disable_view_protocol
|
MDEV-15340 Wrong result HOUR(case_expression_with_time_and_datetime)
The problem was that Item_func_hybrid_field_type::get_date() did not
convert the result to the correct data type, so MYSQL_TIME::time_type
of the get_date() result could be not in sync with field_type().
Changes:
1. Adding two new classes Datetime and Date to store MYSQL_TIMESTAMP_DATETIME
and MYSQL_TIMESTAMP_DATE values respectively
(in addition to earlier added class Time, for MYSQL_TIMESTAMP_TIME values).
2. Adding Item_func_hybrid_field_type::time_op().
It performs the operation using TIME representation,
and always returns a MYSQL_TIME value with time_type=MYSQL_TIMESTAMP_TIME.
Implementing time_op() for all affected children classes.
3. Fixing all implementations of date_op() to perform the operation
using strictly DATETIME representation. Now they always return a MYSQL_TIME
value with time_type=MYSQL_TIMESTAMP_{DATE|DATETIME},
according to the result data type.
4. Removing assignment of ltime.time_type to mysql_timestamp_type()
from all val_xxx_from_date_op(), because now date_op() makes sure
to return a proper MYSQL_TIME value with a good time_type (and other member)
5. Adding Item_func_hybrid_field_type::val_xxx_from_time_op().
6. Overriding Type_handler_time_common::Item_func_hybrid_field_type_val_xxx()
to call val_xxx_from_time_op() instead of val_xxx_from_date_op().
7. Modified Item_func::get_arg0_date() to return strictly a TIME value
if TIME_TIME_ONLY is passed, or return strictly a DATETIME value otherwise.
If args[0] returned a value of a different temporal type,
(for example a TIME value when TIME_TIME_ONLY was not passed,
or a DATETIME value when TIME_TIME_ONLY was passed), the conversion
is automatically applied.
Earlier, get_arg0_date() did not guarantee a result in
accordance to TIME_TIME_ONLY flag.
2018-02-19 20:41:01 +01:00
|
|
|
|
SELECT
|
|
|
|
|
TIME'00:00:00'='' AS c1_true,
|
|
|
|
|
TIME'00:00:00' IN ('', TIME'10:20:30') AS c2_true,
|
|
|
|
|
TIME'00:00:00' NOT IN ('', TIME'10:20:30') AS c3_false;
|
2022-06-09 05:32:51 +02:00
|
|
|
|
|
|
|
|
|
--enable_view_protocol
|
|
|
|
|
|