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

LP:813473 - Wrong result with outer join + NOT IN subquery

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      Repeatable in maria-5.3, maria-5.2, maria-5.1, mysql-5.5 . Not repeatable in mysql-5.1. Not influenced by optimizer switches.

      The following query:

      SELECT t2.b , t1.c
      FROM t2 LEFT JOIN t1 ON t2.a != 0
      WHERE ( t2.b , t1.c ) NOT IN ( SELECT 2 , 9 );

      does not return rows for which the WHERE predicate is true. It returns an empty result in maria and mysql-5.5 and in mysql-5.1 it returns:

      b c
      9 NULL
      9 NULL

      test case:

      CREATE TABLE t1 (c int) ;

      CREATE TABLE t2 (a int, b int) ;
      INSERT INTO t2 VALUES (20,9),(20,9);

      SELECT t2.b , t1.c
      FROM t2 LEFT JOIN t1 ON t2.a != 0
      WHERE ( t2.b , t1.c ) NOT IN ( SELECT 2 , 9 );

      explain:

      1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
      2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used

      optimizer switch:

      index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

      revision-id: <email address hidden>
      date: 2011-07-20 11:56:28 +0400
      build-date: 2011-07-20 15:37:47 +0300
      revno: 3123
      branch-nick: maria-5.3

      test case:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (c int) ;

      DROP TABLE IF EXISTS t2;
      CREATE TABLE t2 (a int, b int) ;
      INSERT INTO t2 VALUES (20,9),(20,9);

      SELECT t2.b , t1.c
      FROM t2 LEFT JOIN t1 ON t2.a != 0
      WHERE ( t2.b , t1.c ) NOT IN ( SELECT 2 , 9 );

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            timour Timour Katchaounov added a comment -

            Re: Wrong result with outer join + NOT IN subquery
            This a very old bug that is present in most mysql/mariadb versions.

            Show
            timour Timour Katchaounov added a comment - Re: Wrong result with outer join + NOT IN subquery This a very old bug that is present in most mysql/mariadb versions.
            Hide
            timour Timour Katchaounov added a comment -

            Re: Wrong result with outer join + NOT IN subquery
            An example that demonstrates that the wrong result is
            reproducible without constant tables:

            CREATE TABLE t1 (c int) ;
            INSERT INTO t1 VALUES (5),(6);

            CREATE TABLE t2 (a int, b int) ;
            INSERT INTO t2 VALUES (20,9),(20,9);

            create table t3 (d int, e int);
            insert into t3 values (2, 9), (3,10);

            EXPLAIN
            SELECT t2.b , t1.c
            FROM t2 LEFT JOIN t1 ON t1.c < 3
            WHERE ( t2.b , t1.c ) NOT IN ( SELECT * from t3);

            SELECT t2.b , t1.c
            FROM t2 LEFT JOIN t1 ON t1.c < 3
            WHERE (t2.b, t1.c) NOT IN ( SELECT * from t3);

            Show
            timour Timour Katchaounov added a comment - Re: Wrong result with outer join + NOT IN subquery An example that demonstrates that the wrong result is reproducible without constant tables: CREATE TABLE t1 (c int) ; INSERT INTO t1 VALUES (5),(6); CREATE TABLE t2 (a int, b int) ; INSERT INTO t2 VALUES (20,9),(20,9); create table t3 (d int, e int); insert into t3 values (2, 9), (3,10); EXPLAIN SELECT t2.b , t1.c FROM t2 LEFT JOIN t1 ON t1.c < 3 WHERE ( t2.b , t1.c ) NOT IN ( SELECT * from t3); SELECT t2.b , t1.c FROM t2 LEFT JOIN t1 ON t1.c < 3 WHERE (t2.b, t1.c) NOT IN ( SELECT * from t3);
            Hide
            timour Timour Katchaounov added a comment -

            Re: Wrong result with outer join + NOT IN subquery
            This bug is a duplicate of MySQL's Bug#11764086.

            Show
            timour Timour Katchaounov added a comment - Re: Wrong result with outer join + NOT IN subquery This bug is a duplicate of MySQL's Bug#11764086.
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 813473

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 813473

              People

              • Assignee:
                timour Timour Katchaounov
                Reporter:
                philipstoev Philip Stoev
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: