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

Oracle outer join syntax (+): query with checking for null of non-null column uses wrong query plan and returns wrong result

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 12.1
    • N/A
    • Optimizer
    • None
    • Not for Release Notes
    • Q3/2025 Maintenance

    Description

      If in the query there is a checking for null of non-null column then it uses wrong query plan and returns wrong result.
      In testcase below the query plan for oracle join ( + ) is like INNER JOIN, not LEFT JOIN:

      Testcase:

      create table t1 (a int default NULL);
      create table t2 (a int not null);
      insert into t1 values (1), (2), (3), (4), (5), (6), (NULL);
      insert into t2 values (1), (4), (5), (6), (7);
       
      select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
      explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
       
      select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
      explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
       
      select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1;
      explain extended select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1;
       
      drop table t1,t2;
      

      Results:

      select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
      a	a
       
      explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
      id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
      1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
      

      select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
      a	a
      2	NULL
      3	NULL
      NULL	NULL
      explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
       
      id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
      1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	
      1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	5	Using where; Using join buffer (flat, BNL join)
      

      select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1;
      a	a
       
      explain extended select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1;
      id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
      1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
      Warnings:
      Note	1003	select "test"."t1"."a" AS "a","test"."t2"."a" AS "a" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0
      

      Attachments

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              lstartseva Lena Startseva
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.