Slick 文档中的错误示例?
Wrong example in Slick docs?
要么我今天注意力不集中,要么 Slick 的入门文档设计不佳。
所以在 Queries/Unions 部分他们有这个片段:
val q1 = coffees.filter(_.price < 8.0)
val q2 = coffees.filter(_.price > 9.0)
val unionQuery = q1 union q2
// compiles to SQL (simplified):
// select x8."COF_NAME", x8."SUP_ID", x8."PRICE", x8."SALES", x8."TOTAL"
// from "COFFEES" x8
// where x8."PRICE" < 8.0
// union select x9."COF_NAME", x9."SUP_ID", x9."PRICE", x9."SALES", x9."TOTAL"
// from "COFFEES" x9
// where x9."PRICE" > 9.0
val unionAllQuery = q1 ++ q2
// compiles to SQL (simplified):
// select x8."COF_NAME", x8."SUP_ID", x8."PRICE", x8."SALES", x8."TOTAL"
// from "COFFEES" x8
// where x8."PRICE" < 8.0
// union all select x9."COF_NAME", x9."SUP_ID", x9."PRICE", x9."SALES", x9."TOTAL"
// from "COFFEES" x9
// where x9."PRICE" > 9.0
然后他们说:
Unlike union which filters out duplicate values, ++ simply concatenates the results of the individual queries, which is usually more efficient.
我认为 q1
和 q2
没有产生重复。所以这要么是他们提供的错误查询示例来说明 union
和 ++
之间的真正区别,要么我没有得到重要的东西。你们能帮忙吗?
在这种特定情况下,没有重复项,因为 q1
和 q2
之间没有交集。也许将查询更改为
val q1 = coffees.filter(_.price < 8.0)
val q2 = coffees.filter(_.price < 9.0)
会是一个更好的例子。总之,底线是这样的:
q1 union q2
转换为 SQL UNION
q1 ++ q2
转换为 SQL UNION ALL
要么我今天注意力不集中,要么 Slick 的入门文档设计不佳。 所以在 Queries/Unions 部分他们有这个片段:
val q1 = coffees.filter(_.price < 8.0)
val q2 = coffees.filter(_.price > 9.0)
val unionQuery = q1 union q2
// compiles to SQL (simplified):
// select x8."COF_NAME", x8."SUP_ID", x8."PRICE", x8."SALES", x8."TOTAL"
// from "COFFEES" x8
// where x8."PRICE" < 8.0
// union select x9."COF_NAME", x9."SUP_ID", x9."PRICE", x9."SALES", x9."TOTAL"
// from "COFFEES" x9
// where x9."PRICE" > 9.0
val unionAllQuery = q1 ++ q2
// compiles to SQL (simplified):
// select x8."COF_NAME", x8."SUP_ID", x8."PRICE", x8."SALES", x8."TOTAL"
// from "COFFEES" x8
// where x8."PRICE" < 8.0
// union all select x9."COF_NAME", x9."SUP_ID", x9."PRICE", x9."SALES", x9."TOTAL"
// from "COFFEES" x9
// where x9."PRICE" > 9.0
然后他们说:
Unlike union which filters out duplicate values, ++ simply concatenates the results of the individual queries, which is usually more efficient.
我认为 q1
和 q2
没有产生重复。所以这要么是他们提供的错误查询示例来说明 union
和 ++
之间的真正区别,要么我没有得到重要的东西。你们能帮忙吗?
在这种特定情况下,没有重复项,因为 q1
和 q2
之间没有交集。也许将查询更改为
val q1 = coffees.filter(_.price < 8.0)
val q2 = coffees.filter(_.price < 9.0)
会是一个更好的例子。总之,底线是这样的:
q1 union q2
转换为 SQLUNION
q1 ++ q2
转换为 SQLUNION ALL