List:Commits« Previous MessageNext Message »
From:kgeorge Date:August 31 2007 7:59am
Subject:bk commit into 5.1 tree (gkodinov:1.2583) BUG#30639
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of kgeorge. When kgeorge does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-08-31 10:59:21+03:00, gkodinov@stripped +4 -0
  Bug #30639: limit offset,rowcount wraps when rowcount >= 2^32 in windows
  
   The parser uses ulonglong to store the LIMIT number. This number
   then is stored into a variable of type ha_rows. ha_rows is either
   4 or 8 byte depending on the BIG_TABLES define from config.h
   So an overflow may occur (and LIMIT becomes zero) while storing an
   ulonglong value in ha_rows.
   Fixed by :
    1. Using the maximum possible value for ha_rows on overflow
    2. Defining BIG_TABLES for the windows builds (to match the others) 

  include/config-win.h@stripped, 2007-08-31 10:59:20+03:00, gkodinov@stripped +2 -0
    Bug #30639: turn on BIG_TABLES for windows

  mysql-test/r/select.result@stripped, 2007-08-31 10:59:20+03:00, gkodinov@stripped +17 -0
    Bug #30639: test case

  mysql-test/t/select.test@stripped, 2007-08-31 10:59:20+03:00, gkodinov@stripped +10 -0
    Bug #30639: test case

  sql/sql_lex.cc@stripped, 2007-08-31 10:59:20+03:00, gkodinov@stripped +9 -2
    Bug #30639: Use the maximum possible number on overflow 
     of LIMIT. This is valid because there won't be more rows
     anyway.

diff -Nrup a/include/config-win.h b/include/config-win.h
--- a/include/config-win.h	2007-07-24 00:19:22 +03:00
+++ b/include/config-win.h	2007-08-31 10:59:20 +03:00
@@ -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 -Nrup a/mysql-test/r/select.result b/mysql-test/r/select.result
--- a/mysql-test/r/select.result	2007-08-17 05:27:35 +03:00
+++ b/mysql-test/r/select.result	2007-08-31 10:59:20 +03:00
@@ -4048,3 +4048,20 @@ Level	Code	Message
 Note	1003	select '0' AS `c1` from `test`.`t1` `join_0` join `test`.`t1` `join_1` join `test`.`t1` `join_2` join `test`.`t1` `join_3` join `test`.`t1` `join_4` join `test`.`t1` `join_5` join `test`.`t1` `join_6` join `test`.`t1` `join_7` where 0 group by '0','0','0','0','0'
 DROP TABLE t1;
 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 -Nrup a/mysql-test/t/select.test b/mysql-test/t/select.test
--- a/mysql-test/t/select.test	2007-08-17 02:51:16 +03:00
+++ b/mysql-test/t/select.test	2007-08-31 10:59:20 +03:00
@@ -3450,3 +3450,13 @@ SHOW WARNINGS;
 DROP TABLE t1;
 
 --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 -Nrup a/sql/sql_lex.cc b/sql/sql_lex.cc
--- a/sql/sql_lex.cc	2007-08-25 11:43:14 +03:00
+++ b/sql/sql_lex.cc	2007-08-31 10:59:20 +03:00
@@ -2372,10 +2372,17 @@ st_lex::copy_db_to(char **p_db, size_t *
 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;
+  /* 
+    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;
   offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
                                                  ULL(0));
   select_limit_cnt= select_limit_val + offset_limit_cnt;
Thread
bk commit into 5.1 tree (gkodinov:1.2583) BUG#30639kgeorge31 Aug