From f489e562916440d3de65f8b57e27a78da15bdc7b Mon Sep 17 00:00:00 2001 From: "timour@mysql.com" <> Date: Wed, 9 Mar 2005 16:51:03 +0200 Subject: [PATCH] Fix for BUG#7425. The reported problems were due to two completely unrelated omissions. 1) The file sort procedure didn't correctly create the sort key in make_sortkey when the sortkey was an unsigned integer. 2) The name resolution procedure for column references inside a HAVING clause did not propagate the unsigned_flag of the resolved references. This patch corrects both problems. --- mysql-test/r/select.result | 23 +++++++++++++++++++++++ mysql-test/t/select.test | 11 +++++++++++ sql/filesort.cc | 10 ++++++++-- sql/item.cc | 1 + 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 1a3b2ab22e6..9252b3dc689 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2422,3 +2422,26 @@ SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London'; city London DROP TABLE t1; +create table t1 (a int(11) unsigned, b int(11) unsigned); +insert into t1 values (1,0), (1,1), (1,2); +select a-b from t1 order by 1; +a-b +0 +1 +18446744073709551615 +select a-b , (a-b < 0) from t1 order by 1; +a-b (a-b < 0) +0 0 +1 0 +18446744073709551615 0 +select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0; +d (a-b >= 0) b +1 1 0 +0 1 1 +18446744073709551615 1 2 +select cast((a - b) as unsigned) from t1 order by 1; +cast((a - b) as unsigned) +0 +1 +18446744073709551615 +drop table t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 53f569c773e..f7144f436df 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -1964,3 +1964,14 @@ SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London'; DROP TABLE t1; +# +# Bug#7425 inconsistent sort order on unsigned columns result of substraction +# + +create table t1 (a int(11) unsigned, b int(11) unsigned); +insert into t1 values (1,0), (1,1), (1,2); +select a-b from t1 order by 1; +select a-b , (a-b < 0) from t1 order by 1; +select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0; +select cast((a - b) as unsigned) from t1 order by 1; +drop table t1; diff --git a/sql/filesort.cc b/sql/filesort.cc index 76ce9ac4ce2..c6af8cfc1b7 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -656,12 +656,18 @@ static void make_sortkey(register SORTPARAM *param, to[3]= (uchar) (value >> 32); to[2]= (uchar) (value >> 40); to[1]= (uchar) (value >> 48); - to[0]= (uchar) (value >> 56) ^ 128; // Fix sign + if (item->unsigned_flag) /* Fix sign */ + to[0]= (uchar) (value >> 56); + else + to[0]= (uchar) (value >> 56) ^ 128; /* Reverse signbit */ #else to[3]= (uchar) value; to[2]= (uchar) (value >> 8); to[1]= (uchar) (value >> 16); - to[0]= (uchar) (value >> 24) ^ 128; // Fix sign + if (item->unsigned_flag) /* Fix sign */ + to[0]= (uchar) (value >> 24); + else + to[0]= (uchar) (value >> 24) ^ 128; /* Reverse signbit */ #endif break; } diff --git a/sql/item.cc b/sql/item.cc index 1293d2c94fe..690ada2d660 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2281,6 +2281,7 @@ void Item_ref::set_properties() decimals= (*ref)->decimals; collation.set((*ref)->collation); with_sum_func= (*ref)->with_sum_func; + unsigned_flag= (*ref)->unsigned_flag; fixed= 1; }