Bug #28400 make test Failed mysql_client_test test_fetch_long
Submitted: 13 May 2007 14:29 Modified: 23 Jun 2007 8:45
Reporter: imacat . (Basic Quality Contributor) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Tests Severity:S7 (Test Cases)
Version:5.0.41 OS:Linux (2.6.18)
Assigned to: Georgi Kodinov CPU Architecture:Any
Tags: qc

[13 May 2007 14:29] imacat .
Description:
    Hi.  This is imacat from Taiwan.  I just downloaded the newly-released MySQL 5.0.41 source and tried to compile on my newly-upgraded Debian GNU/Linux 4.0 r0 Etch i386.  My building environment is Debian GNU/Linux 4.0 r0 Etch, kernel 2.6.18-4-686, GCC 4.1.2, glibc 2.3.6.  make test fails at mysql_client_test test_fetch_long.  I cannot succeed even with the default configuration without any parameters:

./configure

    The terminal log is attached below.  I looked into mysql-test/var/log/mysql_client_test.log, and found it stops at test_fetch_long.  I attached the part below, too.

    Hope this helps.  Please tell me if you need any information, or if I could be of any help.  Thank you.

==================
imacat@gaya src/mysql-5.0.41 % make test
Logging: ./mysql-test-run.pl
MySQL Version 5.0.41
Skipping ndbcluster, mysqld not compiled with ndbcluster
Skipping SSL, mysqld not compiled with SSL
Using MTR_BUILD_THREAD      = 0
Using MASTER_MYPORT         = 9306
Using MASTER_MYPORT1        = 9307
Using SLAVE_MYPORT          = 9308
Using SLAVE_MYPORT1         = 9309
Using SLAVE_MYPORT2         = 9310
Using IM_PORT               = 9312
Using IM_MYSQLD1_PORT       = 9313
Using IM_MYSQLD2_PORT       = 9314
Killing Possible Leftover Processes
Removing Stale Files
Creating Directories
Installing Master Database
Installing Master Database
Installing Slave1 Database
Creating IM password file (/usr/local/src/mysql-5.0.41/mysql-test/var/im.passwd)
Installing Im_mysqld_1 Database
Installing Im_mysqld_2 Database
=======================================================
Starting Tests in the 'main' suite

TEST                           RESULT         TIME (ms)
-------------------------------------------------------

alias                          [ pass ]             28
...
mysql                          [ pass ]           1979
mysql_client_test              [ fail ]

Errors are (from /usr/local/src/mysql-5.0.41/mysql-test/var/log/mysqltest-time) :
sh: line 1: 30002 Aborted                 /usr/local/src/mysql-5.0.41/tests/mysql_client_test --no-defaults --testcase --user=root --port=9306 --socket=/usr/local/src/mysql-5.0.41/mysql-test/var/tmp/master.sock --vardir=/usr/local/src/mysql-5.0.41/mysql-test/var --getopt-ll-test=25600M >>/usr/local/src/mysql-5.0.41/mysql-test/var/log/mysql_client_test.log 2>&1
mysqltest: At line 12: command "$MYSQL_CLIENT_TEST --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.log 2>&1" failed
(the last lines may be the most important ones)
Result from queries before failure can be found in r/mysql_client_test.log

Aborting: mysql_client_test failed in default mode. To continue, re-run with '--force'.
Stopping All Servers
Shutting-down Instance Manager
make: *** [test-ns] Error 1
imacat@gaya src/mysql-5.0.41 %
==================
imacat@gaya src/mysql-5.0.41 % cat mysql-test/var/log/mysql_client_test.log
/usr/local/src/mysql-5.0.41/tests/mysql_client_test --no-defaults --testcase --user=root --port=9306 --socket=/usr/local/src/mysql-5.0.41/mysql-test/var/tmp/master.sock --vardir=/usr/local/src/mysql-5.0.41/mysql-test/var

#####################################
client_connect
#####################################

...
#####################################
11 of (1/1): test_fetch_long
#####################################

 total parameters in stmt: `7` (expected: `7`)

 SELECT * FROM test_bind_fetch

        +-------------+-------------+-------------+-------------+-------------+-------------+-------------+
        | c1          | c2          | c3          | c4          | c5          | c6          | c7          |
        +-------------+-------------+-------------+-------------+-------------+-------------+-------------+
        |          13 |          26 |          39 |          52 |          65 |          78 |          91 |
        |          12 |          25 |          38 |          51 |          64 |          77 |          90 |
        |          11 |          24 |          37 |          50 |          63 |          76 |          89 |
        |          10 |          23 |          36 |          49 |          62 |          75 |          88 |
        +-------------+-------------+-------------+-------------+-------------+-------------+-------------+

        4 rows returned
mysql_client_test.c:3893: check failed: 'rc == 0'
imacat@gaya src/mysql-5.0.41 %
==================

How to repeat:
Always.  On Debian GNU/Linux 4.0r0 2.6.18-4-686, run

% ./configure
% make
% make test
[14 May 2007 9:12] Valeriy Kravchuk
Thank you for a problem report. Please, send the results of

env

from your testing environment. 

Please, also upload compressed .tar of var/log subdirectory of mysql-test directory after running this test.
[14 May 2007 9:42] imacat .
master.log in the mysql-test/var/log Directory

Attachment: mysql-5.0.41_mysql-test_var_log-master.log.tar.bz2 (application/octet-stream, text), 460.77 KiB.

[14 May 2007 9:43] imacat .
Files Other Than master.log in the mysql-test/var/log Directory

Attachment: mysql-5.0.41_mysql-test_var_log-rest.tar.bz2 (application/octet-stream, text), 43.57 KiB.

[14 May 2007 9:46] imacat .
Hi.  This is imacat from Taiwan.  The mysql-test/var/log directory is uploaded.  Here is the environment.  Please tell me if you need any more information, or if I could be of any help.  Thank you.

imacat@gaya src/mysql-5.0.41 % env
USER=imacat
LOGNAME=imacat
HOME=/home/imacat
PATH=/home/imacat/bin:/bin:/usr/bin:/opt/java/bin:/usr/local/bin
MAIL=/var/mail/imacat
SHELL=/bin/zsh
SSH_CLIENT=211.78.169.163 49745 22
SSH_CONNECTION=211.78.169.163 49745 211.78.163.131 22
SSH_TTY=/dev/pts/1
TERM=xterm
SSH_AUTH_SOCK=/var/run/ssh/ssh-imNpAn4242/agent.4242
SHLVL=1
PWD=/usr/local/src/mysql-5.0.41
OLDPWD=/usr/local/src
HISTFILE=/home/imacat/.bash_history
SAVEHIST=1000
EDITOR=nano -w
PERL5LIB=/home/imacat/lib/perl5
MAKEFLAGS=--quiet
INFOPATH=/home/imacat/share/info:/home/imacat/info:/home/imacat/local/share/info:/home/imacat/local/info
WWW_HOME=http://www.imacat.idv.tw/home/
CVSROOT=:ext:rinse.wov.idv.tw:/var/lib/cvsroot
OPENSSL_CONF=/etc/ssl/openssl.cnf
PGHOST=/var/run/postgres
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:
_=/usr/bin/env
imacat@gaya src/mysql-5.0.41 %
[24 May 2007 20:52] Peter O'Gorman
We also see this test failure on Red Hat Enterprise Linux 5, gcc-4.1 mysql-5.0.38
[4 Jun 2007 19:09] TOM DONOVAN
Also observed with MySQL 5.0.42 on Linux 2.6.18  with gcc 4.1.2.

The error is that the call to mysql_stmt_fetch in tests/mysql_client_test.c:3892 returns MYSQL_DATA_TRUNCATED.  The field  my_bind[5] (MYSQL_TYPE_DOUBLE) is incorrectly reported as being truncated.

This problem could affect any numeric field which is bound to a float or double parameter, although it is more likely to occur with doubles than floats because they occupy the fpu longer.

The function fetch_long_with_conversion in libmysql/libmysql.c:3638 uses unsafe aliasing of doubles/floats vs. int64s. Although the code looks OK, on a fast cpu with optimized code the check for truncation can happen before the fp value is fully converted.

A workaround is to build MySQL with no optimizations, or else add the gcc flag -fno-strict-aliasing.  e.g.:

  CFLAGS="-O3 -DNDEBUG -fno-strict-aliasing"  ./configure  ...options...

Some notes on unsafe aliasing which explain why the macro 'doublestore' and the (u)longlong casts in libmysql.c are evil:

gcc common Bugs:
    http://gcc.gnu.org/bugs.html#nonbugs_c
gcc Bug 21920 (Resolved - Invalid bug):
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21920
gcc "strict aliasing":  http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Optimize-Options.html#index-fstrict_002daliasi...
[5 Jun 2007 18:27] TOM DONOVAN
Looking more carefully, the truncation check for conversions to float or double are not necessary.  

  MySQL 5.0.19 libmysql/libmysql.c lines 3673 & 3686

All possible 64-bit integer values convert to either float or double OK. Precision may be lost (expected and allowed), but either float or double can represent 64-bit numbers between -9223372036854775807 and +9223372036854775807. Only the least-significant digits are lost.

SQL-92 section 4.6  "Type conversions and mixing of data types" says:
 Values of the data types NUMERIC, DECIMAL, INTEGER, SMALLINT, FLOAT, REAL, and 
 DOUBLE PRECISION are numbers and are all mutually comparable and mutually 
 assignable. If an assignment would result in a loss of the most-significant 
 digits, an exception condition is raised. If least-significant digits are lost, 
 implementation-defined rounding or truncating occurs with no exception 
 condition being raised.

These truncation checks should be removed from both the functions fetch_long_with_conversion and fetch_float_with_conversion so they never set the truncation error flag when converting numbers to float or double.
[5 Jun 2007 18:38] TOM DONOVAN
Apologies. There is a typo in my last note.  
The source code lines (truncation check) that I meant to reference are:
   MySQL 5.1.19 libmysql/libmysql.c   lines 3673 & 3686
   MySQL 5.0.42 libmysql/libmysql.c   lines 3679 & 3692
[15 Jun 2007 13:36] Valeriy Kravchuk
Tom,

Thank you for the detailed analysis. Verifed on both 5.0-BK and 5.1-BK with code review. Test failure is not repeatable when gcc 3.x.y is used for compilation.
[19 Jun 2007 15:58] Georgi Kodinov
Looks like related to bug #27383
[20 Jun 2007 8:36] Georgi Kodinov
Marking this bug as a duplicate to 27383.
[23 Jun 2007 8:45] imacat .
As the original bug reporter, I have tested the patch#29389 that comes with bug#27383.  It did solve my problem.  It looks like this bug is indeed a duplicate of bug#27383.

    Thank you for your time and effort on this.