Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-19588

Wrong results from query, using left join

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4
    • Fix Version/s: 5.5.65
    • Component/s: Optimizer
    • Labels:
      None

      Description

      CREATE TABLE t1 (i1 int, c1 varchar(20), pk int) engine=myisam;
       
      CREATE TABLE t2 (pk int, c1 varchar(20), i1 int) engine=myisam;
      INSERT INTO t2 VALUES (1,'a',NULL),(2,'a',777),(3,'a',192),(4,'a',284),(5,'a',2),(6,'a',NULL),(7,'a',-912),(8,'a',5),(9,'a',NULL),(10,'a',-184);
       
      CREATE TABLE t3 (pk int, c1 varchar(20), i1 int) engine=myisam ;
      INSERT INTO t3 VALUES (1,'a',-145),(2,'a',6),(3,'a',1),(4,'a',NULL),(5,'a',NULL),(6,'a',NULL),(7,'a',NULL),(8,'a',889),(9,'a',146),(10,'a',177),(11,'a',NULL),(12,'a',-183),(13,'a',-137),(14,'a',NULL),(15,'a',NULL),(16,'a',-433),(17,'a',NULL),(18,'a',2),(19,'a',3),(20,'a',5),(21,'a',-484),(22,'a',369),(23,'a',-192),(24,'a',-163),(25,'a',5),(26,'a',NULL),(27,'a',NULL),(28,'a',1),(29,'a',NULL),(30,'a',NULL),(31,'a',127),(32,'a',-424),(33,'a',3),(34,'a',-144),(35,'a',5),(36,'a',913),(37,'a',NULL),(38,'a',6),(39,'a',-173),(40,'a',4),(41,'a',101),(42,'a',-795),(43,'a',201),(44,'a',103),(45,'a',NULL),(46,'a',NULL),(47,'a',6),(48,'a',NULL),(49,'a',9),(50,'a',NULL);
       
      SELECT count(t3.c1) 
      FROM t3 LEFT JOIN t1 LEFT JOIN t2 ON t1.i1 = t2.i1 ON t3.i1 = t1.i1
      WHERE t2.pk < 13 OR t3.i1 IS NULL;
      

      The expected result is 17 rows. It is correct in versions 5.5-10.3 (and in Mysql 8.0.15), and also while using Innodb engine in 10.4
      The current result in 10.4 is 21 rows (with MyIsam)

      10.4 592fe954ef82be1b

      MariaDB [test]> SELECT count(t3.c1) 
          -> FROM t3 LEFT JOIN t1 LEFT JOIN t2 ON t1.i1 = t2.i1 ON t3.i1 = t1.i1
          -> WHERE t2.pk < 13 OR t3.i1 IS NULL;
      +--------------+
      | count(t3.c1) |
      +--------------+
      |           21 |
      +--------------+
      1 row in set (0.003 sec)
       
       
      MariaDB [test]> SELECT t3.*
          -> FROM t3 LEFT JOIN t1 LEFT JOIN t2 ON t1.i1 = t2.i1 ON t3.i1 = t1.i1
          -> WHERE t2.pk < 13 OR t3.i1 IS NULL;
      +------+------+------+
      | pk   | c1   | i1   |
      +------+------+------+
      |    4 | a    | NULL |
      |    5 | a    | NULL |
      |    6 | a    | NULL |
      |    7 | a    | NULL |
      |   11 | a    | NULL |
      |   14 | a    | NULL |
      |   15 | a    | NULL |
      |   18 | a    |    2 |
      |   20 | a    |    5 |
      |   25 | a    |    5 |
      |   17 | a    | NULL |
      |   26 | a    | NULL |
      |   27 | a    | NULL |
      |   29 | a    | NULL |
      |   30 | a    | NULL |
      |   35 | a    |    5 |
      |   37 | a    | NULL |
      |   45 | a    | NULL |
      |   46 | a    | NULL |
      |   48 | a    | NULL |
      |   50 | a    | NULL |
      +------+------+------+
      21 rows in set (0.005 sec)
      
      

      10.3 592dc59d7a5f9bd80bf

      MariaDB [test]> SELECT count(t3.c1) 
          -> FROM t3
          -> LEFT JOIN t1 LEFT JOIN t2 ON t1.i1 = t2.i1 ON t3.i1 = t1.i1
          -> WHERE t2.pk < 13 OR t3.i1 IS NULL;
      +--------------+
      | count(t3.c1) |
      +--------------+
      |           17 |
      +--------------+
      1 row in set (0.001 sec)
      
      

        Attachments

          Activity

            People

            • Assignee:
              igor Igor Babaev
              Reporter:
              alice Alice Sherepa
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: