Bug #45782 Query with nested JOIN + GROUP BY sporadically returns bad results

Submitted: 26 Jun 2009 10:10 Modified: 26 Jun 2009 13:07
Reporter: Philip Stoev Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:5.1 OS:Any
Assigned to: CPU Architecture:Any

[26 Jun 2009 10:10] Philip Stoev
Description:
Queries of the following form

  SELECT table3 .`date_key` field1  FROM B table1
  LEFT JOIN B table3
  JOIN (
        C table6
        JOIN A table7
        ON table6 .`varchar_nokey`
  ) ON table6 .`int_nokey`
  ON table6 .`date_key`
  WHERE  NOT ( table1 .`varchar_key`  AND table7 .`pk`  )
  GROUP  BY field1

(or very likely simpler ones) produce inconsistent results when run multiple times on a server that is executing other concurrent queries.

See also bug #45266 in Azalea.

How to repeat:
To reproduce:

1. Use the Random Query Generator (in the mysql-test/gentest directory of the mysql-test-extra-6.0 tree) to run the following

$ perl runall.pl --basedir1=/build/bzr/mysql-5.1/ --grammar=conf/join.yy --threads=1 --queries=100000

Ignore any output from this script, it is just there to provide the background query load that is required for the bug to show up.

2. In a separate console, use the following script to run the offending query numerous times:

use strict;
use DBI;
$| = 1;

my $dsn = 'dbi:mysql:host=127.0.0.1:port=19306:user=root:database=test';
my $query = "
  SELECT table3 .`date_key` field1  FROM B table1
  LEFT JOIN B table3
  JOIN (
        C table6
        JOIN A table7
        ON table6 .`varchar_nokey`
  ) ON table6 .`int_nokey`
  ON table6 .`date_key`
  WHERE  NOT ( table1 .`varchar_key`  AND table7 .`pk`  )
  GROUP  BY field1
";

my $dbh = DBI->connect($dsn);
foreach my $trial (1..150000) {
        my $sth = $dbh->prepare($query);
        $sth->execute();
        print localtime()." [$$] trial: $trial; rows ".$sth->rows()."\n";
        exit if $sth->rows() != 1;
}

After a few thousand queries, the query will return zero rows.
[26 Jun 2009 13:07] Evgeny Potemkin
Duplicate of the bug#45266.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.060 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.