简体   繁体   English

为什么在关系代数中将并,交和差运算称为布尔运算?

[英]Why are union, intersection and difference operations called boolean operations in relational algebra?

Why are union, intersection and difference operations of relational algebra called boolean operations? 为什么关系代数的并,交和差运算称为布尔运算?

I found them called that in the first line in section 5.4.1 Boolean operations (Section 5.4 is Relational Algebra and Datalog) in a book named A First Course in DATABASE SYSTEMS by Ullman & Widom. 我在Ullman&Widom撰写的名为DATABASE SYSTEMS中的A First Course的书中,在5.4.1节的布尔运算(第5.4节是关系代数和数据记录)的第一行中发现了它们的名称。

The statement that you are citing is from the Chapter 5 (Algebraic and Logical Query Languages) of the book “First Course in Database Systems” by Ullman and Widom (Pearson 2013). 您引用的陈述来自于Ullman和Widom(Pearson 2013)的“数据库系统第一课程”一书的第5章(代数和逻辑查询语言)。

In particular, the sections 5.3 and 5.4 of that Chapter treat the language Datalog, which can be used to work on a Relational Data Base, in which a Relation is seen as predicate , not a set (see Section 5.3.1). 特别是,该章的第5.3和5.4节处理了Datalog语言,该语言可用于在关系数据库上工作,在该数据库中,关系被视为谓词而不是集合(请参见第5.3.1节)。

In other words, a tuple (x1, x2, ..., xn) of R is seen as the fact that the relation R is true for the arguments specified (x1, x2, ..., xn). 换句话说,R的元组(x1,x2,...,xn)被视为这样的事实,即关系R对于指定的参数(x1,x2,...,xn)为真。 In this way one could transform the set operators discussed in the context of Relation Algebra (union, difference, intersection) as rules of Datalog expressed through the use of boolean operators, like AND, NOT, etc. 通过这种方式,可以将在关系代数(联合,差分,交集)的上下文中讨论的集合运算符转换为通过使用布尔运算符(如AND,NOT等)表示的Datalog规则。

In fact, you can see that in the same book, in section 2.4.4, they are called Set Operators (as they actually are), so I think the naming of “boolean operators” is due to the fact that they are strictly related to boolean operators and are discussed in the context of a logical view of a database. 实际上,您可以在同一本书的第2.4.4节中看到它们被称为集合运算符(实际上是它们),因此我认为“布尔运算符”的命名是由于它们严格相关布尔运算符,并在数据库逻辑视图的上下文中进行讨论。

The notion of "boolean" relational operations is an idiosyncratic ad hoc distinction/categorization in that book and chapter. “布尔”关系运算的概念是该书和该章中的一种特殊的临时区分/分类。 The authors identify 3 common relation operators that "can each be expressed simply in Datalog". 作者确定了3个“可以在Datalog中简单表示”的公共关系运算符。 The next sections at the same level go on to each express some other relational operator. 同一级别的下一部分继续说明其他一些关系运算符。 ("Selections can be somewhat more difficult to express in Datalog.") The 3 operators' treatments are similar to each other and different from others' in a certain context-specific "boolean" way. (“选择可能很难在Datalog中表达。”)3个运算符的处理方式彼此相似,并且在特定于上下文的“布尔”方式下与其他操作符不同。 (So it's not a particularly helpful or deep distinction.) (因此,这不是特别有用或有深度的区别。)

5.4.1 Boolean Operations 5.4.1布尔运算

The boolean operations of relational algebra--union, intersection, and set difference--can each be expressed simply in Datalog. 关系代数的布尔运算(联合,交集和集差)可以简单地在Datalog中表示。

  • To take the union R ∪ S, [...] As a result, each tuple from R and each tuple of S is put into the answer relation. 为了使并集R∪S,结果,R中的每个元组和S的每个元组都放入了答案关系。
  • To take the intersection R ∩ S, [...] Then, a tuple is in the answer relation if and only if it is in both R and S. 为了求交R∩S,...,则当且仅当在R和S中都存在一个元组时,它才处于答案关系中。
  • To take the difference R - S, [...] Then, a tuple is in the answer relation if and only if it is in R but not in S. 为了求差R-S,那么,当且仅当元组在R中但不在S中时,元组才处于答案关系中。

So the "boolean" is because each relation operator corresponds to a certain boolean operator in that context: 因此,“布尔值”是因为每个关系运算符都对应于该上下文中的某个布尔运算符:

UNION returns tuples that are in one operand OR the other UNION返回一个操作数或另一个操作数中的元组
INTERSECTION returns tuples that are in one operand AND the other INTERSECTION返回一个操作数和另一个操作数中的元组
DIFFERENCE returns tuples that are in one operand AND NOT the other 差异返回一个操作数中的元组,而不返回另一个

(Datalog also literally uses AND and AND NOT, but OR is implicit.) (数据日志实际上也使用AND和AND NOT,但OR是隐式的。)

More importantly, this can be put another way: If every base relation holds the tuples that make a true proposition (statement) from some associated predicate (sentence template parameterized by attribute names) then every result has a predicate made from its operand predicates, and its value holds the tuples that make a true proposition from that predicate: 更重要的是,这可以用另一种方式表示:如果每个基本关系都包含从某个关联谓词 (由属性名称参数化的句子模板)构成真实命题 (陈述)的元组,则每个结果都有一个由其操作数谓词构成的谓词,并且它的值包含从该谓词提出真实命题的元组:

U holds tuples where U U持有的元组,其中U
V holds the tuples where V V持有元组,其中V
U UNION V holds the tuples where U OR V U UNION V包含UV的元组
U INTERSECTION V holds the tuples where U AND V U INTERSECTION V包含元组,其中UV
U DIFFERENCE V holds the tuples where U AND NOT V U DIFFERENCE V包含元组,其中U和NOT V

But more than that it's not just that those operators correspond to some boolean propositional logic connectives/nonterminals, but that every relational operator corresponds to a predicate logic connective/nonterminal, every query expression has an associated predicate, and every query result value holds the tuples that make a true proposition from that predicate: 但是,不仅是这些运算符对应于一些布尔命题逻辑连接词/非终端,而且每个关系运算符都对应于谓词逻辑连接词/非终端, 每个查询表达式都有一个关联的谓词, 每个查询结果值都包含元组。从该谓词中得出一个真正的命题:

U JOIN V holds the tuples where U AND V U JOIN V包含UV的元组
R RESTRICT condition holds the tuples where U AND condition R RESTRICT condition包含U AND 条件的元组
U PROJECT A holds the tuples where FORSOME values for all attributes but A, U U PROJECT A包含元组,其中除A, U之外的所有属性的FORSOME值
U RENAME A A' holds the tuples where U with A replaced by A' U RENAME A A'持有元组,其中U替换为A'的U

So the book ties those three operators to the syntax & semantics of Datalog, but really all operators can be tied to the syntax & semantics of predicate logic . 因此,本书将这三个运算符与Datalog的语法和语义联系在一起,但实际上所有运算符都可以与谓词逻辑的语法和语义联系在一起。 Which is the language/notation of precision in mathematics, science (including computer science) & engineering (including software engineering.) In fact, that's how we know what a query means . 数学,科学(包括计算机科学)和工程(包括软件工程)中的精确度的语言/符号。实际上, 这就是我们知道查询含义的方式 So it's not really that those three operators are in some sense boolean so much as that all relational operators are logical : every relation expression corresponds to a predicate logic expression. 因此,从某种意义上说,这三个运算符并不是布尔值那么大,而是所有关系运算符都是逻辑的 :每个关系表达式都对应一个谓词逻辑表达式。

(The three operators are also frequently called the "set operators", since the set that is the body of the result relation arises from the sets that are the bodies of the operand relations according to the set operators by the same names. And that might be a helpful way to group them in your mind or remember them or their names, and no doubt inspired their names. But in light of the correspondence between relation operators and predicate logic connectives/nonterminals and the correspondence between relation expressions and predicate logic expressions and the correspondence between predicates and relation values, the fact that some relation operators are reminiscent of some set operators is totally irrelevant .) (Just like that some operators are reminiscent of boolean operators. Just like that you can make an algebra with "relations" whose bodies are bags instead of sets.) (这三个运算符也经常称为“集合运算符”,因为作为结果关系的主体的集合是根据集合运算符的相同名称来自于作为操作数关系的主体的集合。这可能是将它们归类或记住它们或它们的名称的有用方法,无疑会激发它们的名称,但鉴于关系运算符与谓词逻辑连接词/非终结符之间的对应关系以及关系表达式与谓词逻辑表达式之间的对应关系以及谓词与关系值之间的对应关系,某些关系运算符让人联想到某些集合运算符的事实是完全不相关的 。)(就像某些运算符让人联想到布尔运算符一样。就像您可以用“关系”来代数一样尸体是袋子而不是套装。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM