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

LP:869012 - Wrong result with semijoin + materialization + AND in WHERE

    Details

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

      Description

      The following query:

      SELECT *
      FROM t1 , t2
      WHERE ( t1.f4 ) IN ( SELECT f4 FROM t3 )
      AND t2.f4 != t1.f3 ;

      returns no rows when executed with semijoin+materialization, even though the correct result is:

      x x g
      x x g

      as those rows do match the WHERE predicate.

      Explain:

      1 PRIMARY t2 ALL NULL NULL NULL NULL 1  
      1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1 Using where
      1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
      2 SUBQUERY t3 ALL NULL NULL NULL NULL 1  

      minimal optimizer switch:semijoin=on,materialization=on
      full 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=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,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

      bzr version-info:
      revision-id: <email address hidden>
      date: 2011-10-06 01:21:15 +0400
      build-date: 2011-10-06 12:19:12 +0300
      revno: 3213
      branch-nick: maria-5.3

      test case:

      --source include/have_innodb.inc
      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (f3 varchar(1) , f4 varchar(1) ) engine=InnoDB;
      INSERT IGNORE INTO t1 VALUES ('x','x'),('x','x');

      DROP TABLE IF EXISTS t2;
      CREATE TABLE t2 ( f4 varchar(1) ) ;
      INSERT IGNORE INTO t2 VALUES ('g');

      DROP TABLE IF EXISTS t3;
      CREATE TABLE t3 (f4 varchar(1) ) Engine=InnoDB;
      INSERT IGNORE INTO t3 VALUES ('x');

      SET SESSION optimizer_switch='semijoin=on,materialization=on';
      SELECT *
      FROM t1 , t2
      WHERE ( t1.f4 ) IN ( SELECT f4 FROM t3 )
      AND t2.f4 != t1.f3 ;

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            psergey Sergei Petrunia added a comment -

            Re: Wrong result with semijoin + materialization + AND in WHERE
            The bug can only be repeated after

            ALTER TABLE t2 engine=innodb;

            Show
            psergey Sergei Petrunia added a comment - Re: Wrong result with semijoin + materialization + AND in WHERE The bug can only be repeated after ALTER TABLE t2 engine=innodb;
            Hide
            psergey Sergei Petrunia added a comment -

            Re: Wrong result with semijoin + materialization + AND in WHERE
            This bug has most likely been introduced by this change:

            revno: 3053.1.1
            revision-id: psergey@askmonty.org-20110621215728-6tkzlruy8iiv1nxf
            parent: timour@askmonty.org-20110621200101-9jh217r9zk71qhz1
            committer: Sergey Petrunya <psergey@askmonty.org>
            branch nick: 5.3-sj1
            timestamp: Wed 2011-06-22 01:57:28 +0400
            message:
            Make semi-joins work with outer joins part #1:

            • Make make_outerjoin_info() correctly process semi-join nests
            • Make make_join_select() attach conditions to the right places.
            Show
            psergey Sergei Petrunia added a comment - Re: Wrong result with semijoin + materialization + AND in WHERE This bug has most likely been introduced by this change: revno: 3053.1.1 revision-id: psergey@askmonty.org-20110621215728-6tkzlruy8iiv1nxf parent: timour@askmonty.org-20110621200101-9jh217r9zk71qhz1 committer: Sergey Petrunya <psergey@askmonty.org> branch nick: 5.3-sj1 timestamp: Wed 2011-06-22 01:57:28 +0400 message: Make semi-joins work with outer joins part #1: Make make_outerjoin_info() correctly process semi-join nests Make make_join_select() attach conditions to the right places.
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 869012

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

              People

              • Assignee:
                psergey Sergei Petrunia
                Reporter:
                philipstoev Philip Stoev
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: