Bug #16991 select DISTINCT returns zero rows, without distinct works
Submitted: 1 Feb 2006 1:10 Modified: 1 Mar 2006 2:17
Reporter: Brian Barnes Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.16 OS:Linux (Suse 10 64 bit)
Assigned to: CPU Architecture:Any

[1 Feb 2006 1:10] Brian Barnes
Description:
Select without distinct returns multiple, duplicate rows. Select DISTINCT returns zero rows. 

It fails on specific where clause values and works on others. 

raptor:/usr/local/mysql/bin # ./mysql --version
./mysql  Ver 14.12 Distrib 5.0.16, for unknown-linux-gnu (x86_64) using readline 5.0
raptor:/usr/local/mysql/bin # ll mysql
-rwxr-xr-x  1 root mysql 1613416 Nov 15 12:55 mysql

How to repeat:
Run the Perl script below (with the connect parameters set to your data)
=============================================================
#!/usr/local/bin/perl -w

use DBI;
$dbh = &connect();

$sql = "SELECT distinct subProjectId, subProjectDesc
FROM fgpPdSpidTwdid
where subProjectId = 7512";

&exec($sql);             # Show results with DISTINCT.
$sql =~ s/distinct//;  # Remove __DISTINCT__ from select statement.
&exec($sql);             # Show results WITHOUT___DISTINCT__

sub exec()  {
my $sql = $_[0];
my $rows = 0;
	print("\nExec: SQL = \"$sql\".\n");
	$ssh = $dbh->prepare($sql);  # Source Statement Handle.
	$ssh->execute;
	while(@ara = $ssh->fetchrow_array())  {
		printf("Fetch[$rows] has %d elements, \"%s\"\n", 
		scalar @ara, join(", ", @ara));
		$rows++;
	}
	print("SQL returned $rows rows.\n");
}

sub connect()  {
	$dhost   = "raptor";  # Destination Hostname of database server.
	$ddb     = "XXXXX";      # Destination DataBase.
	$duid    = "XXXXX";      # Destination User ID.
	$dpw     = "XXXXX";      # Destination PassWord. 
	$dbh = DBI->connect("dbi:mysql:database=$ddb;host=$dhost", 
		$duid, $dpw, {'RaiseError' => 1})		
		or die "Couldn't connect $DBI::errstr";
	return $dbh;
}
===========================================================

Results:
brianp@raptor:/usr/local/apache2/cgi-bin> mysql.bug.pl

Exec: SQL = "SELECT distinct subProjectId, subProjectDesc
FROM fgpPdSpidTwdid
where subProjectId = 7512".
SQL returned 0 rows.

Exec: SQL = "SELECT  subProjectId, subProjectDesc
FROM fgpPdSpidTwdid
where subProjectId = 7512".
Fetch[0] has 2 elements, "7512, ddr2 write"
Fetch[1] has 2 elements, "7512, ddr2 write"
SQL returned 2 rows.
brianp@raptor:/usr/local/apache2/cgi-bin>
[1 Feb 2006 2:17] Hartmut Holzgraefe
Can't reproduce this whith your PERL script alone, 
would need your table data, too, but this looks very
similar to bug report 16710

http://bugs.mysql.com/bug.php?id=16710
[2 Mar 2006 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".