From 0b5696b82b8c60ebdb70fd267f32479d0bb96ab5 Mon Sep 17 00:00:00 2001 From: "ramil/ram@mysql.com/myoffice.izhnet.ru" <> Date: Wed, 6 Dec 2006 16:32:12 +0400 Subject: [PATCH 1/3] Fix for bug #22533: Traditional: Too-long bit value not rejected. Problem: storing >=8 byte hexadecimal values we don't check data. Fix: check if the data fits the {u}longlong range. --- mysql-test/r/select.result | 17 +++++++++++++++++ mysql-test/t/range.test | 4 ++-- mysql-test/t/select.test | 13 ++++++++++++- sql/item.cc | 25 +++++++++++++++++++------ 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index f09143fcaa6..6dc971a953c 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2819,3 +2819,20 @@ select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; min(key1) 0.37619999051094 DROP TABLE t1,t2; +create table t1(a bigint unsigned, b bigint); +insert into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff), +(0x10000000000000000, 0x10000000000000000), +(0x8fffffffffffffff, 0x8fffffffffffffff); +Warnings: +Warning 1264 Data truncated; out of range for column 'a' at row 1 +Warning 1264 Data truncated; out of range for column 'b' at row 1 +Warning 1264 Data truncated; out of range for column 'a' at row 2 +Warning 1264 Data truncated; out of range for column 'b' at row 2 +Warning 1264 Data truncated; out of range for column 'b' at row 3 +select hex(a), hex(b) from t1; +hex(a) hex(b) +FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF +FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF +8FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF +drop table t1; +End of 4.1 tests diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test index 245178d7d4a..6d3b2fb52ee 100644 --- a/mysql-test/t/range.test +++ b/mysql-test/t/range.test @@ -400,8 +400,8 @@ select count(*) from t1 where x = 18446744073709551601; create table t2 (x bigint not null); -insert into t2(x) values (0xfffffffffffffff0); -insert into t2(x) values (0xfffffffffffffff1); +insert into t2(x) values (-16); +insert into t2(x) values (-15); select * from t2; select count(*) from t2 where x>0; select count(*) from t2 where x=0; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 3f9fb59d26f..0dc179e9b4b 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2342,4 +2342,15 @@ select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; DROP TABLE t1,t2; --enable_ps_protocol -# End of 4.1 tests +# +# Bug #22533: storing large hex strings +# + +create table t1(a bigint unsigned, b bigint); +insert into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff), + (0x10000000000000000, 0x10000000000000000), + (0x8fffffffffffffff, 0x8fffffffffffffff); +select hex(a), hex(b) from t1; +drop table t1; + +--echo End of 4.1 tests diff --git a/sql/item.cc b/sql/item.cc index 94f0a24fcc3..30f34f9ec3b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2340,18 +2340,31 @@ longlong Item_varbinary::val_int() int Item_varbinary::save_in_field(Field *field, bool no_conversions) { - int error; field->set_notnull(); if (field->result_type() == STRING_RESULT) + return field->store(str_value.ptr(), str_value.length(), + collation.collation); + + ulonglong nr; + uint32 length= str_value.length(); + if (length > 8) { - error=field->store(str_value.ptr(),str_value.length(),collation.collation); + nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX; + goto warn; } - else + nr= (ulonglong) val_int(); + if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX)) { - longlong nr=val_int(); - error=field->store(nr); + nr= LONGLONG_MAX; + goto warn; } - return error; + return field->store((longlong) nr); + +warn: + if (!field->store((longlong) nr)) + field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, + 1); + return 1; } From 5c42e6838843b5210b2682f25bfb932f717eeb49 Mon Sep 17 00:00:00 2001 From: "ramil/ram@mysql.com/myoffice.izhnet.ru" <> Date: Thu, 18 Jan 2007 10:51:29 +0400 Subject: [PATCH 2/3] after merge fix. --- mysql-test/r/select.result | 380 ++----------------------------------- sql/item.cc | 4 +- 2 files changed, 19 insertions(+), 365 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 92b9281e70e..dbc406b9a6c 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2811,6 +2811,23 @@ select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; min(key1) 0.37619999051094 DROP TABLE t1,t2; +create table t1(a bigint unsigned, b bigint); +insert into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff), +(0x10000000000000000, 0x10000000000000000), +(0x8fffffffffffffff, 0x8fffffffffffffff); +Warnings: +Warning 1264 Out of range value adjusted for column 'a' at row 1 +Warning 1264 Out of range value adjusted for column 'b' at row 1 +Warning 1264 Out of range value adjusted for column 'a' at row 2 +Warning 1264 Out of range value adjusted for column 'b' at row 2 +Warning 1264 Out of range value adjusted for column 'b' at row 3 +select hex(a), hex(b) from t1; +hex(a) hex(b) +FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF +FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF +8FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF +drop table t1; +End of 4.1 tests CREATE TABLE t1 ( K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', @@ -3200,179 +3217,6 @@ select count(*) from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id; count(*) 6 -<<<<<<< gca mysql-test/r/select.result 1.34.3.40 -t1 MyISAM 9 Dynamic 2 20 X X X X X X X X latin1_swedish_ci NULL -t11 MyISAM 9 Dynamic 0 0 X X X X X X X X latin1_swedish_ci NULL -select 123 as a from t1 where f1 is null; -a -drop table t1,t11; -CREATE TABLE t1 (a INT, b INT); -(SELECT a, b AS c FROM t1) ORDER BY c+1; -a c -(SELECT a, b AS c FROM t1) ORDER BY b+1; -a c -SELECT a, b AS c FROM t1 ORDER BY c+1; -a c -SELECT a, b AS c FROM t1 ORDER BY b+1; -a c -drop table t1; -CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, UNIQUE idx (a,b) ); -INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4); -CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, c INT ); -INSERT INTO t2 VALUES ( 1,10,1), (1,10,2), (1,11,1), (1,11,2), (1,2,1), (1,2,2), -(1,2,3); -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN -t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c; -a b c d -1 2 1 1 -1 2 2 1 -1 2 3 1 -1 10 2 -1 11 2 -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN -t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t1.a, t1.b, c; -a b c d -1 10 4 -1 2 1 1 -1 2 2 1 -1 2 3 1 -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN -t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t2.a, t2.b, c; -a b c d -1 2 1 1 -1 2 2 1 -1 2 3 1 -1 10 2 -1 11 2 -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2,t1 -WHERE t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c; -a b c d -1 2 1 1 -1 2 2 1 -1 2 3 1 -DROP TABLE IF EXISTS t1, t2; -create table t1 (f1 int primary key, f2 int); -create table t2 (f3 int, f4 int, primary key(f3,f4)); -insert into t1 values (1,1); -insert into t2 values (1,1),(1,2); -select distinct count(f2) >0 from t1 left join t2 on f1=f3 group by f1; -count(f2) >0 -1 -drop table t1,t2; -create table t1 (f1 int,f2 int); -insert into t1 values(1,1); -create table t2 (f3 int, f4 int, primary key(f3,f4)); -insert into t2 values(1,1); -select * from t1 where f1 in (select f3 from t2 where (f3,f4)= (select f3,f4 from t2)); -f1 f2 -1 1 -drop table t1,t2; -CREATE TABLE t1(a int, b int, c int, KEY b(b), KEY c(c)); -insert into t1 values (1,0,0),(2,0,0); -CREATE TABLE t2 (a int, b varchar(2), c varchar(2), PRIMARY KEY(a)); -insert into t2 values (1,'',''), (2,'',''); -CREATE TABLE t3 (a int, b int, PRIMARY KEY (a,b), KEY a (a), KEY b (b)); -insert into t3 values (1,1),(1,2); -explain select straight_join DISTINCT t2.a,t2.b, t1.c from t1, t3, t2 -where (t1.c=t2.a or (t1.c=t3.a and t2.a=t3.b)) and t1.b=556476786 and -t2.b like '%%' order by t2.b limit 0,1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref b,c b 5 const 1 Using where; Using temporary; Using filesort -1 SIMPLE t3 index PRIMARY,a,b PRIMARY 8 NULL 2 Using index -1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Range checked for each record (index map: 0x1) -DROP TABLE t1,t2,t3; -CREATE TABLE t1 (a int, INDEX idx(a)); -INSERT INTO t1 VALUES (2), (3), (1); -EXPLAIN SELECT * FROM t1 IGNORE INDEX (idx); -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 -EXPLAIN SELECT * FROM t1 IGNORE INDEX (a); -ERROR HY000: Key 'a' doesn't exist in table 't1' -EXPLAIN SELECT * FROM t1 FORCE INDEX (a); -ERROR HY000: Key 'a' doesn't exist in table 't1' -DROP TABLE t1; -CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); -INSERT INTO t1 VALUES (10); -SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1; -i='1e+01' i=1e+01 i in (1e+01) i in ('1e+01') -0 1 1 1 -DROP TABLE t1; -CREATE TABLE t1 (a int, b int); -INSERT INTO t1 VALUES (1,1), (2,1), (4,10); -CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b)); -INSERT INTO t2 VALUES (1,NULL), (2,10); -ALTER TABLE t1 ENABLE KEYS; -EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index b b 5 NULL 2 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where -SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -a b a b -1 NULL 1 1 -1 NULL 2 1 -1 NULL 4 10 -2 10 4 10 -EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index b b 5 NULL 2 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where -SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -a b a b -1 NULL 1 1 -1 NULL 2 1 -1 NULL 4 10 -2 10 4 10 -DROP TABLE IF EXISTS t1,t2; -CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1)); -CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2)); -INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941); -INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941); -explain select max(key1) from t1 where key1 <= 0.6158; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key2) from t2 where key2 <= 1.6158; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key1) from t1 where key1 >= 0.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key2) from t2 where key2 >= 1.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key1), min(key2) from t1, t2 -where key1 <= 0.6158 and key2 >= 1.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -select max(key1) from t1 where key1 <= 0.6158; -max(key1) -0.61580002307892 -select max(key2) from t2 where key2 <= 1.6158; -max(key2) -1.6158000230789 -select min(key1) from t1 where key1 >= 0.3762; -min(key1) -0.37619999051094 -select min(key2) from t2 where key2 >= 1.3762; -min(key2) -1.3761999607086 -select max(key1), min(key2) from t1, t2 -where key1 <= 0.6158 and key2 >= 1.3762; -max(key1) min(key2) -0.61580002307892 1.3761999607086 -select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; -max(key1) -0.61580002307892 -select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; -min(key1) -0.37619999051094 -DROP TABLE t1,t2; -<<<<<<< local mysql-test/r/select.result 1.143 drop table t1,t2,t3; create table t1 (a int); create table t2 (b int); @@ -3784,193 +3628,3 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range si,ai si 5 NULL 2 Using where 1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where DROP TABLE t1,t2,t3; -<<<<<<< remote mysql-test/r/select.result 1.34.3.41 -t1 MyISAM 9 Dynamic 2 20 X X X X X X X X latin1_swedish_ci NULL -t11 MyISAM 9 Dynamic 0 0 X X X X X X X X latin1_swedish_ci NULL -select 123 as a from t1 where f1 is null; -a -drop table t1,t11; -CREATE TABLE t1 (a INT, b INT); -(SELECT a, b AS c FROM t1) ORDER BY c+1; -a c -(SELECT a, b AS c FROM t1) ORDER BY b+1; -a c -SELECT a, b AS c FROM t1 ORDER BY c+1; -a c -SELECT a, b AS c FROM t1 ORDER BY b+1; -a c -drop table t1; -CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, UNIQUE idx (a,b) ); -INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4); -CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, c INT ); -INSERT INTO t2 VALUES ( 1,10,1), (1,10,2), (1,11,1), (1,11,2), (1,2,1), (1,2,2), -(1,2,3); -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN -t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c; -a b c d -1 2 1 1 -1 2 2 1 -1 2 3 1 -1 10 2 -1 11 2 -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN -t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t1.a, t1.b, c; -a b c d -1 10 4 -1 2 1 1 -1 2 2 1 -1 2 3 1 -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2 LEFT JOIN -t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t2.a, t2.b, c; -a b c d -1 2 1 1 -1 2 2 1 -1 2 3 1 -1 10 2 -1 11 2 -SELECT t2.a, t2.b, IF(t1.b IS NULL,'',c) AS c, COUNT(*) AS d FROM t2,t1 -WHERE t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c; -a b c d -1 2 1 1 -1 2 2 1 -1 2 3 1 -DROP TABLE IF EXISTS t1, t2; -create table t1 (f1 int primary key, f2 int); -create table t2 (f3 int, f4 int, primary key(f3,f4)); -insert into t1 values (1,1); -insert into t2 values (1,1),(1,2); -select distinct count(f2) >0 from t1 left join t2 on f1=f3 group by f1; -count(f2) >0 -1 -drop table t1,t2; -create table t1 (f1 int,f2 int); -insert into t1 values(1,1); -create table t2 (f3 int, f4 int, primary key(f3,f4)); -insert into t2 values(1,1); -select * from t1 where f1 in (select f3 from t2 where (f3,f4)= (select f3,f4 from t2)); -f1 f2 -1 1 -drop table t1,t2; -CREATE TABLE t1(a int, b int, c int, KEY b(b), KEY c(c)); -insert into t1 values (1,0,0),(2,0,0); -CREATE TABLE t2 (a int, b varchar(2), c varchar(2), PRIMARY KEY(a)); -insert into t2 values (1,'',''), (2,'',''); -CREATE TABLE t3 (a int, b int, PRIMARY KEY (a,b), KEY a (a), KEY b (b)); -insert into t3 values (1,1),(1,2); -explain select straight_join DISTINCT t2.a,t2.b, t1.c from t1, t3, t2 -where (t1.c=t2.a or (t1.c=t3.a and t2.a=t3.b)) and t1.b=556476786 and -t2.b like '%%' order by t2.b limit 0,1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref b,c b 5 const 1 Using where; Using temporary; Using filesort -1 SIMPLE t3 index PRIMARY,a,b PRIMARY 8 NULL 2 Using index -1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Range checked for each record (index map: 0x1) -DROP TABLE t1,t2,t3; -CREATE TABLE t1 (a int, INDEX idx(a)); -INSERT INTO t1 VALUES (2), (3), (1); -EXPLAIN SELECT * FROM t1 IGNORE INDEX (idx); -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 -EXPLAIN SELECT * FROM t1 IGNORE INDEX (a); -ERROR HY000: Key 'a' doesn't exist in table 't1' -EXPLAIN SELECT * FROM t1 FORCE INDEX (a); -ERROR HY000: Key 'a' doesn't exist in table 't1' -DROP TABLE t1; -CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); -INSERT INTO t1 VALUES (10); -SELECT i='1e+01',i=1e+01, i in (1e+01), i in ('1e+01') FROM t1; -i='1e+01' i=1e+01 i in (1e+01) i in ('1e+01') -0 1 1 1 -DROP TABLE t1; -CREATE TABLE t1 (a int, b int); -INSERT INTO t1 VALUES (1,1), (2,1), (4,10); -CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b)); -INSERT INTO t2 VALUES (1,NULL), (2,10); -ALTER TABLE t1 ENABLE KEYS; -EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index b b 5 NULL 2 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where -SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -a b a b -1 NULL 1 1 -1 NULL 2 1 -1 NULL 4 10 -2 10 4 10 -EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index b b 5 NULL 2 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where -SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL; -a b a b -1 NULL 1 1 -1 NULL 2 1 -1 NULL 4 10 -2 10 4 10 -DROP TABLE IF EXISTS t1,t2; -CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1)); -CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2)); -INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941); -INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941); -explain select max(key1) from t1 where key1 <= 0.6158; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key2) from t2 where key2 <= 1.6158; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key1) from t1 where key1 >= 0.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key2) from t2 where key2 >= 1.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key1), min(key2) from t1, t2 -where key1 <= 0.6158 and key2 >= 1.3762; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -select max(key1) from t1 where key1 <= 0.6158; -max(key1) -0.61580002307892 -select max(key2) from t2 where key2 <= 1.6158; -max(key2) -1.6158000230789 -select min(key1) from t1 where key1 >= 0.3762; -min(key1) -0.37619999051094 -select min(key2) from t2 where key2 >= 1.3762; -min(key2) -1.3761999607086 -select max(key1), min(key2) from t1, t2 -where key1 <= 0.6158 and key2 >= 1.3762; -max(key1) min(key2) -0.61580002307892 1.3761999607086 -select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5; -max(key1) -0.61580002307892 -select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5; -min(key1) -0.37619999051094 -DROP TABLE t1,t2; -create table t1(a bigint unsigned, b bigint); -insert into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff), -(0x10000000000000000, 0x10000000000000000), -(0x8fffffffffffffff, 0x8fffffffffffffff); -Warnings: -Warning 1264 Data truncated; out of range for column 'a' at row 1 -Warning 1264 Data truncated; out of range for column 'b' at row 1 -Warning 1264 Data truncated; out of range for column 'a' at row 2 -Warning 1264 Data truncated; out of range for column 'b' at row 2 -Warning 1264 Data truncated; out of range for column 'b' at row 3 -select hex(a), hex(b) from t1; -hex(a) hex(b) -FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF -FFFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF -8FFFFFFFFFFFFFFF 7FFFFFFFFFFFFFFF -drop table t1; -End of 4.1 tests ->>>>>>> diff --git a/sql/item.cc b/sql/item.cc index e5a888842ac..11bc5771b56 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4478,10 +4478,10 @@ int Item_hex_string::save_in_field(Field *field, bool no_conversions) nr= LONGLONG_MAX; goto warn; } - return field->store((longlong) nr); + return field->store((longlong) nr, TRUE); // Assume hex numbers are unsigned warn: - if (!field->store((longlong) nr)) + if (!field->store((longlong) nr, TRUE)) field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); return 1; From c57442d6d82d8a74105c949682d165513f0e9a21 Mon Sep 17 00:00:00 2001 From: "ramil/ram@mysql.com/myoffice.izhnet.ru" <> Date: Thu, 18 Jan 2007 15:28:45 +0400 Subject: [PATCH 3/3] after merge fix. --- mysql-test/r/range.result | 4 ++-- mysql-test/r/type_bit.result | 2 +- mysql-test/r/type_bit_innodb.result | 2 +- sql/field.cc | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index c96173e74cc..9d2da82813f 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -521,8 +521,8 @@ select count(*) from t1 where x = 18446744073709551601; count(*) 1 create table t2 (x bigint not null); -insert into t2(x) values (cast(0xfffffffffffffff0+0 as signed)); -insert into t2(x) values (cast(0xfffffffffffffff1+0 as signed)); +insert into t2(x) values (-16); +insert into t2(x) values (-15); select * from t2; x -16 diff --git a/mysql-test/r/type_bit.result b/mysql-test/r/type_bit.result index bd58e83bb3f..5726501916c 100644 --- a/mysql-test/r/type_bit.result +++ b/mysql-test/r/type_bit.result @@ -568,7 +568,7 @@ create table t1 (a bit(7)); insert into t1 values (0x60); select * from t1; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def test t1 t1 a a 16 7 1 Y 0 0 63 +def test t1 t1 a a 16 7 1 Y 32 0 63 a ` drop table t1; diff --git a/mysql-test/r/type_bit_innodb.result b/mysql-test/r/type_bit_innodb.result index 1f6857277bd..c4506231f27 100644 --- a/mysql-test/r/type_bit_innodb.result +++ b/mysql-test/r/type_bit_innodb.result @@ -406,7 +406,7 @@ create table t1 (a bit(7)) engine=innodb; insert into t1 values (0x60); select * from t1; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def test t1 t1 a a 16 7 1 Y 0 0 63 +def test t1 t1 a a 16 7 1 Y 32 0 63 a ` drop table t1; diff --git a/sql/field.cc b/sql/field.cc index ec97bc92d24..41b30111488 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7865,6 +7865,7 @@ Field_bit::Field_bit(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, bit_ptr(bit_ptr_arg), bit_ofs(bit_ofs_arg), bit_len(len_arg & 7), bytes_in_rec(len_arg / 8) { + flags|= UNSIGNED_FLAG; /* Ensure that Field::eq() can distinguish between two different bit fields. (two bit fields that are not null, may have same ptr and null_ptr) @@ -8104,6 +8105,7 @@ Field_bit_as_char::Field_bit_as_char(char *ptr_arg, uint32 len_arg, : Field_bit(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 0, 0, unireg_check_arg, field_name_arg, table_arg) { + flags|= UNSIGNED_FLAG; bit_len= 0; bytes_in_rec= (len_arg + 7) / 8; }