关系代数叉积和自然连接

Relational Algebra Cross Product and Natural Join

我对何时使用这两个运算符有点困惑。我觉得我理解它们,但我很难弄清楚什么时候在关系代数语句中需要它们。有人可以给我一些 insight/advice 吗?

某些版本的关系代数具有关系标题,这些关系标题是(无序、唯一命名的)属性集。 Then (relational (Cartesian)) PRODUCT, aka CROSS JOIN, aka CROSS PRODUCT, 仅在输入关系不共享属性名称时才定义,但在其他方面类似于 NATURAL JOIN。所以它的作用是确认你期望没有共享属性名。

(某些版本的关系代数具有非集合的关系标题;属性可以排序 and/or 多个属性可以具有相同的名称。通常 PRODUCT 为每个输入属性输出一个属性。如果有NATURAL JOIN 然后它的结果就像首先做 PRODUCT,然后限制 same-named 属性对的相等性,然后投影出每对的一个属性。所以 PRODUCT 适用于任何两个输入,而 NATURAL JOIN 可能在以下情况下未定义一个输入具有重复的属性名称,但当没有共享属性名称时它们将给出相同的结果。)

至于why you would compose any particular relational algebra query:

Every table/relation has a statement parameterized by columns/attributes. (Its "characteristic predicate".) The rows/tuples that make the statement true go in the table/relation. First find the statements for the given tables/relations:

// customer [Cust-Name] has £[Balance] in account [Acc-No] at branch [Branch]
Deposit (Branch, Acc-No, Cust-Name, Balance)
// customer [Cust-Name] loan [Loan-No] balance is £[Balance] at branch [Branch]
Loan(Branch, Loan-No, Cust-Name, Balance)

Now put these given statements together to get a statement that only the rows we want satisfy. Use AND, OR, AND NOT, AND condition. Keep or drop names. Use a new name if you need one.

    customer [Cust-Name] loan [Loan-No] balance is £[Loan-Balance] at branch [Branch]
AND customer [Cust-Name] has £[Balance] in account [Acc-No] at branch [Branch]

Now to get the algebra replace:

  • every statement by its table/relation
  • every AND of table/relation statements by ⋈ (natural join)
  • every OR of table/relation statements (which must have the same columns/attributes) by ∪ (union)
  • every AND NOT of statements (which must have the same columns/attributes) by \ (difference)
  • every AND condition by σ condition
  • every Keeping names to keep by π names to keep (projection) (and Dropping by π names to keep)
  • every column/attribute renaming in a given statement by ρ (rename).

∩ (intersection) and x (product) are special cases of ⋈ (∩ for both sides the same columns/attributes and x for no shared columns/attributes).

(ρ Loan-Balance/Balance Loan) ⋈ Deposit