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

LP:922971 - Missing row in the result set of a query with IN subquery containing a left join

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • None
    • None
    • None

    Description

      Some queries with IN subqueries that contain left joins may return incomplete result set.

      The following test case provides such a query:

      CREATE TABLE t1 (a varchar(1024));
      INSERT INTO t1 VALUES ('v'), ('we');
      CREATE TABLE t2 (
      a varchar(1024) CHARACTER SET utf8 DEFAULT NULL, b int, c int
      );
      INSERT INTO t2 VALUES ('we',4,NULL), ('v',1305673728,6);
      CREATE TABLE t3 (b int, c int);
      INSERT INTO t3 VALUES (4,4);
      set @tmp_optimizer_switch=@@optimizer_switch;
      set optimizer_switch='semijoin=off';
      set optimizer_switch='materialization=off';
      et join_cache_level=2;
      SELECT * FROM t1
      WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
      WHERE t2.c < 10 OR t3.c > 1);
      set join_cache_level = default;
      set optimizer_switch=@tmp_optimizer_switch;
      DROP TABLE t1,t2,t3;

      The last SELECT returns:

      MariaDB [test]> SELECT * FROM t1
      -> WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
      -> WHERE t2.c < 10 OR t3.c > 1);
      ------

      a

      ------

      v

      ------

      while the correct answer is:

      MariaDB [test]> SELECT * FROM t1
      -> WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
      -> WHERE t2.c < 10 OR t3.c > 1);
      ------

      a

      ------

      v
      we

      ------

      Attachments

        Activity

          People

            igor Igor Babaev (Inactive)
            igor Igor Babaev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.