>Description:
When joining tables using a SELECT statement and using the DISTINCTROW modifier, I
noticed a difference in the resultset by adding the ORDER BY directive on the end of
the SQL command on a column that is not included in the result. If no join is
performed and the DISTINCTROW/ORDER BY combination is used, the results remain
correct; however, by joining the tables by a common ID, all rows with a different
value in the column being ORDERed BY are returned. I have also repeated this bug on
MySQL 3.23.49a on RedHat 7.2 using the official build on InnoDB tables.
>How-To-Repeat:
# ----------------------------
# Creating tables for the test
# ----------------------------
CREATE TABLE table1 (email varchar(50), infoID BIGINT, dateentered DATETIME);
CREATE TABLE table2 (infoID BIGINT, shipcode varchar(10));
# -----------------
# Populating table1
# -----------------
INSERT INTO table1(email, infoID, dateentered) VALUES
('[EMAIL PROTECTED]', 1, '2002-07-30 22:56:38'),
('[EMAIL PROTECTED]', 1, '2002-07-27 22:58:16'),
('[EMAIL PROTECTED]', 1, '2002-06-19 15:22:19'),
('[EMAIL PROTECTED]', 2, '2002-06-18 14:23:47'),
('[EMAIL PROTECTED]', 1, '2002-05-19 22:17:32');
INSERT INTO table2(infoID, shipcode) VALUES
(1, 'Z001'),
(2, 'R002');
# ------------------------------
# Reading out correct statements
# ------------------------------
SELECT DISTINCTROW email, shipcode FROM table1, table2 WHERE
table1.infoID=table2.infoID;
SELECT DISTINCTROW email FROM table1 ORDER BY dateentered DESC;
# -----------------------------
# Reading out erratic statement
# -----------------------------
SELECT DISTINCTROW email, shipcode FROM table1, table2 WHERE
table1.infoID=table2.infoID
ORDER BY dateentered DESC;
# -----------
# Cleaning up
# -----------
DROP TABLE table1;
DROP TABLE table2;
>Fix:
If you do not use ORDER BY, the correct resultset is returned, just not in any
particular order. ;)
>Submitter-Id: [EMAIL PROTECTED]
>Originator: Stephen Cuppett
>Organization: IBM, eServer zSeries development
>MySQL support: none
>Synopsis: JOIN-like SELECT with DISTINCTROW AND ORDER BY produces erratic results
>Severity: serious
>Priority: medium
>Category: mysql
>Class: sw-bug
>Release: mysql-3.23.51 (Official MySQL RPM)
>Server: /usr/bin/mysqladmin Ver 8.23 Distrib 3.23.51, for pc-linux-gnu on i686
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 3.23.51-Max
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 24 min 55 sec
Threads: 1 Questions: 25 Slow queries: 0 Opens: 14 Flush tables: 1 Open tables: 2
Queries per second avg: 0.017
>Environment:
System: Linux cuppett.endicott.ibm.com 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686
unknown
Architecture: i686
Some paths: /usr/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc /usr/bin/cc
GCC: Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-112)
Compilation info: CC='gcc' CFLAGS='-O6 -fno-omit-frame-pointer -mpentium' CXX='gcc'
CXXFLAGS='-O6 -fno-omit-frame-pointer -felide-constructors
-fno-exceptions -fno-rtti -mpentium' LDFLAGS=''
LIBC:
lrwxrwxrwx 1 root root 13 Jul 29 07:00 /lib/libc.so.6 -> libc-2.2.5.so
-rwxr-xr-x 1 root root 1260480 Jul 9 11:58 /lib/libc-2.2.5.so
-rw-r--r-- 1 root root 2312370 Jul 9 11:25 /usr/lib/libc.a
-rw-r--r-- 1 root root 178 Jul 9 11:19 /usr/lib/libc.so
Configure command: ./configure --disable-shared --with-mysqld-ldflags=-all-static
--with-client-ldflags=-all-static --with-other-libc=/usr/local/mysql-glibc
--without-berkeley-db --without-innodb --enable-assembler --enable-local-infile
--with-mysqld-user=mysql --with-unix-socket-path=/var/lib/mysql/mysql.sock --prefix=/
--with-extra-charsets=complex --exec-prefix=/usr --libexecdir=/usr/sbin
--sysconfdir=/etc --datadir=/usr/share --localstatedir=/var/lib/mysql
--infodir=/usr/info --includedir=/usr/include --mandir=/usr/man
'--with-comment=Official MySQL RPM' CC=gcc 'CFLAGS=-O6 -fno-omit-frame-pointer
-mpentium' 'CXXFLAGS=-O6 -fno-omit-frame-pointer -felide-constructors
-fno-exceptions -fno-rtti -mpentium' CXX=gcc
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php