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

LP:833600 - Wrong result with view + outer join + uncorrelated subquery (non-semijoin)

    XMLWordPrintable

Details

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

    Description

      If the following query:

      SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ;

      is run without semijoin, it returns no rows whereas if a base table is used insted of the view, the query returns:

      ------------------+

      a b a b

      ------------------+

      NULL NULL 1 0
      NULL NULL 1 0

      ------------------+

      explain:

      MariaDB [test]> explain SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ;
      --------------------------------------------------------------------------------------------------------------+

      id select_type table type possible_keys key key_len ref rows Extra

      --------------------------------------------------------------------------------------------------------------+

      1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
      1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
      2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where

      --------------------------------------------------------------------------------------------------------------+

      minimal optimizer_switch=semijoin=off;

      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=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

      test case:

      CREATE TABLE t1 ( a int, b int );
      INSERT INTO t1 VALUES (0,0),(0,0);

      CREATE TABLE t2 ( a int, b int );
      INSERT IGNORE INTO t2 VALUES (1,0),(1,0);

      CREATE TABLE t3 ( b int );
      INSERT IGNORE INTO t3 VALUES (0),(0);

      CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
      SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ;

      Repeatable in maria-5.3. Not repeatable in maria-5.2,mysql-5.5

      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.