diff --git a/include/config-win.h b/include/config-win.h index bc2ae60f137..2e64e165630 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -15,6 +15,8 @@ /* Defines for Win32 to make it compatible for MySQL */ +#define BIG_TABLES + #ifdef __WIN2000__ /* We have to do this define before including windows.h to get the AWE API functions */ diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index c28102d13e0..ed61cfffa6b 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -4082,3 +4082,20 @@ x 1 DROP VIEW v1, v2, v3; End of 5.0 tests +create table t1(a INT, KEY (a)); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5); +SELECT a FROM t1 ORDER BY a LIMIT 2; +a +1 +2 +SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296; +a +3 +4 +5 +SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297; +a +3 +4 +5 +DROP TABLE t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 91f68fd4057..76a66cc4783 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -3474,3 +3474,13 @@ DROP VIEW v1, v2, v3; --enable_ps_protocol --echo End of 5.0 tests + +# +# Bug #30639: limit offset,rowcount wraps when rowcount >= 2^32 in windows +# +create table t1(a INT, KEY (a)); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5); +SELECT a FROM t1 ORDER BY a LIMIT 2; +SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296; +SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297; +DROP TABLE t1; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 6b94505e46e..0a5f83af400 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -2397,10 +2397,19 @@ st_lex::copy_db_to(char **p_db, size_t *p_db_length) const void st_select_lex_unit::set_limit(st_select_lex *sl) { ha_rows select_limit_val; + ulonglong val; DBUG_ASSERT(! thd->stmt_arena->is_stmt_prepare()); - select_limit_val= (ha_rows)(sl->select_limit ? sl->select_limit->val_uint() : - HA_POS_ERROR); + val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR; + select_limit_val= (ha_rows)val; +#ifndef BIG_TABLES + /* + Check for overflow : ha_rows can be smaller then ulonglong if + BIG_TABLES is off. + */ + if (val != (ulonglong)select_limit_val) + select_limit_val= HA_POS_ERROR; +#endif offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() : ULL(0)); select_limit_cnt= select_limit_val + offset_limit_cnt;