Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 23179e1

Browse files
committed
Support correlated subquery in having clause with aggregation in subquery
1 parent f16f6f9 commit 23179e1

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

test/sql/optimizer_sql_test.cpp

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -809,40 +809,27 @@ TEST_F(OptimizerSQLTests, NestedQueryInHavingTest) {
809809
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO test2 VALUES (22, 00, '4th');");
810810

811811
TestingSQLUtil::ExecuteSQLQuery("CREATE TABLE agg(a int, b int);");
812-
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (1, 2);");
813-
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (1, 3);");
814-
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (2, 3);");
815-
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (2, 4);");
812+
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (1, 22);");
813+
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (2, 33);");
814+
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (1, 11);");
815+
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO agg VALUES (1, 11);");
816816
TestUtil(
817817
"select sum(a) as c, b from test as B group by b having exists (select b "
818818
"from test2 where a = B.b);",
819819
{"7", "11", "8", "22"}, false);
820+
// TestUtil(
821+
// "select sum(a) as d, b from test as B group by b having exists (select
822+
// b "
823+
// "from test2 where a = B.d);",
824+
// {"7", "11", "8", "22"}, false);
820825
TestUtil(
821-
"select sum(a) as c, b from test as B group by b having exists (select b "
822-
"from test2 where a = B.c);",
826+
"select sum(a) as c, b from test as B group by b having exists (select "
827+
"avg(a) from agg where b = B.b);",
828+
{"7", "11", "8", "22", "3", "33"}, false);
829+
TestUtil(
830+
"select sum(a) as c, b from test as B group by b having exists (select "
831+
"avg(a) from agg where b = B.b group by b having avg(a) < 2);",
823832
{"7", "11", "8", "22"}, false);
824-
// TestUtil(
825-
// "select b from test where a in (select a from test as t where a = "
826-
// "test.a)",
827-
// {"11", "22", "33", "0"}, false);
828-
// TestUtil(
829-
// "select B.a from test as B where exists (select b as a from test2 where "
830-
// "a = B.a) and "
831-
// "b in (select b from test where b > 22);",
832-
// {"3"}, false);
833-
// TestUtil(
834-
// "select B.a from test as B where exists (select b as a from test2 where "
835-
// "a = B.a) and "
836-
// "b in (select b from test) and c > 0;",
837-
// {"1", "3"}, false);
838-
// TestUtil(
839-
// "select t1.a, t2.a from test as t1 join test as t2 on t1.a=t2.a "
840-
// "where t1.b+t2.b in (select 2*b from test2 where a > 2)",
841-
// {"3", "3", "4", "4"}, false);
842-
// TestUtil(
843-
// "select B.a from test as B where exists (select b as a from test as T "
844-
// "where a = B.a and exists (select c from test where T.c = c));",
845-
// {"1", "2", "3", "4"}, false);
846833
}
847834

848835
} // namespace test

0 commit comments

Comments
 (0)