From: Tor Didriksen Date: July 18 2011 9:39am Subject: bzr push into mysql-5.5 branch (tor.didriksen:3465 to 3466) Bug#12711164 List-Archive: http://lists.mysql.com/commits/140340 X-Bug: 12711164 Message-Id: <201107180939.p6I9dUij011725@acsmt358.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3466 Tor Didriksen 2011-07-18 Bug#12711164 - 61676: RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE Truncate result of decimal division before converting to integer. @ mysql-test/r/func_math.result New test case. @ mysql-test/t/func_math.test New test case. @ sql/item_func.cc Item_func_int_div::val_int(): Truncate result of decimal division before converting to integer. modified: mysql-test/r/func_math.result mysql-test/t/func_math.test sql/item_func.cc 3465 Tor Didriksen 2011-07-18 Bug#12537160 ASSERTION FAILED: STOP0 <= &TO->BUF[TO->LEN] WITH LARGE NUMBER. Turns out the DBUG_ASSERT added by fix for Bug#11792200 was overly pessimistic: 'stop0' is used in the main loop of do_div_mod, but we only dereference 'buf0' for div operations, not for mod. @ mysql-test/r/func_math.result New test case. @ mysql-test/t/func_math.test New test case. @ strings/decimal.c Move DBUG_ASSERT down to where we actually dereference the loop pointer. modified: mysql-test/r/func_math.result mysql-test/t/func_math.test strings/decimal.c === modified file 'mysql-test/r/func_math.result' --- a/mysql-test/r/func_math.result 2011-07-18 07:47:39 +0000 +++ b/mysql-test/r/func_math.result 2011-07-18 09:21:14 +0000 @@ -709,3 +709,22 @@ foo select 999999999999999999999999999999999999999999999999999999999999999999999999999999999 % 0.0 as foo; foo NULL +# +# Bug#12711164 - 61676: +# RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE +# +select 5 div 2; +5 div 2 +2 +select 5.0 div 2.0; +5.0 div 2.0 +2 +select 5.0 div 2; +5.0 div 2 +2 +select 5 div 2.0; +5 div 2.0 +2 +select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2; +5.9 div 2 1.23456789e3 DIV 2 1.23456789e9 DIV 2 1.23456789e19 DIV 2 +2 617 617283945 6172839450000000000 === modified file 'mysql-test/t/func_math.test' --- a/mysql-test/t/func_math.test 2011-07-18 07:47:39 +0000 +++ b/mysql-test/t/func_math.test 2011-07-18 09:21:14 +0000 @@ -547,3 +547,14 @@ let $nine_81= eval select $nine_81 % 0.1 as foo; eval select $nine_81 % 0.0 as foo; + +--echo # +--echo # Bug#12711164 - 61676: +--echo # RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE +--echo # + +select 5 div 2; +select 5.0 div 2.0; +select 5.0 div 2; +select 5 div 2.0; +select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2; === modified file 'sql/item_func.cc' --- a/sql/item_func.cc 2011-07-07 11:22:43 +0000 +++ b/sql/item_func.cc 2011-07-18 09:21:14 +0000 @@ -1605,8 +1605,13 @@ longlong Item_func_int_div::val_int() return 0; } + my_decimal truncated; + const bool do_truncate= true; + if (my_decimal_round(E_DEC_FATAL_ERROR, &tmp, 0, do_truncate, &truncated)) + DBUG_ASSERT(false); + longlong res; - if (my_decimal2int(E_DEC_FATAL_ERROR, &tmp, unsigned_flag, &res) & + if (my_decimal2int(E_DEC_FATAL_ERROR, &truncated, unsigned_flag, &res) & E_DEC_OVERFLOW) raise_integer_overflow(); return res; No bundle (reason: useless for push emails).