跳到主要内容

在没有聚合的情况下使用 TO_MANY

让我们看看传统关系型数据库(RDBMS)中的一个例子,了解如果在没有聚合的情况下使用 TO_MANY 会发生什么。

D select c_custkey, o_orderkey, o_totalprice 
from tpch.customer join tpch.orders
on customer.c_custkey = orders.o_custkey
order by 1,2
limit 5;
┌───────────┬────────────┬───────────────┐
│ c_custkey │ o_orderkey │ o_totalprice │
│ int32 │ int32 │ decimal(15,2)
├───────────┼────────────┼───────────────┤
19154357345.46
11465628599.83
124322231040.44
131653152411.41
13401989230.03
└───────────┴────────────┴───────────────┘

D select count(*) from tpch.customer;
┌──────────────┐
│ count_star()
│ int64 │
├──────────────┤
1500
└──────────────┘

D select count(*) from tpch.customer
join tpch.orders on customer.c_custkey = orders.o_custkey;
┌──────────────┐
│ count_star()
│ int64 │
├──────────────┤
15000
└──────────────┘

很容易注意到,TO_MANY 关系会增加行数。例如,Customer 的行数为 1500。然而,如果我们将其与 Orders 连接,行数将增加到 15000。这在传统关系型数据库中是合理的。但是,作为模型中的一个列,它不应该影响模型的行数。