Back to home page

OSCL-LXR

 
 

    


0001 -- Cross join detection and error checking is done in JoinSuite since explain output is
0002 -- used in the error message and the ids are not stable. Only positive cases are checked here.
0003 -- This test file was converted from cross-join.sql.
0004 
0005 create temporary view nt1 as select * from values
0006   ("one", 1),
0007   ("two", 2),
0008   ("three", 3)
0009   as nt1(k, v1);
0010 
0011 create temporary view nt2 as select * from values
0012   ("one", 1),
0013   ("two", 22),
0014   ("one", 5)
0015   as nt2(k, v2);
0016 
0017 -- Cross joins with and without predicates
0018 SELECT * FROM nt1 cross join nt2;
0019 SELECT * FROM nt1 cross join nt2 where udf(nt1.k) = udf(nt2.k);
0020 SELECT * FROM nt1 cross join nt2 on (udf(nt1.k) = udf(nt2.k));
0021 SELECT * FROM nt1 cross join nt2 where udf(nt1.v1) = "1" and udf(nt2.v2) = "22";
0022 
0023 SELECT udf(a.key), udf(b.key) FROM
0024 (SELECT udf(k) key FROM nt1 WHERE v1 < 2) a
0025 CROSS JOIN
0026 (SELECT udf(k) key FROM nt2 WHERE v2 = 22) b;
0027 
0028 -- Join reordering 
0029 create temporary view A(a, va) as select * from nt1;
0030 create temporary view B(b, vb) as select * from nt1;
0031 create temporary view C(c, vc) as select * from nt1;
0032 create temporary view D(d, vd) as select * from nt1;
0033 
0034 -- Allowed since cross join with C is explicit
0035 select * from ((A join B on (udf(a) = udf(b))) cross join C) join D on (udf(a) = udf(d));
0036 -- Cross joins with non-equal predicates
0037 SELECT * FROM nt1 CROSS JOIN nt2 ON (udf(nt1.k) > udf(nt2.k));