在没有聚合的情况下使用 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) │
├───────────┼────────────┼───────────────┤
│ 1 │ 9154 │ 357345.46 │
│ 1 │ 14656 │ 28599.83 │
│ 1 │ 24322 │ 231040.44 │
│ 1 │ 31653 │ 152411.41 │
│ 1 │ 34019 │ 89230.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。这在传统关系型数据库中是合理的。但是,作为模型中的一个列,它不应该影响模型的行数。