选择和投影是关联的吗?

发布于 2024-12-09 00:05:56 字数 37 浏览 0 评论 0原文

选择(p)(投影(R))==投影(选择(p)(R))总是吗?

Is selection(p)(projection(R)) == projection(selection(p)(R)) always?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

許願樹丅啲祈禱 2024-12-16 00:05:56

如果认为选择是在投影中使用的列的子集上,那么是,

但如果不是,则可能会出现您在不存在的列上进行选择的情况。

If think if the selection is on subset of columns that are used in projections then YES,

but if not, there can be a situation where you are making a selection on columns that not exists.

顾铮苏瑾 2024-12-16 00:05:56

首先,“交换性”的属性根本不适用于您的情况。

交换性是对于所有 x,y 的属性:x op y == y op x。

例如,对于所有 R1,R2 : R1 NATURAL JOIN R2 == R2 NATURAL JOIN R1。

其次,答案是否定的。

仅当投影保留限制条件中涉及的所有属性时,才可以在限制内移动投影。否则,整个表达式就会变得无效。

编辑

(稍稍延伸一下,您可能会说涉及交换性,因为您的示例案例是关于函数组合是否可交换的问题(f°g ?= g°f)。了解您的数学应该使您的问题成为修辞性的但是,在这种情况下是一个。)

编辑 2

将问题改为它们是否具有关联性也不好。结合性是一种只有一个运算符和三个参数的情况,其中问题是对于所有 a、b、c 是否 (a op b) op c ?= a op (b op c)。您有两个运算符(投影和选择)和一个​​参数。

这也意味着分布性问题(严格的数学意义上)也不适用,尽管您的场景在某些方面确实类似于运算符分布性的数学情况,并且有足够的延伸。严格数学意义上的分配性涉及两个二元运算符(即采用两个参数)。投影和限制是一元的。

我认为 csviri 已经正确回答了你的问题。你应该接受它。

First, the property of 'commutativity' simply doesn't apply to your case.

Commutativity is the property that for all x,y : x op y == y op x.

For example, for all R1,R2 : R1 NATURAL JOIN R2 == R2 NATURAL JOIN R1.

Second, the answer is no.

A projection can only be moved inside a restrict if the projection retains all the attributes that are involved in the restriction condition. Otherwise, the overall expression simply becomes invalid.

EDIT

(With a bit of a stretch, you could argue that commutativity is involved because your example case is about the question of whether FUNCTION COMPOSITION is commutative (f°g ?= g°f). Knowing your maths should make your question a rhetorical one, in that case, however.)

EDIT 2

And changing the question to whether they are associative is no good either. Associativity is a case with one single operator and three arguments, where the question is whether (a op b) op c ?= a op (b op c), for all a,b,c. You have two operators (projection and selection) and one single argument.

That also means that the question of DISTRIBUTIVITY (in its strict mathematical sense) does not apply either, although your scenario does resemble the mathematical case of operator distributivity, in certain respects, and given enough stretch. Distributivity in its strict mathematical sense involves two dyadic operators (i.e. taking two arguments). Projection and restriction are unary.

I think csviri has answered your question proper. You should accept it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文