Skip to content

Commit f17a865

Browse files
MDEV-30710 Incorrect operator when comparing large unsigned integers.
When constructing a SEL_TREE, an unsigned integer greater than its signed equivalent caused an incorrect comparison operator to be chosen.
1 parent 1a5c4c2 commit f17a865

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

mysql-test/main/type_int.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,5 +1675,16 @@ SELECT DISTINCT 1 FROM t1 GROUP BY 0 >> NULL WITH ROLLUP;
16751675
1
16761676
DROP TABLE t1;
16771677
#
1678+
# MDEV-30710 Incorrect operator when comparing large unsigned integers.
1679+
#
1680+
create table t1(c0 tinyint unique);
1681+
insert into t1 values (127);
1682+
insert into t1 values (-128);
1683+
select * from t1 where 18446744073700599371 > c0;
1684+
c0
1685+
-128
1686+
127
1687+
drop table t1;
1688+
#
16781689
# End of 10.5 tests
16791690
#

mysql-test/main/type_int.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,15 @@ INSERT INTO t1 VALUES (1),(2);
554554
SELECT DISTINCT 1 FROM t1 GROUP BY 0 >> NULL WITH ROLLUP;
555555
DROP TABLE t1;
556556

557+
--echo #
558+
--echo # MDEV-30710 Incorrect operator when comparing large unsigned integers.
559+
--echo #
560+
561+
create table t1(c0 tinyint unique);
562+
insert into t1 values (127);
563+
insert into t1 values (-128);
564+
select * from t1 where 18446744073700599371 > c0;
565+
drop table t1;
557566

558567
--echo #
559568
--echo # End of 10.5 tests

sql/opt_range.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8995,7 +8995,8 @@ SEL_ARG *Field::stored_field_make_mm_leaf_bounded_int(RANGE_OPT_PARAM *param,
89958995
DBUG_RETURN(new (param->mem_root) SEL_ARG_IMPOSSIBLE(this));
89968996
longlong item_val= value->val_int();
89978997

8998-
if (op == SCALAR_CMP_LT && item_val > 0)
8998+
if (op == SCALAR_CMP_LT && ((item_val > 0)
8999+
|| (value->unsigned_flag && (ulonglong)item_val > 0 )))
89999000
op= SCALAR_CMP_LE; // e.g. rewrite (tinyint < 200) to (tinyint <= 127)
90009001
else if (op == SCALAR_CMP_GT && !unsigned_field &&
90019002
!value->unsigned_flag && item_val < 0)

0 commit comments

Comments
 (0)