I have confirmed that this problem exhibits itself on the Mysql AB
compiled binaries that are compiled with gcc, both Standard and Max, but
does _not_ exhibit itself on the Mysql AB binary built with the Intel C++
Compiler 8.1 (mysql-standard-4.1.12-pc-linux-gnu-i686-icc-glibc23.tar.gz).
I have also verifed that the problem does _not_ exhibit on the mysql-4.12
server in Debian stable (Sarge), nor in Gentoo's latest ebuild.
I believe this problem likely stems from a compiler problem with the version
(2.95.3 20010315 SuSE) of GCC that Mysql AB compiles with.
# GCC: mysql-standard-4.1.12-pc-linux-gnu-i686.tar.gz
[EMAIL PROTECTED]:/usr/local# ls -l mysql
lrwxrwxrwx 1 root root 9 Jul 8 21:25 /usr/local/mysql -> mysql-gcc/
[EMAIL PROTECTED]:/usr/local# ./mysql/bin/mysqld_safe --user=mysql &
[EMAIL PROTECTED]:/# /usr/local/mysql/bin/mysql test
[...snip...]
mysql> select * from foo1 left join foo2 on foo2.test1 between foo1.test1 and
foo1.test2;
+---++---+---+
| test1 | test2 | test1 | test2 |
+---++---+---+
| 97.50 | 154.30 | NULL | NULL |
+---++---+---+
1 row in set (0.00 sec)
[EMAIL PROTECTED]:/usr/local# ./mysql/bin/mysqladmin shutdown
STOPPING server from pid file /usr/local/mysql/data/ponybox.pid
050708 21:30:36 mysqld ended
# ICC: mysql-standard-4.1.12-pc-linux-gnu-i686-icc-glibc23.tar.gz
[EMAIL PROTECTED]:/usr/local# rm mysql && ln -s mysql-icc mysql
[EMAIL PROTECTED]:/usr/local# ./mysql/bin/mysqld_safe --user=mysql &
[EMAIL PROTECTED]:/# /usr/local/mysql/bin/mysql test
[...snip...]
mysql> select * from foo1 left join foo2 on foo2.test1 between foo1.test1 and
foo1.test2;
+---++++
| test1 | test2 | test1 | test2 |
+---++++
| 97.50 | 154.30 | 154.30 | 154.30 |
+---++++
--
Lester Hightower <[EMAIL PROTECTED]>
10East Corp.
On Fri, 8 Jul 2005 [EMAIL PROTECTED] wrote:
Description:
There appears to be a type promotion problem involving sql statements which
include a 'between' comparison and a decimal type field is one of the operands.
How-To-Repeat:
CREATE TABLE `foo1` (
`test1` decimal(7,2) NOT NULL default '0.00',
`test2` decimal(7,2) NOT NULL default '0.00'
);
INSERT INTO `foo1` (`test1`, `test2`) VALUES ('97.50','154.30');
CREATE TABLE `foo2` (
`test1` decimal(7,2) NOT NULL default '0.00',
`test2` decimal(7,2) NOT NULL default '0.00'
);
INSERT INTO `foo2` (`test1`, `test2`) VALUES ('154.30','154.30');
CREATE TABLE `foo3` (
`test1` float(7,2) NOT NULL default '0.00',
`test2` float(7,2) NOT NULL default '0.00'
);
INSERT INTO `foo3` (`test1`, `test2`) VALUES (97.50,154.30);
CREATE TABLE `foo4` (
`test1` float(7,2) NOT NULL default '0.00',
`test2` float(7,2) NOT NULL default '0.00'
);
INSERT INTO `foo4` (`test1`, `test2`) VALUES (154.30,154.30);
select * from foo1 left join foo2 on foo2.test1 between foo1.test1 and
foo1.test2;
+---++---+---+
| test1 | test2 | test1 | test2 |
+---++---+---+
| 97.50 | 154.30 | NULL | NULL |
+---++---+---+
1 row in set (0.00 sec)
select * from foo3 left join foo4 on foo4.test2 between foo3.test1 and
foo3.test2;
+---++++
| test1 | test2 | test1 | test2 |
+---++++
| 97.50 | 154.30 | 154.30 | 154.30 |
+---++++
1 row in set (0.00 sec)
mysql> select * from foo1 where test1 between 97.50 and 154.30;
+---++
| test1 | test2 |
+---++
| 97.50 | 154.30 |
+---++
1 row in set (0.00 sec)
mysql> select * from foo1 where 154.30 between test1 and test2;
Empty set (0.00 sec)
mysql> select * from foo1 where test2 between 154.30 and test2;
Empty set (0.00 sec)
Fix:
A work around is to include OR conditions that are equal comparisons to the
boundary condition of the BETWEEN. This query demonstrates a work around.
mysql> select * from foo1 where test2 between 154.30 and test2 or 154.30=test2;
+---++
| test1 | test2 |
+---++
| 97.50 | 154.30 |
+---++
1 row in set (0.00 sec)
Originator: Tom Allen
Organization:
10 East Corp
MySQL support: none
Synopsis: BETWEEN comparisons with one or more DECIMAL type fields as
operands don't handle boundary conditions properly
Severity: <[ non-critical | serious | critical ] (one line)>
Priority: <[ low | medium | high ] (one line)>
Category: mysql
Class: <[ sw-bug | doc-bug | change-request | support ] (one line)>
Release:mysql-4.1.12-max (MySQL Community Edition - Experimental (GPL))
C compiler:2.95.3
C++ compiler: 2.95.3
Environment:
System: Linux docs2 2.6.12 #1 SMP Mon Jun 20 12:08:43 EDT 2005 i686 unknown
unknown GNU/Linux
Architecture: i686
Some paths: /usr/local/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc
/usr/bin/cc
GCC: Reading specs from /usr/lib/gcc-lib/i486-sl