From 3e8d9ec450ab34885dff84002344412e7561d465 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 14 Mar 2019 05:53:15 +0300 Subject: [PATCH] Added a test for multiple JOINs from Denny Crane #4571 --- ...00917_multiple_joins_denny_crane.reference | 2 + .../00917_multiple_joins_denny_crane.sql | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.reference create mode 100644 dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.sql diff --git a/dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.reference b/dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.reference new file mode 100644 index 00000000000..0b1df65ee71 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.reference @@ -0,0 +1,2 @@ +CAT 2 +CAT 2 diff --git a/dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.sql b/dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.sql new file mode 100644 index 00000000000..d1e137c0f40 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00917_multiple_joins_denny_crane.sql @@ -0,0 +1,40 @@ +USE test; + +DROP TABLE IF EXISTS ANIMAL; + +CREATE TABLE ANIMAL ( ANIMAL Nullable(String) ) engine = TinyLog; +INSERT INTO ANIMAL (ANIMAL) VALUES ('CAT'), ('FISH'), ('DOG'), ('HORSE'), ('BIRD'); + +set enable_optimize_predicate_expression = 0; + +select * from ( +select x.b x, count(distinct x.c) ANIMAL +from ( +select a.ANIMAL a, 'CAT' b, c.ANIMAL c, d.ANIMAL d +from ANIMAL a join ANIMAL b on a.ANIMAL = b.ANIMAL + left outer join ANIMAL c on (b.ANIMAL = c.ANIMAL) + right outer join (select * from ANIMAL union all select * from ANIMAL + union all select * from ANIMAL) d on (a.ANIMAL = d.ANIMAL) +where d.ANIMAL <> 'CAT' and c.ANIMAL <>'DOG' and b.ANIMAL <> 'FISH') as x +where x.b >= 'CAT' +group by x.b +having ANIMAL >= 0) ANIMAL +where ANIMAL.ANIMAL >= 0; + +set enable_optimize_predicate_expression = 1; + +select * from ( +select x.b x, count(distinct x.c) ANIMAL +from ( +select a.ANIMAL a, 'CAT' b, c.ANIMAL c, d.ANIMAL d +from ANIMAL a join ANIMAL b on a.ANIMAL = b.ANIMAL + left outer join ANIMAL c on (b.ANIMAL = c.ANIMAL) + right outer join (select * from ANIMAL union all select * from ANIMAL + union all select * from ANIMAL) d on (a.ANIMAL = d.ANIMAL) +where d.ANIMAL <> 'CAT' and c.ANIMAL <>'DOG' and b.ANIMAL <> 'FISH') as x +where x.b >= 'CAT' +group by x.b +having ANIMAL >= 0) ANIMAL +where ANIMAL.ANIMAL >= 0; + +DROP TABLE ANIMAL;