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

LP:849776 - Wrong result with semijoin + "Impossible where"

    XMLWordPrintable

Details

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

    Description

      The following query:

      select * from t5 where (a) in (
      SELECT t1.a FROM t1
      LEFT JOIN t2 ON ( t1.a = t2.a ) WHERE t2.b NOT IN ( SELECT t4.b FROM t4 WHERE t4.b < t1.b ));

      returns no rows when executed with semijoin, even though the correct result must be "8", since table t5 contains the result from the subquery.

      mysql 5.5 also wrongly returns an empty result, though the plan there is different. Postgresql confirms that the correct result is "8".

      explain:

      1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
      3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables

      minimal optimizer_switch: semijoin=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=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,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-09-10 18:01:27 +0300
      build-date: 2011-09-14 11:28:19 +0300
      revno: 3183
      branch-nick: maria-5.3

      test case:

      CREATE TABLE t1 ( b varchar(1), a integer) ;
      INSERT INTO t1 VALUES ('z',8);

      CREATE TABLE t2 ( a integer, b varchar(1)) ;

      CREATE TABLE t4 ( a integer, b varchar(1)) ;

      CREATE TABLE t5 ( a integer) ;
      INSERT INTO t5 VALUES (8);

      set session optimizer_switch='semijoin=on';
      select * from t5 where (a) in (
      SELECT t1.a FROM t1
      LEFT JOIN t2 ON ( t1.a = t2.a ) WHERE t2.b NOT IN ( SELECT t4.b FROM t4 WHERE t4.b < t1.b ));

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            philipstoev Philip Stoev (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.