mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fix JOIN rewriters inconsistency (#9830)
* fix join rewrites: inconsistent visitors
This commit is contained in:
parent
5b8824c065
commit
38cbf3e6f7
@ -273,9 +273,6 @@ bool getTables(ASTSelectQuery & select, std::vector<JoinedElement> & joined_tabl
|
|||||||
if (num_using && (num_tables - num_array_join) > 2)
|
if (num_using && (num_tables - num_array_join) > 2)
|
||||||
throw Exception("Multiple CROSS/COMMA JOIN do not support USING", ErrorCodes::NOT_IMPLEMENTED);
|
throw Exception("Multiple CROSS/COMMA JOIN do not support USING", ErrorCodes::NOT_IMPLEMENTED);
|
||||||
|
|
||||||
if (num_comma && (num_comma != (joined_tables.size() - 1)))
|
|
||||||
throw Exception("Mix of COMMA and other JOINS is not supported", ErrorCodes::NOT_IMPLEMENTED);
|
|
||||||
|
|
||||||
return !(num_array_join || num_using);
|
return !(num_array_join || num_using);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,6 +639,11 @@ std::shared_ptr<ASTExpressionList> subqueryExpressionList(
|
|||||||
} /// namelesspace
|
} /// namelesspace
|
||||||
|
|
||||||
|
|
||||||
|
bool JoinToSubqueryTransformMatcher::needChildVisit(ASTPtr & node, const ASTPtr &)
|
||||||
|
{
|
||||||
|
return !node->as<ASTSubquery>();
|
||||||
|
}
|
||||||
|
|
||||||
void JoinToSubqueryTransformMatcher::visit(ASTPtr & ast, Data & data)
|
void JoinToSubqueryTransformMatcher::visit(ASTPtr & ast, Data & data)
|
||||||
{
|
{
|
||||||
if (auto * t = ast->as<ASTSelectQuery>())
|
if (auto * t = ast->as<ASTSelectQuery>())
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
bool done = false;
|
bool done = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool needChildVisit(ASTPtr &, const ASTPtr &) { return true; }
|
static bool needChildVisit(ASTPtr &, const ASTPtr &);
|
||||||
static void visit(ASTPtr & ast, Data & data);
|
static void visit(ASTPtr & ast, Data & data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -11,6 +11,7 @@ SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n `--t1_0084
|
|||||||
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n `--t1_00849.a`, \n b, \n `--t2_00849.a`, \n `t2_00849.b`, \n a AS `--t3_00849.a`, \n t3_00849.b\n FROM \n (\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a AS `--t2_00849.a`, \n t2_00849.b\n FROM t1_00849\n ALL INNER JOIN t2_00849 ON `--t1_00849.a` = `--t2_00849.a`\n ) AS `--.s`\n ALL INNER JOIN t3_00849 ON `--t2_00849.a` = `--t3_00849.a`\n) AS `--.s`\nALL INNER JOIN t4_00849 ON `--t3_00849.a` = a\nWHERE (`--t1_00849.a` = `--t2_00849.a`) AND (`--t2_00849.a` = `--t3_00849.a`) AND (`--t3_00849.a` = a)
|
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n `--t1_00849.a`, \n b, \n `--t2_00849.a`, \n `t2_00849.b`, \n a AS `--t3_00849.a`, \n t3_00849.b\n FROM \n (\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a AS `--t2_00849.a`, \n t2_00849.b\n FROM t1_00849\n ALL INNER JOIN t2_00849 ON `--t1_00849.a` = `--t2_00849.a`\n ) AS `--.s`\n ALL INNER JOIN t3_00849 ON `--t2_00849.a` = `--t3_00849.a`\n) AS `--.s`\nALL INNER JOIN t4_00849 ON `--t3_00849.a` = a\nWHERE (`--t1_00849.a` = `--t2_00849.a`) AND (`--t2_00849.a` = `--t3_00849.a`) AND (`--t3_00849.a` = a)
|
||||||
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n `--t1_00849.a`, \n b, \n `t2_00849.a`, \n `t2_00849.b`, \n a, \n t3_00849.b\n FROM \n (\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a, \n t2_00849.b\n FROM t1_00849\n CROSS JOIN t2_00849\n ) AS `--.s`\n CROSS JOIN t3_00849\n) AS `--.s`\nCROSS JOIN t4_00849
|
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n `--t1_00849.a`, \n b, \n `t2_00849.a`, \n `t2_00849.b`, \n a, \n t3_00849.b\n FROM \n (\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a, \n t2_00849.b\n FROM t1_00849\n CROSS JOIN t2_00849\n ) AS `--.s`\n CROSS JOIN t3_00849\n) AS `--.s`\nCROSS JOIN t4_00849
|
||||||
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n `--t1_00849.a`, \n b, \n `t2_00849.a`, \n `t2_00849.b`, \n a, \n t3_00849.b\n FROM \n (\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a, \n t2_00849.b\n FROM t1_00849\n CROSS JOIN t2_00849\n ) AS `--.s`\n CROSS JOIN t3_00849\n) AS `--.s`\nCROSS JOIN t4_00849
|
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n `--t1_00849.a`, \n b, \n `t2_00849.a`, \n `t2_00849.b`, \n a, \n t3_00849.b\n FROM \n (\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a, \n t2_00849.b\n FROM t1_00849\n CROSS JOIN t2_00849\n ) AS `--.s`\n CROSS JOIN t3_00849\n) AS `--.s`\nCROSS JOIN t4_00849
|
||||||
|
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a, \n t2_00849.b\n FROM t1_00849\n CROSS JOIN t2_00849\n) AS `--.s`\nCROSS JOIN t3_00849
|
||||||
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a AS `--t2_00849.a`, \n t2_00849.b\n FROM t1_00849\n ALL INNER JOIN t2_00849 ON `--t1_00849.a` = `--t2_00849.a`\n) AS `--.s`\nCROSS JOIN t3_00849
|
SELECT `--t1_00849.a` AS `t1_00849.a`\nFROM \n(\n SELECT \n a AS `--t1_00849.a`, \n b, \n t2_00849.a AS `--t2_00849.a`, \n t2_00849.b\n FROM t1_00849\n ALL INNER JOIN t2_00849 ON `--t1_00849.a` = `--t2_00849.a`\n) AS `--.s`\nCROSS JOIN t3_00849
|
||||||
SELECT * FROM t1, t2
|
SELECT * FROM t1, t2
|
||||||
1 1 1 1
|
1 1 1 1
|
||||||
|
@ -28,7 +28,7 @@ ANALYZE SELECT t1_00849.a FROM t1_00849, t2_00849, t3_00849, t4_00849 WHERE t1_0
|
|||||||
ANALYZE SELECT t1_00849.a FROM t1_00849, t2_00849, t3_00849, t4_00849;
|
ANALYZE SELECT t1_00849.a FROM t1_00849, t2_00849, t3_00849, t4_00849;
|
||||||
ANALYZE SELECT t1_00849.a FROM t1_00849 CROSS JOIN t2_00849 CROSS JOIN t3_00849 CROSS JOIN t4_00849;
|
ANALYZE SELECT t1_00849.a FROM t1_00849 CROSS JOIN t2_00849 CROSS JOIN t3_00849 CROSS JOIN t4_00849;
|
||||||
|
|
||||||
ANALYZE SELECT t1_00849.a FROM t1_00849, t2_00849 CROSS JOIN t3_00849; -- { serverError 48 }
|
ANALYZE SELECT t1_00849.a FROM t1_00849, t2_00849 CROSS JOIN t3_00849;
|
||||||
ANALYZE SELECT t1_00849.a FROM t1_00849 JOIN t2_00849 USING a CROSS JOIN t3_00849; -- { serverError 48 }
|
ANALYZE SELECT t1_00849.a FROM t1_00849 JOIN t2_00849 USING a CROSS JOIN t3_00849; -- { serverError 48 }
|
||||||
ANALYZE SELECT t1_00849.a FROM t1_00849 JOIN t2_00849 ON t1_00849.a = t2_00849.a CROSS JOIN t3_00849;
|
ANALYZE SELECT t1_00849.a FROM t1_00849 JOIN t2_00849 ON t1_00849.a = t2_00849.a CROSS JOIN t3_00849;
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT \n `--t1.a`, \n `-
|
|||||||
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT \n `--t1.a`, \n `--t2.a`, \n a AS `--t3.a`\n FROM \n (\n SELECT \n a AS `--t1.a`, \n t2.a AS `--t2.a`\n FROM t1\n ALL INNER JOIN t2 ON `--t1.a` = `--t2.a`\n ) AS `--.s`\n ALL INNER JOIN t3 ON `--t2.a` = `--t3.a`\n) AS `--.s`\nALL INNER JOIN t4 ON `--t3.a` = a\nWHERE (`--t1.a` = `--t2.a`) AND (`--t2.a` = `--t3.a`) AND (`--t3.a` = a)
|
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT \n `--t1.a`, \n `--t2.a`, \n a AS `--t3.a`\n FROM \n (\n SELECT \n a AS `--t1.a`, \n t2.a AS `--t2.a`\n FROM t1\n ALL INNER JOIN t2 ON `--t1.a` = `--t2.a`\n ) AS `--.s`\n ALL INNER JOIN t3 ON `--t2.a` = `--t3.a`\n) AS `--.s`\nALL INNER JOIN t4 ON `--t3.a` = a\nWHERE (`--t1.a` = `--t2.a`) AND (`--t2.a` = `--t3.a`) AND (`--t3.a` = a)
|
||||||
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT `--t1.a`\n FROM \n (\n SELECT a AS `--t1.a`\n FROM t1\n CROSS JOIN t2\n ) AS `--.s`\n CROSS JOIN t3\n) AS `--.s`\nCROSS JOIN t4
|
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT `--t1.a`\n FROM \n (\n SELECT a AS `--t1.a`\n FROM t1\n CROSS JOIN t2\n ) AS `--.s`\n CROSS JOIN t3\n) AS `--.s`\nCROSS JOIN t4
|
||||||
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT `--t1.a`\n FROM \n (\n SELECT a AS `--t1.a`\n FROM t1\n CROSS JOIN t2\n ) AS `--.s`\n CROSS JOIN t3\n) AS `--.s`\nCROSS JOIN t4
|
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT `--t1.a`\n FROM \n (\n SELECT a AS `--t1.a`\n FROM t1\n CROSS JOIN t2\n ) AS `--.s`\n CROSS JOIN t3\n) AS `--.s`\nCROSS JOIN t4
|
||||||
|
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT a AS `--t1.a`\n FROM t1\n CROSS JOIN t2\n) AS `--.s`\nCROSS JOIN t3
|
||||||
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT \n a AS `--t1.a`, \n t2.a AS `--t2.a`\n FROM t1\n ALL INNER JOIN t2 ON `--t1.a` = `--t2.a`\n) AS `--.s`\nCROSS JOIN t3
|
SELECT `--t1.a` AS `t1.a`\nFROM \n(\n SELECT \n a AS `--t1.a`, \n t2.a AS `--t2.a`\n FROM t1\n ALL INNER JOIN t2 ON `--t1.a` = `--t2.a`\n) AS `--.s`\nCROSS JOIN t3
|
||||||
SELECT * FROM t1, t2
|
SELECT * FROM t1, t2
|
||||||
1 1 1 1
|
1 1 1 1
|
||||||
|
@ -28,7 +28,7 @@ ANALYZE SELECT t1.a FROM t1, t2, t3, t4 WHERE t1.a = t2.a AND t2.a = t3.a AND t3
|
|||||||
ANALYZE SELECT t1.a FROM t1, t2, t3, t4;
|
ANALYZE SELECT t1.a FROM t1, t2, t3, t4;
|
||||||
ANALYZE SELECT t1.a FROM t1 CROSS JOIN t2 CROSS JOIN t3 CROSS JOIN t4;
|
ANALYZE SELECT t1.a FROM t1 CROSS JOIN t2 CROSS JOIN t3 CROSS JOIN t4;
|
||||||
|
|
||||||
ANALYZE SELECT t1.a FROM t1, t2 CROSS JOIN t3; -- { serverError 48 }
|
ANALYZE SELECT t1.a FROM t1, t2 CROSS JOIN t3;
|
||||||
ANALYZE SELECT t1.a FROM t1 JOIN t2 USING a CROSS JOIN t3; -- { serverError 48 }
|
ANALYZE SELECT t1.a FROM t1 JOIN t2 USING a CROSS JOIN t3; -- { serverError 48 }
|
||||||
ANALYZE SELECT t1.a FROM t1 JOIN t2 ON t1.a = t2.a CROSS JOIN t3;
|
ANALYZE SELECT t1.a FROM t1 JOIN t2 ON t1.a = t2.a CROSS JOIN t3;
|
||||||
|
|
||||||
|
@ -1,14 +1,25 @@
|
|||||||
1
|
1
|
||||||
|
2 fail: correlated subquery
|
||||||
3
|
3
|
||||||
|
4 fail: exists
|
||||||
5
|
5
|
||||||
6
|
6
|
||||||
0.0000
|
0.0000
|
||||||
|
7
|
||||||
|
8
|
||||||
9
|
9
|
||||||
10
|
10
|
||||||
|
11
|
||||||
12
|
12
|
||||||
|
13 fail: join predicates
|
||||||
14
|
14
|
||||||
0.00000000
|
0.00000000
|
||||||
|
15 fail: correlated subquery
|
||||||
16
|
16
|
||||||
|
17 fail: correlated subquery
|
||||||
18
|
18
|
||||||
19
|
19
|
||||||
0.0000
|
0.0000
|
||||||
|
20 fail: correlated subquery
|
||||||
|
21 fail: exists, not exists
|
||||||
|
22 fail: not exists
|
||||||
|
@ -137,51 +137,51 @@ order by
|
|||||||
l_returnflag,
|
l_returnflag,
|
||||||
l_linestatus;
|
l_linestatus;
|
||||||
|
|
||||||
-- select 2; -- rewrite fail
|
select 2, 'fail: correlated subquery'; -- TODO: Missing columns: 'p_partkey'
|
||||||
-- select
|
select
|
||||||
-- s_acctbal,
|
s_acctbal,
|
||||||
-- s_name,
|
s_name,
|
||||||
-- n_name,
|
n_name,
|
||||||
-- p_partkey,
|
p_partkey,
|
||||||
-- p_mfgr,
|
p_mfgr,
|
||||||
-- s_address,
|
s_address,
|
||||||
-- s_phone,
|
s_phone,
|
||||||
-- s_comment
|
s_comment
|
||||||
-- from
|
from
|
||||||
-- part,
|
part,
|
||||||
-- supplier,
|
supplier,
|
||||||
-- partsupp,
|
partsupp,
|
||||||
-- nation,
|
nation,
|
||||||
-- region
|
region
|
||||||
-- where
|
where
|
||||||
-- p_partkey = ps_partkey
|
p_partkey = ps_partkey
|
||||||
-- and s_suppkey = ps_suppkey
|
and s_suppkey = ps_suppkey
|
||||||
-- and p_size = 15
|
and p_size = 15
|
||||||
-- and p_type like '%BRASS'
|
and p_type like '%BRASS'
|
||||||
-- and s_nationkey = n_nationkey
|
and s_nationkey = n_nationkey
|
||||||
-- and n_regionkey = r_regionkey
|
and n_regionkey = r_regionkey
|
||||||
-- and r_name = 'EUROPE'
|
and r_name = 'EUROPE'
|
||||||
-- and ps_supplycost = (
|
and ps_supplycost = (
|
||||||
-- select
|
select
|
||||||
-- min(ps_supplycost)
|
min(ps_supplycost)
|
||||||
-- from
|
from
|
||||||
-- partsupp,
|
partsupp,
|
||||||
-- supplier,
|
supplier,
|
||||||
-- nation,
|
nation,
|
||||||
-- region
|
region
|
||||||
-- where
|
where
|
||||||
-- p_partkey = ps_partkey
|
p_partkey = ps_partkey
|
||||||
-- and s_suppkey = ps_suppkey
|
and s_suppkey = ps_suppkey
|
||||||
-- and s_nationkey = n_nationkey
|
and s_nationkey = n_nationkey
|
||||||
-- and n_regionkey = r_regionkey
|
and n_regionkey = r_regionkey
|
||||||
-- and r_name = 'EUROPE'
|
and r_name = 'EUROPE'
|
||||||
-- )
|
)
|
||||||
-- order by
|
order by
|
||||||
-- s_acctbal desc,
|
s_acctbal desc,
|
||||||
-- n_name,
|
n_name,
|
||||||
-- s_name,
|
s_name,
|
||||||
-- p_partkey
|
p_partkey
|
||||||
-- limit 100;
|
limit 100; -- { serverError 47 }
|
||||||
|
|
||||||
select 3;
|
select 3;
|
||||||
select
|
select
|
||||||
@ -208,7 +208,7 @@ order by
|
|||||||
o_orderdate
|
o_orderdate
|
||||||
limit 10;
|
limit 10;
|
||||||
|
|
||||||
-- select 4;
|
select 4, 'fail: exists'; -- TODO
|
||||||
-- select
|
-- select
|
||||||
-- o_orderpriority,
|
-- o_orderpriority,
|
||||||
-- count(*) as order_count
|
-- count(*) as order_count
|
||||||
@ -269,85 +269,85 @@ where
|
|||||||
and toDecimal32(0.06, 2) + toDecimal32(0.01, 2)
|
and toDecimal32(0.06, 2) + toDecimal32(0.01, 2)
|
||||||
and l_quantity < 24;
|
and l_quantity < 24;
|
||||||
|
|
||||||
-- select 7;
|
select 7;
|
||||||
-- select
|
select
|
||||||
-- supp_nation,
|
supp_nation,
|
||||||
-- cust_nation,
|
cust_nation,
|
||||||
-- l_year,
|
l_year,
|
||||||
-- sum(volume) as revenue
|
sum(volume) as revenue
|
||||||
-- from
|
from
|
||||||
-- (
|
(
|
||||||
-- select
|
select
|
||||||
-- n1.n_name as supp_nation,
|
n1.n_name as supp_nation,
|
||||||
-- n2.n_name as cust_nation,
|
n2.n_name as cust_nation,
|
||||||
-- extract(year from l_shipdate) as l_year,
|
extract(year from l_shipdate) as l_year,
|
||||||
-- l_extendedprice * (1 - l_discount) as volume
|
l_extendedprice * (1 - l_discount) as volume
|
||||||
-- from
|
from
|
||||||
-- supplier,
|
supplier,
|
||||||
-- lineitem,
|
lineitem,
|
||||||
-- orders,
|
orders,
|
||||||
-- customer,
|
customer,
|
||||||
-- nation n1,
|
nation n1,
|
||||||
-- nation n2
|
nation n2
|
||||||
-- where
|
where
|
||||||
-- s_suppkey = l_suppkey
|
s_suppkey = l_suppkey
|
||||||
-- and o_orderkey = l_orderkey
|
and o_orderkey = l_orderkey
|
||||||
-- and c_custkey = o_custkey
|
and c_custkey = o_custkey
|
||||||
-- and s_nationkey = n1.n_nationkey
|
and s_nationkey = n1.n_nationkey
|
||||||
-- and c_nationkey = n2.n_nationkey
|
and c_nationkey = n2.n_nationkey
|
||||||
-- and (
|
and (
|
||||||
-- (n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')
|
(n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')
|
||||||
-- or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')
|
or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')
|
||||||
-- )
|
)
|
||||||
-- and l_shipdate between date '1995-01-01' and date '1996-12-31'
|
and l_shipdate between date '1995-01-01' and date '1996-12-31'
|
||||||
-- ) as shipping
|
) as shipping
|
||||||
-- group by
|
group by
|
||||||
-- supp_nation,
|
supp_nation,
|
||||||
-- cust_nation,
|
cust_nation,
|
||||||
-- l_year
|
l_year
|
||||||
-- order by
|
order by
|
||||||
-- supp_nation,
|
supp_nation,
|
||||||
-- cust_nation,
|
cust_nation,
|
||||||
-- l_year;
|
l_year;
|
||||||
|
|
||||||
-- select 8;
|
select 8;
|
||||||
-- select
|
select
|
||||||
-- o_year,
|
o_year,
|
||||||
-- sum(case
|
sum(case
|
||||||
-- when nation = 'BRAZIL' then volume
|
when nation = 'BRAZIL' then volume
|
||||||
-- else 0
|
else 0
|
||||||
-- end) / sum(volume) as mkt_share
|
end) / sum(volume) as mkt_share
|
||||||
-- from
|
from
|
||||||
-- (
|
(
|
||||||
-- select
|
select
|
||||||
-- extract(year from o_orderdate) as o_year,
|
extract(year from o_orderdate) as o_year,
|
||||||
-- l_extendedprice * (1 - l_discount) as volume,
|
l_extendedprice * (1 - l_discount) as volume,
|
||||||
-- n2.n_name as nation
|
n2.n_name as nation
|
||||||
-- from
|
from
|
||||||
-- part,
|
part,
|
||||||
-- supplier,
|
supplier,
|
||||||
-- lineitem,
|
lineitem,
|
||||||
-- orders,
|
orders,
|
||||||
-- customer,
|
customer,
|
||||||
-- nation n1,
|
nation n1,
|
||||||
-- nation n2,
|
nation n2,
|
||||||
-- region
|
region
|
||||||
-- where
|
where
|
||||||
-- p_partkey = l_partkey
|
p_partkey = l_partkey
|
||||||
-- and s_suppkey = l_suppkey
|
and s_suppkey = l_suppkey
|
||||||
-- and l_orderkey = o_orderkey
|
and l_orderkey = o_orderkey
|
||||||
-- and o_custkey = c_custkey
|
and o_custkey = c_custkey
|
||||||
-- and c_nationkey = n1.n_nationkey
|
and c_nationkey = n1.n_nationkey
|
||||||
-- and n1.n_regionkey = r_regionkey
|
and n1.n_regionkey = r_regionkey
|
||||||
-- and r_name = 'AMERICA'
|
and r_name = 'AMERICA'
|
||||||
-- and s_nationkey = n2.n_nationkey
|
and s_nationkey = n2.n_nationkey
|
||||||
-- and o_orderdate between date '1995-01-01' and date '1996-12-31'
|
and o_orderdate between date '1995-01-01' and date '1996-12-31'
|
||||||
-- and p_type = 'ECONOMY ANODIZED STEEL'
|
and p_type = 'ECONOMY ANODIZED STEEL'
|
||||||
-- ) as all_nations
|
) as all_nations
|
||||||
-- group by
|
group by
|
||||||
-- o_year
|
o_year
|
||||||
-- order by
|
order by
|
||||||
-- o_year;
|
o_year;
|
||||||
|
|
||||||
select 9;
|
select 9;
|
||||||
select
|
select
|
||||||
@ -417,37 +417,37 @@ order by
|
|||||||
revenue desc
|
revenue desc
|
||||||
limit 20;
|
limit 20;
|
||||||
|
|
||||||
-- select 11; -- rewrite fail
|
select 11; -- TODO: remove toDecimal()
|
||||||
-- select
|
select
|
||||||
-- ps_partkey,
|
ps_partkey,
|
||||||
-- sum(ps_supplycost * ps_availqty) as value
|
sum(ps_supplycost * ps_availqty) as value
|
||||||
-- from
|
from
|
||||||
-- partsupp,
|
partsupp,
|
||||||
-- supplier,
|
supplier,
|
||||||
-- nation
|
nation
|
||||||
-- where
|
where
|
||||||
-- ps_suppkey = s_suppkey
|
ps_suppkey = s_suppkey
|
||||||
-- and s_nationkey = n_nationkey
|
and s_nationkey = n_nationkey
|
||||||
-- and n_name = 'GERMANY'
|
and n_name = 'GERMANY'
|
||||||
-- group by
|
group by
|
||||||
-- ps_partkey having
|
ps_partkey having
|
||||||
-- sum(ps_supplycost * ps_availqty) > (
|
sum(ps_supplycost * ps_availqty) > (
|
||||||
-- select
|
select
|
||||||
-- sum(ps_supplycost * ps_availqty) * 0.0100000000
|
sum(ps_supplycost * ps_availqty) * toDecimal64('0.0100000000', 2)
|
||||||
-- -- ^^^^^^^^^^^^
|
-- ^^^^^^^^^^^^
|
||||||
-- -- The above constant needs to be adjusted according
|
-- The above constant needs to be adjusted according
|
||||||
-- -- to the scale factor (SF): constant = 0.0001 / SF.
|
-- to the scale factor (SF): constant = 0.0001 / SF.
|
||||||
-- from
|
from
|
||||||
-- partsupp,
|
partsupp,
|
||||||
-- supplier,
|
supplier,
|
||||||
-- nation
|
nation
|
||||||
-- where
|
where
|
||||||
-- ps_suppkey = s_suppkey
|
ps_suppkey = s_suppkey
|
||||||
-- and s_nationkey = n_nationkey
|
and s_nationkey = n_nationkey
|
||||||
-- and n_name = 'GERMANY'
|
and n_name = 'GERMANY'
|
||||||
-- )
|
)
|
||||||
-- order by
|
order by
|
||||||
-- value desc;
|
value desc;
|
||||||
|
|
||||||
select 12;
|
select 12;
|
||||||
select
|
select
|
||||||
@ -479,27 +479,27 @@ group by
|
|||||||
order by
|
order by
|
||||||
l_shipmode;
|
l_shipmode;
|
||||||
|
|
||||||
-- select 13; -- rewrite fail
|
select 13, 'fail: join predicates'; -- TODO: Invalid expression for JOIN ON
|
||||||
-- select
|
select
|
||||||
-- c_count,
|
c_count,
|
||||||
-- count(*) as custdist
|
count(*) as custdist
|
||||||
-- from
|
from
|
||||||
-- (
|
(
|
||||||
-- select
|
select
|
||||||
-- c_custkey,
|
c_custkey,
|
||||||
-- count(o_orderkey)
|
count(o_orderkey)
|
||||||
-- from
|
from
|
||||||
-- customer left outer join orders on
|
customer left outer join orders on
|
||||||
-- c_custkey = o_custkey
|
c_custkey = o_custkey
|
||||||
-- and o_comment not like '%special%requests%'
|
and o_comment not like '%special%requests%'
|
||||||
-- group by
|
group by
|
||||||
-- c_custkey
|
c_custkey
|
||||||
-- ) as c_orders
|
) as c_orders
|
||||||
-- group by
|
group by
|
||||||
-- c_count
|
c_count
|
||||||
-- order by
|
order by
|
||||||
-- custdist desc,
|
custdist desc,
|
||||||
-- c_count desc;
|
c_count desc; -- { serverError 403 }
|
||||||
|
|
||||||
select 14;
|
select 14;
|
||||||
select
|
select
|
||||||
@ -516,39 +516,40 @@ where
|
|||||||
and l_shipdate >= date '1995-09-01'
|
and l_shipdate >= date '1995-09-01'
|
||||||
and l_shipdate < date '1995-09-01' + interval '1' month;
|
and l_shipdate < date '1995-09-01' + interval '1' month;
|
||||||
|
|
||||||
-- select 15;
|
select 15, 'fail: correlated subquery'; -- TODO: Missing columns: 'total_revenue'
|
||||||
-- create view revenue0 as
|
drop table if exists revenue0;
|
||||||
-- select
|
create view revenue0 as
|
||||||
-- l_suppkey,
|
select
|
||||||
-- sum(l_extendedprice * (1 - l_discount))
|
l_suppkey,
|
||||||
-- from
|
sum(l_extendedprice * (1 - l_discount))
|
||||||
-- lineitem
|
from
|
||||||
-- where
|
lineitem
|
||||||
-- l_shipdate >= date '1996-01-01'
|
where
|
||||||
-- and l_shipdate < date '1996-01-01' + interval '3' month
|
l_shipdate >= date '1996-01-01'
|
||||||
-- group by
|
and l_shipdate < date '1996-01-01' + interval '3' month
|
||||||
-- l_suppkey;
|
group by
|
||||||
-- select
|
l_suppkey;
|
||||||
-- s_suppkey,
|
select
|
||||||
-- s_name,
|
s_suppkey,
|
||||||
-- s_address,
|
s_name,
|
||||||
-- s_phone,
|
s_address,
|
||||||
-- total_revenue
|
s_phone,
|
||||||
-- from
|
total_revenue
|
||||||
-- supplier,
|
from
|
||||||
-- revenue0
|
supplier,
|
||||||
-- where
|
revenue0
|
||||||
-- s_suppkey = supplier_no
|
where
|
||||||
-- and total_revenue = (
|
s_suppkey = supplier_no
|
||||||
-- select
|
and total_revenue = (
|
||||||
-- max(total_revenue)
|
select
|
||||||
-- from
|
max(total_revenue)
|
||||||
-- revenue0
|
from
|
||||||
-- )
|
revenue0
|
||||||
-- order by
|
)
|
||||||
-- s_suppkey;
|
order by
|
||||||
-- drop view revenue0;
|
s_suppkey; -- { serverError 47 }
|
||||||
|
drop table revenue0; -- TODO: drop view
|
||||||
|
|
||||||
select 16;
|
select 16;
|
||||||
select
|
select
|
||||||
p_brand,
|
p_brand,
|
||||||
@ -580,25 +581,25 @@ order by
|
|||||||
p_brand,
|
p_brand,
|
||||||
p_type,
|
p_type,
|
||||||
p_size;
|
p_size;
|
||||||
|
|
||||||
-- select 17;
|
select 17, 'fail: correlated subquery'; -- TODO: Missing columns: 'p_partkey'
|
||||||
-- select
|
select
|
||||||
-- sum(l_extendedprice) / 7.0 as avg_yearly
|
sum(l_extendedprice) / 7.0 as avg_yearly
|
||||||
-- from
|
from
|
||||||
-- lineitem,
|
lineitem,
|
||||||
-- part
|
part
|
||||||
-- where
|
where
|
||||||
-- p_partkey = l_partkey
|
p_partkey = l_partkey
|
||||||
-- and p_brand = 'Brand#23'
|
and p_brand = 'Brand#23'
|
||||||
-- and p_container = 'MED BOX'
|
and p_container = 'MED BOX'
|
||||||
-- and l_quantity < (
|
and l_quantity < (
|
||||||
-- select
|
select
|
||||||
-- 0.2 * avg(l_quantity)
|
0.2 * avg(l_quantity)
|
||||||
-- from
|
from
|
||||||
-- lineitem
|
lineitem
|
||||||
-- where
|
where
|
||||||
-- l_partkey = p_partkey
|
l_partkey = p_partkey
|
||||||
-- );
|
); -- { serverError 47 }
|
||||||
|
|
||||||
select 18;
|
select 18;
|
||||||
select
|
select
|
||||||
@ -672,46 +673,46 @@ where
|
|||||||
and l_shipinstruct = 'DELIVER IN PERSON'
|
and l_shipinstruct = 'DELIVER IN PERSON'
|
||||||
);
|
);
|
||||||
|
|
||||||
-- select 20;
|
select 20, 'fail: correlated subquery'; -- TODO: Missing columns: 'ps_suppkey' 'ps_partkey'
|
||||||
-- select
|
select
|
||||||
-- s_name,
|
s_name,
|
||||||
-- s_address
|
s_address
|
||||||
-- from
|
from
|
||||||
-- supplier,
|
supplier,
|
||||||
-- nation
|
nation
|
||||||
-- where
|
where
|
||||||
-- s_suppkey in (
|
s_suppkey in (
|
||||||
-- select
|
select
|
||||||
-- ps_suppkey
|
ps_suppkey
|
||||||
-- from
|
from
|
||||||
-- partsupp
|
partsupp
|
||||||
-- where
|
where
|
||||||
-- ps_partkey in (
|
ps_partkey in (
|
||||||
-- select
|
select
|
||||||
-- p_partkey
|
p_partkey
|
||||||
-- from
|
from
|
||||||
-- part
|
part
|
||||||
-- where
|
where
|
||||||
-- p_name like 'forest%'
|
p_name like 'forest%'
|
||||||
-- )
|
)
|
||||||
-- and ps_availqty > (
|
and ps_availqty > (
|
||||||
-- select
|
select
|
||||||
-- 0.5 * sum(l_quantity)
|
0.5 * sum(l_quantity)
|
||||||
-- from
|
from
|
||||||
-- lineitem
|
lineitem
|
||||||
-- where
|
where
|
||||||
-- l_partkey = ps_partkey
|
l_partkey = ps_partkey
|
||||||
-- and l_suppkey = ps_suppkey
|
and l_suppkey = ps_suppkey
|
||||||
-- and l_shipdate >= date '1994-01-01'
|
and l_shipdate >= date '1994-01-01'
|
||||||
-- and l_shipdate < date '1994-01-01' + interval '1' year
|
and l_shipdate < date '1994-01-01' + interval '1' year
|
||||||
-- )
|
)
|
||||||
-- )
|
)
|
||||||
-- and s_nationkey = n_nationkey
|
and s_nationkey = n_nationkey
|
||||||
-- and n_name = 'CANADA'
|
and n_name = 'CANADA'
|
||||||
-- order by
|
order by
|
||||||
-- s_name;
|
s_name; -- { serverError 47 }
|
||||||
|
|
||||||
-- select 21;
|
select 21, 'fail: exists, not exists'; -- TODO
|
||||||
-- select
|
-- select
|
||||||
-- s_name,
|
-- s_name,
|
||||||
-- count(*) as numwait
|
-- count(*) as numwait
|
||||||
@ -753,7 +754,7 @@ where
|
|||||||
-- s_name
|
-- s_name
|
||||||
-- limit 100;
|
-- limit 100;
|
||||||
|
|
||||||
-- select 22;
|
select 22, 'fail: not exists'; -- TODO
|
||||||
-- select
|
-- select
|
||||||
-- cntrycode,
|
-- cntrycode,
|
||||||
-- count(*) as numcust,
|
-- count(*) as numcust,
|
||||||
|
Loading…
Reference in New Issue
Block a user