set SQL_MODE= oracle;
create table t1 (a int);
insert into t1 values (1),(2),(3);
create table t2 (b int);
insert into t2 values (2),(1),(20);
create table t3 (c int, e int);
insert into t3 values (3,2),(10,3),(2,20);
create table t4 (d int);
insert into t4 values (3),(1),(20);
select t1.a, t4.d, t2.b, t3.c
from t1, t2, t3, t4
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
a d b c 33 NULL 3 111 NULL 13 NULL NULL 23 NULL NULL 21 NULL NULL 31 NULL NULL 120 NULL NULL 220 NULL NULL 320 NULL NULL
explain extended
select t1.a, t4.d, t2.b, t3.c
from t1, t2, t3, t4
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3100.00 1 SIMPLE t4 ALL NULL NULL NULL NULL 3100.00 Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t4"."d" AS "d","test"."t2"."b" AS "b","test"."t3"."c" AS "c" from "test"."t1" join "test"."t4" left join "test"."t2" on("test"."t4"."d" = "test"."t1"."a"and"test"."t2"."b" = "test"."t1"."a") left join "test"."t3" on("test"."t4"."d" = "test"."t1"."a"and"test"."t3"."c" = "test"."t1"."a") where 1
select t1.a, t4.d, t2.b, t3.c
from t4, t3, t2, t1
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
a d b c 111 NULL 33 NULL 3 13 NULL NULL 120 NULL NULL 23 NULL NULL 21 NULL NULL 220 NULL NULL 31 NULL NULL 320 NULL NULL
explain extended
select t1.a, t4.d, t2.b, t3.c
from t4, t3, t2, t1
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t4 ALL NULL NULL NULL NULL 3100.00 1 SIMPLE t1 ALL NULL NULL NULL NULL 3100.00 Using join buffer (flat, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t4"."d" AS "d","test"."t2"."b" AS "b","test"."t3"."c" AS "c" from "test"."t4" join "test"."t1" left join "test"."t3" on("test"."t1"."a" = "test"."t4"."d"and"test"."t3"."c" = "test"."t4"."d") left join "test"."t2" on("test"."t1"."a" = "test"."t4"."d"and"test"."t2"."b" = "test"."t4"."d") where 1
select t1.a, t4.d, t2.b, t3.c
from t2, t1, t4, t3
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
a d b c 33 NULL 3 111 NULL 13 NULL NULL 23 NULL NULL 21 NULL NULL 31 NULL NULL 120 NULL NULL 220 NULL NULL 320 NULL NULL
explain extended
select t1.a, t4.d, t2.b, t3.c
from t2, t1, t4, t3
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3100.00 1 SIMPLE t4 ALL NULL NULL NULL NULL 3100.00 Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t4"."d" AS "d","test"."t2"."b" AS "b","test"."t3"."c" AS "c" from "test"."t1" join "test"."t4" left join "test"."t2" on("test"."t4"."d" = "test"."t1"."a"and"test"."t2"."b" = "test"."t1"."a") left join "test"."t3" on("test"."t4"."d" = "test"."t1"."a"and"test"."t3"."c" = "test"."t1"."a") where 1
select t1.a, t4.d, t2.b, t3.c
from t3, t4, t1, t2
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
a d b c 111 NULL 33 NULL 3 13 NULL NULL 120 NULL NULL 23 NULL NULL 21 NULL NULL 220 NULL NULL 31 NULL NULL 320 NULL NULL
explain extended
select t1.a, t4.d, t2.b, t3.c
from t3, t4, t1, t2
where
t1.a = t2.b(+) and
t1.a = t3.c(+) and
t4.d = t2.b(+) and
t4.d = t3.c(+);
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t4 ALL NULL NULL NULL NULL 3100.00 1 SIMPLE t1 ALL NULL NULL NULL NULL 3100.00 Using join buffer (flat, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (incremental, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t4"."d" AS "d","test"."t2"."b" AS "b","test"."t3"."c" AS "c" from "test"."t4" join "test"."t1" left join "test"."t3" on("test"."t1"."a" = "test"."t4"."d"and"test"."t3"."c" = "test"."t4"."d") left join "test"."t2" on("test"."t1"."a" = "test"."t4"."d"and"test"."t2"."b" = "test"."t4"."d") where 1
drop table t1, t2, t3, t4;
#
# tests of Iqbal Hassan <iqbal@hasprime.com>
# (with 2 fixes)
#
CREATE TABLE tj1(a int, b int);
CREATE TABLE tj2(c int, d int);
CREATE TABLE tj3(e int, f int);
CREATE TABLE tj4(b int, c int);
INSERT INTO tj1 VALUES (1, 1);
INSERT INTO tj1 VALUES (2, 2);
INSERT INTO tj2 VALUES (2, 3);
INSERT INTO tj3 VALUES (1, 4);
#
# Basic test
#
SELECT * FROM tj1,tj2 WHERE tj1.a = tj2.c(+);
a b c d 2223 11 NULL NULL
#
# Compare marked with literal
#
SELECT * FROM tj1,tj2 WHERE tj1.a = tj2.c(+) AND tj2.d(+) > 4;
a b c d 11 NULL NULL 22 NULL NULL
explain extended
SELECT * FROM tj1,tj2 WHERE tj1.a = tj2.c(+) AND tj2.d(+) > 4;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE tj1 ALL NULL NULL NULL NULL 2100.00 1 SIMPLE tj2 ALL NULL NULL NULL NULL 1100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."tj1"."a" AS "a","test"."tj1"."b" AS "b","test"."tj2"."c" AS "c","test"."tj2"."d" AS "d" from "test"."tj1" left join "test"."tj2" on("test"."tj2"."c" = "test"."tj1"."a"and"test"."tj2"."d" > 4) where 1
#
# Use both marked and unmarked field in the same condition
#
SELECT * FROM tj1,tj2 WHERE tj1.a = tj2.c(+) AND tj2.d = 3;
a b c d 2223
#
# Use both marked and unmarked field in OR condition
#
SELECT * FROM tj2,tj1 WHERE tj1.a = tj2.c(+) OR tj2.d=4; ERROR HY000: Invalid usage of (+) operator: cycle dependencies
SELECT * FROM tj1,tj2,tj3 WHERE tj1.a = tj3.e(+) AND (tj1.a = tj2.c(+) OR tj2.d=4); ERROR HY000: Invalid usage of (+) operator: cycle dependencies
#
# Use unmarked fields in OR condition
#
SELECT * FROM tj2,tj1 WHERE tj1.a = tj2.c(+) AND (tj2.d=3OR tj2.d * 2=3);
c d a b 2322
#
# Use marked fields in OR condition when all fields are marked
#
SELECT * FROM tj1,tj2 WHERE tj1.a = tj2.c(+) AND (tj2.d(+)=3OR tj2.c(+)=1);
a b c d 2223 11 NULL NULL
#
# Use more than one marked table per condition
#
SELECT * FROM tj1,tj2,tj3 WHERE tj1.a = tj2.c(+) + tj3.e(+); ERROR HY000: Invalid usage of (+) operator: both tables tj2 and tj3 are of INNER type in the relation
#
# Use different tables per `AND` operand
#
SELECT * FROM tj1,tj2,tj3 WHERE tj1.a = tj2.c(+) AND tj1.a = tj3.e(+);
a b c d e f 11 NULL NULL 14 2223 NULL NULL
#
# Ensure table dependencies are properly resolved
#
SELECT * FROM tj1,tj2,tj3 WHERE tj1.a = tj3.e AND tj1.a + 1 = tj2.c(+);
a b c d e f 112314
SELECT * FROM tj1,tj2,tj3 WHERE tj1.a = tj2.c(+) AND tj2.c = tj3.e(+) + 1;
a b c d e f 222314 11 NULL NULL NULL NULL
SELECT * FROM tj1, tj2, tj3 WHERE tj1.a + tj3.e = tj2.c(+);
a b c d e f 112314 22 NULL NULL 14
#
# Cyclic dependency of tables
# ORA-01416 two tables cannot be outer-joined to each other
#
SELECT * FROM tj1,tj2,tj3 WHERE tj1.a = tj2.c(+) AND tj2.c = tj3.e(+) + 1AND tj3.e = tj1.a(+); ERROR HY000: Invalid usage of (+) operator: cycle dependencies
#
# Table not referenced in where condition (must be cross-joined)
#
SELECT * FROM tj1, tj2, tj3 WHERE tj1.a + 1 = tj2.c(+);
a b c d e f 112314 22 NULL NULL 14
#
# Alias
#
SELECT * FROM tj1, tj2 b WHERE tj1.a + 1 = b.c(+);
a b c d 1123 22 NULL NULL
#
# Subselect
#
SELECT * FROM tj1, (SELECT * from tj2) b WHERE tj1.a + 1 = b.c(+);
a b c d 1123 22 NULL NULL
SELECT * FROM tj1, (SELECT * FROM tj1, tj2 d WHERE tj1.a = d.c(+)) b WHERE tj1.a + 1 = b.c(+);
a b a b c d 112223 22 NULL NULL NULL NULL
#
# Single table
#
SELECT * FROM tj1 WHERE tj1.a(+) = 1;
a b 11
Warnings:
Warning 4237 Oracle outer join operator (+) ignored in '"test"."tj1"."a" = 1'
#
# Self outer join
#
SELECT * FROM tj1 a, tj1 b WHERE a.a + 1 = b.a(+);
a b a b 1122 22 NULL NULL
#
# Self outer join without alias
#
SELECT * FROM tj1, tj2 WHERE tj1.a + 1 = tj1.a(+); ERROR HY000: Invalid usage of (+) operator: cycle dependencies
#
# Outer join condition is independent of other tables
# In this case we need to restrict the marked table(s) to appear
# after the unmarked table(s) during topological sort. This test
# ensures that the topological sort is working correctly.
#
# correct result in is empty result set (tj2.c = 1 filters all out)
SELECT * FROM tj1, tj2 WHERE tj2.c(+) = 1;
a b c d
Warnings:
Warning 4237 Oracle outer join operator (+) ignored in '"test"."tj2"."c" = 1'
# one row (there is tj1.a = 1)
SELECT * FROM tj1, tj2 WHERE tj1.a(+) = 1;
a b c d 1123
Warnings:
Warning 4237 Oracle outer join operator (+) ignored in '"test"."tj1"."a" = 1'
#
# Outer join in 'IN' condition
# ORA-01719
#
SELECT * FROM tj1, tj2 WHERE tj1.a IN (tj2.c(+), tj2.d(+)); ERROR HY000: Invalid usage of (+) operator: used in OR, IN or ROW operation
SELECT * FROM tj1, tj2 WHERE tj1.a NOT IN (tj2.c(+), tj2.d(+)); ERROR HY000: Invalid usage of (+) operator: used in OR, IN or ROW operation
#
# Outer join in 'IN' condition with a single expression
# This is also allowed in oracle since the expression is
# can be simplified to 'equal'or'not equal' condition
#
SELECT * FROM tj1, tj2 WHERE tj1.a IN (tj2.c(+));
a b c d 2223 11 NULL NULL
SELECT * FROM tj1, tj2 WHERE tj1.a NOT IN (tj2.c(+));
a b c d 1123 22 NULL NULL
#
# Oracle outer join not in WHERE clause
#
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c GROUP BY tj2.c(+); ERROR42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c GROUP BY tj2.c HAVING tj2.c(+) > 1; ERROR42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') > 1' at line 1
SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c ORDER BY tj2.c(+); ERROR42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
SELECT tj2.c(+) FROM tj2; ERROR42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') FROM tj2' at line 1
#
# Mix ANSI and Oracle outer join
# ORA-25156
SELECT * FROM tj1 LEFT JOIN tj2 ON tj2.c = 1 WHERE tj1.a = tj2.c(+); ERROR HY000: Invalid usage of (+) operator: mixed with other type of join
SELECT * FROM tj1 INNER JOIN tj2 ON tj2.c = 1 WHERE tj1.a = tj2.c(+); ERROR HY000: Invalid usage of (+) operator: mixed with other type of join
SELECT * FROM tj1 NATURAL JOIN tj2 WHERE tj1.a = tj2.c(+); ERROR HY000: Invalid usage of (+) operator: mixed with other type of join
#
# View with oracle outer join
#
CREATE VIEW v1 AS SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c(+);
SELECT * FROM v1;
a b c d 2223 11 NULL NULL
#
# Cursor with oracle outer join
#
DECLARE
CURSOR c1 IS SELECT * FROM tj1, tj2 WHERE tj1.a = tj2.c(+);
BEGIN
FOR r1 IN c1 LOOP
SELECT r1.a || ' ' || r1.c;
END LOOP;
END
$$
r1.a || ' ' || r1.c 22
r1.a || ' ' || r1.c 1
#
# Marking ROW type
#
DECLARE
v1 ROW (a INT, b INT);
BEGIN
SELECT * FROM tj1 WHERE tj1.a = v1.a(+);
END
$$ ERROR42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ');
END' at line 4
#
# Unspecified table used in WHERE clause that contains (+)
#
SELECT * FROM tj1, tj2 WHERE tj1.a = tj3.c(+); ERROR42S22: Unknown column 'tj3.c' in 'WHERE'
#
# '.' prefixed table name
#
SELECT * FROM tj1, tj2 WHERE tj1.a = .tj2.c(+);
a b c d 2223 11 NULL NULL
CREATE DATABASE db1;
USE db1;
CREATE TABLE tj1(a int, b int);
INSERT INTO tj1 VALUES (3, 3);
INSERT INTO tj1 VALUES (4, 4);
#
# DB qualifed ident with oracle outer join (aliased)
#
SELECT * FROM test.tj2 a, tj1 WHERE a.c(+) = tj1.a - 1;
c d a b 2333
NULL NULL 44
#
# DB qualifed ident with oracle outer join (non-aliased)
#
SELECT * FROM test.tj2, tj1 WHERE test.tj2.c(+) = tj1.a - 1;
c d a b 2333
NULL NULL 44
#
# DB qualifed ident with oracle outer join (aliased but use table name)
#
SELECT * FROM test.tj2 a, tj1 WHERE test.tj2.c(+) = tj1.a - 1; ERROR42S22: Unknown column 'test.tj2.c' in 'WHERE'
USE test;
#
# UPDATE with oracle outer join
#
UPDATE tj1, tj2 SET tj1.a = tj2.c WHERE tj1.a = tj2.c(+);
SELECT * FROM tj1;
a b
NULL 1 22
#
# DELETE with oracle outer join
#
DELETE tj1 FROM tj1, tj2 WHERE tj1.b(+) = tj2.c;
SELECT * FROM tj1;
a b
NULL 1
DROP DATABASE db1;
DROP VIEW v1;
DROP TABLE tj4;
DROP TABLE tj3;
DROP TABLE tj2;
DROP TABLE tj1;
#
# End of iqbal-rsec tests
#
#
# Test from the MDEV comments
#
create table t1 (a int);
insert into t1 values (1),(2),(3);
create table t2 (b int);
insert into t2 values (2),(1),(20);
create table t3 (c int, e int);
insert into t3 values (3,2),(10,3),(2,20);
create table t4 (d int);
insert into t4 values (3),(1),(20);
select t1.a, t4.d, t2.b, t3.c from t1, t2, t3, t4 where t1.a = t2.b(+) and t1.a = t3.c(+) and t4.d = t2.b(+) and t4.d = t3.c(+);
a d b c 33 NULL 3 111 NULL 13 NULL NULL 23 NULL NULL 21 NULL NULL 31 NULL NULL 120 NULL NULL 220 NULL NULL 320 NULL NULL
select t1.a, t4.d, t2.b, t3.c from t1, t2, t3, t4 where t1.a + t3.c = t2.b(+) and t1.a = t3.c(+) andt4.d = t2.b(+) and t4.d = t3.c(+);
a d b c 33 NULL 3 13 NULL NULL 23 NULL NULL 11 NULL NULL 21 NULL NULL 31 NULL NULL 120 NULL NULL 220 NULL NULL 320 NULL NULL
select t1.a, t4.d, t2.b, t3.c from t1, t2, t3, t4 where (t2.b(+) in (t1.a, t1.a+1)) and t1.a = t3.c(+) and t4.d = t2.b(+) and t4.d = t3.c(+);
a d b c 33 NULL 3 111 NULL 13 NULL NULL 23 NULL NULL 21 NULL NULL 31 NULL NULL 120 NULL NULL 220 NULL NULL 320 NULL NULL
drop tables t1, t2, t3, t4;
create table t1 (a int);
insert into t1 values (1),(2),(3);
create table t2 (b int);
insert into t2 values (2),(1),(20);
create table t3 (c int, f int);
insert into t3 values (3,2),(10,3),(2,20);
create table t4 (d int);
insert into t4 values (3),(1),(20);
create table t5 (e int);
insert into t5 values (3),(2),(20);
select t1.a, t2.b, t3.c, t4.d, t5.e from t1, t2, t3, t4, t5 where t1.a = t2.b(+) and t2.b = t3.c(+) and t1.a = t4.d(+) and t4.d=t5.e(+) and t3.c=t5.e(+);
a b c d e 11 NULL 1 NULL 222 NULL NULL 3 NULL NULL 3 NULL
select t1.a, t2.b, t3.c, t4.d, t5.e from t1, t2, t3, t4, t5 where t1.a = t2.b(+) and t2.b = t3.c(+) and t1.a = t4.d(+) and t4.d=t5.e(+) and1=t5.e(+);
a b c d e 3 NULL NULL 3 NULL 11 NULL 1 NULL 222 NULL NULL
select t1.a, t2.b, t3.c, t4.d, t5.e from t1, t2, t3, t4, t5 where t1.a = t2.b(+) and t2.b = t3.c(+) and t1.a = t4.d(+) and t4.d=t5.e(+) and3=t5.e(+);
a b c d e 3 NULL NULL 33 11 NULL 1 NULL 222 NULL NULL
select t1.a, t2.b, t3.c, t4.d, t5.e from t1, (t2, t3), t4, t5 where t1.a = t2.b(+) and t2.b = t3.c(+) and t1.a = t4.d(+) and t4.d=t5.e(+) and3=t5.e(+); ERROR HY000: Invalid usage of (+) operator: mixed with other type of join
drop tables t1, t2, t3, t4, t5;
create table t1 (a int);
insert into t1 values (1),(2),(3);
create table t2 (b int);
insert into t2 values (2),(1),(20);
select t1.a, t2.b from t1, t2 where 1 = t2.b(+);
a b 11 21 31
Warnings:
Warning 4237 Oracle outer join operator (+) ignored in '1 = "test"."t2"."b"'
select t1.a, t2.b from t2, t1 where 1 = t2.b(+);
a b 11 21 31
Warnings:
Warning 4237 Oracle outer join operator (+) ignored in '1 = "test"."t2"."b"'
select t1.a,t2.b from t2,t1 where t2.b(+) in (1,2);
a b 12 11 22 21 32 31
Warnings:
Warning 4237 Oracle outer join operator (+) ignored in '"test"."t2"."b" in (1,2)'
select t2.b from t2 where 1 = t2.b(+);
b 1
Warnings:
Warning 4237 Oracle outer join operator (+) ignored in '1 = "test"."t2"."b"'
drop tables t1, t2;
create table t1 (a int);
insert into t1 values (1),(2),(4),(5),(20),(21),(23);
create table t2 (b int);
insert into t2 values (1),(4),(6),(7),(8),(23);
create table t3 (c int);
insert into t3 values (4),(7),(9),(4),(6),(10),(11),(1);
create table t4 (d int);
insert into t4 values (1),(4),(10),(12),(20),(21),(23);
SELECT * FROM t1,t2,t3,t4 WHERE t1.a = t2.b(+) AND t1.a = t3.c(+) AND t2.b=t4.d(+) AND t3.c=t4.d(+);
a b c d 1111 4444 4444 2323 NULL NULL 2 NULL NULL NULL 5 NULL NULL NULL 20 NULL NULL NULL 21 NULL NULL NULL
select * from t1, t2, t3 where (t1.a + t2.b = t3.c(+));
a b c 167 189 279 549 246 516 2810 4610 4711 5611 11 NULL 14 NULL 17 NULL 123 NULL 21 NULL 26 NULL 223 NULL 41 NULL 44 NULL 48 NULL 423 NULL 57 NULL 58 NULL 523 NULL 201 NULL 204 NULL 206 NULL 207 NULL 208 NULL 2023 NULL 211 NULL 214 NULL 216 NULL 217 NULL 218 NULL 2123 NULL 231 NULL 234 NULL 236 NULL 237 NULL 238 NULL 2323 NULL
# no tables mentioned
select * from t2, t3 where b = c(+);
b c 44 77 44 66 11 8 NULL 23 NULL
# should be the same as above
select * from t2, t3 where t2.b = t3.c(+);
b c 44 77 44 66 11 8 NULL 23 NULL
drop tables t1, t2, t3, t4;
#
# View creation and usage
#
create table t1 (a int);
insert into t1 values (1),(2),(3);
create table t2 (b int);
insert into t2 values (2),(1),(20);
create view v1 as
select t1.a, t2.b from t1, t2 where t1.a = t2.b(+);
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE VIEW "v1" AS select "t1"."a" AS "a","t2"."b" AS "b" from ("t1" left join "t2" on("t1"."a" = "t2"."b")) latin1 latin1_swedish_ci
select * from v1;
a b 22 11 3 NULL
select t1.a, t2.b from t1, t2 where t1.a = t2.b(+);
a b 22 11 3 NULL
usage without oracle sql mode set SQL_MODE= '';
select * from v1;
a b 22 11 3 NULL
select t1.a, t2.b from t1, t2 where t1.a = t2.b(+); ERROR42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 set SQL_MODE= oracle;
drop view v1;
drop table t1,t2;
#
# MDEV-36830: Oracle outer join syntax (+): outer join not converted to inner
#
create table t1 (
a int not null,
b int not null
);
insert into t1 select seq,seq from seq_1_to_10;
create table t2 (
a int not null,
b int not null
);
insert into t2 select seq,seq from seq_1_to_3;
# Must be converted to inner join:
explain extended
select * from t1, t2
where
t1.a=1and
t1.b=t2.b(+) and
t2.b=1;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 3100.00 Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL 10100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."b" AS "b","test"."t2"."a" AS "a","test"."t2"."b" AS "b" from "test"."t1" join "test"."t2" where "test"."t1"."a" = 1and"test"."t2"."b" = 1and"test"."t1"."b" = 1
drop table t1,t2;
#
# MDEV-36838: Oracle outer join syntax (+): server crash on derived tables
#
select a.a
from (select 1 as a) a,
(select 2 as b) b
where a.a=b.b(+);
a 1
#
# MDEV-36866: Oracle outer join syntax (+): query with checking for
# null of non-null column uses wrong query plan and returns wrong
# result
#
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;
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 2 NULL 3 NULL
NULL NULL
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 t1 ALL NULL NULL NULL NULL 7100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 5100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t2"."a" AS "a" from "test"."t1" left join "test"."t2" on("test"."t2"."a" = "test"."t1"."a") where "test"."t2"."a" is null = 1
drop table t1,t2;
#
# Correct nullability test
#
create table t1 (a int not null, s varchar(10) not null);
create table t2 (a int not null, s varchar(10) not null);
insert into t1 values (1, 'one');
insert into t1 values (2, 'two');
insert into t2 values (2, 'two');
insert into t2 values (3, 'three');
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(t2.a);
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2100.00 Using where; Not exists; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on("test"."t2"."a" = "test"."t1"."a") where "test"."t2"."a" is null
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(t1.a+t2.a);
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on("test"."t2"."a" = "test"."t1"."a") where "test"."t1"."a" + "test"."t2"."a" is null
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(coalesce(t2.s, 'null'));
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"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(ifnull(t2.s, 'null'));
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"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(coalesce(t2.s, null));
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on("test"."t2"."a" = "test"."t1"."a") where coalesce("test"."t2"."s",NULL) is null
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(ifnull(t2.s, null));
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on("test"."t2"."a" = "test"."t1"."a") where ifnull("test"."t2"."s",NULL) is null
# Our optimizer does not optimize out never-null-subselects under
# isnull() so we do not test it. The following test is to make
# sure that nullable one stay in the WHERE.
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(t2.a in (select a from t1));
id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 2100.00 Using where; Using join buffer (flat, BNL join) 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2100.00
Warnings:
Note 1003/* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on("test"."t2"."a" = "test"."t1"."a") where <expr_cache><"test"."t2"."a">(<in_optimizer>("test"."t2"."a","test"."t2"."a" in ( <materialize> (/* select#2 */ select "test"."t1"."a" from "test"."t1" ), <primary_index_lookup>("test"."t2"."a" in <temporary table> on distinct_key where "test"."t2"."a" = "<subquery2>"."a")))) is null
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(t2.a in (1, 2, 3));
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 2100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on("test"."t2"."a" = "test"."t1"."a") where "test"."t2"."a" in (1,2,3) is null
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(t1.a in (1, 2, 3));
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"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(isnull(t2.a));
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"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(field(t2.a, 2, 23));
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"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0
explain extended
select * from t1,t2 where t1.a = t2.a (+) and
isnull(benchmark(10, t2.a));
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"."t1"."s" AS "s","test"."t2"."a" AS "a","test"."t2"."s" AS "s" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0
drop table t1, t2;
#
# MDEV-36895: Oracle outer join syntax (+): some NULLs missing from
# result of the query with derived tables and limit
#
create table t2 (b int);
insert into t2 values (3),(7),(1);
create table t3 (c int);
insert into t3 values (3),(1);
create table t1 (a int);
insert into t1 values (1),(2),(7),(1);
select * from
(
select * from
(select 'Z' as z, t1.a from t1) dt1
left join
(select 'Y' as y, t2.b from t2) dt2
left join
(select 'X' as x, t3.c from t3) dt3
on dt2.b=dt3.c
on dt1.a=dt2.b
order by z, a, y, b, x, c
limit 9
) dt;
z a y b x c
Z 1 Y 1 X 1
Z 1 Y 1 X 1
Z 2 NULL NULL NULL NULL
Z 7 Y 7 NULL NULL
select * from
(
select * from
(select 'Z' as z, t1.a from t1) dt1
,(select * from
(select 'Y' as y, t2.b from t2) dt2
,
(select 'X' as x, t3.c from t3) dt3
where dt2.b=dt3.c(+)
) tdt2
where dt1.a=tdt2.b(+)
order by z, a, y, b, x, c
limit 9
) dt;
z a y b x c
Z 1 Y 1 X 1
Z 1 Y 1 X 1
Z 2 NULL NULL NULL NULL
Z 7 Y 7 NULL NULL
drop table t1, t2, t3;
#
# MDEV-37337: Oracle outer join syntax (+): IN equal to = allow (+) on right side
#
create table t1 (a int);
insert into t1 values (1),(2),(3);
create table t2 (b int);
insert into t2 values (2),(1),(20); set SQL_MODE= oracle;
select t1.a, t2.b
from t1, t2
where
t1.a = t2.b(+);
a b 22 11 3 NULL
select t1.a, t2.b
from t1, t2
where
t1.a IN (t2.b(+));
a b 22 11 3 NULL
explain extended
select t1.a, t2.b
from t1, t2
where
t1.a IN (t2.b(+));
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t2"."b" AS "b" from "test"."t1" left join "test"."t2" on("test"."t2"."b" = "test"."t1"."a") where 1
select t1.a, t2.b
from t1, t2
where
t1.a IN (t2.b(+), 29); ERROR HY000: Invalid usage of (+) operator: used in OR, IN or ROW operation
DROP TABLE t1, t2;
create table t1 (a int);
insert into t1 values (1),(2),(3);
create table t2 (b int);
insert into t2 values (2),(1),(20); set SQL_MODE= oracle;
select t1.a, t2.b
from t1, t2
where
t1.a = t2.b(+);
a b 22 11 3 NULL
select t1.a, t2.b
from t1, t2
where
t1.a IN (t2.b(+));
a b 22 11 3 NULL
explain extended
select t1.a, t2.b
from t1, t2
where
t1.a IN (t2.b(+));
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3100.00 1 SIMPLE t2 ALL NULL NULL NULL NULL 3100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select "test"."t1"."a" AS "a","test"."t2"."b" AS "b" from "test"."t1" left join "test"."t2" on("test"."t2"."b" = "test"."t1"."a") where 1
select t1.a, t2.b
from t1, t2
where
t1.a IN (t2.b(+), 29); ERROR HY000: Invalid usage of (+) operator: used in OR, IN or ROW operation
DROP TABLE t1, t2;
# End of 12.1 tests
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.