-1
$\begingroup$

Let's have a relation $R = (name, surname, age)$. I want to obtain a new relation with only the $name$ attribute. In relational algebra I would simply do $\Pi_{\mathrm{name}}(R)$ but in relational calculus the general way of doing that is $$ \newcommand{\Set}[2]{% \{\, #1 \mid #2 \, \}% } \Set{t}{\exists z \; (R(z) \land t.\mathrm{name} = z.\mathrm{name}}. $$

How does it work? I thought that relation is basically a table and tuple is a row from that table. How does this expression retrieve the original relation with only the name as an attribute?

If I don't specify where the tuple variable $t$ belongs to, we're ranging over all tuples $t$ from the schema right?

  1. How can a tuple be just a slice of a table?

  2. Take a tuple from $R$ that contains $name$, $surname$ and $age$. It also follows the rule that $t.\mathrm{name} = z.\mathrm{name}$ doesn't it? How come it doesn't show up in the result? I'm so confused.

$\endgroup$
2
  • $\begingroup$ "If I don't specify where the tuple variable t belongs to, we're ranging over all tuples t from the schema right?" No, t ranges over all tuples of some type/set that must be made clear but isn't in your post. A comprehension variable range is typically a Cartesian product (alll tuples with given attributes of given types) or union of Cartesian products (all such tuples over all arities). A quantified variable range could be too, or be a base relation value. Eg ∃x∈R[...] & your ∃x[x∈R ∧ ...] have xs with different ranges. But your 2 questions & the reasoning behind them are unclear. $\endgroup$
    – philipxy
    Commented Jan 5, 2022 at 20:17
  • $\begingroup$ Please ask 1 question. PS The definition of the notation in the presentation you are reading probably clearly defines what the meaning of the notation is in detail, but you don't give it. PS {x|p} is the set of values for x of given type that make p true. This is "set comprehension" with "(characteristic) predicate" p. So proposition s={x|p} re set s means ∀x[x∈s iff p]. Shorthand {...x...|p} means {y|∃...x... [y=<...x...> & p]}. TRCs define shorthands like {x.a,...|p} for {<a x.a,...>|p} ie {y|∃...x...[y=<a x.a,...> & p]}. Sometimes the LHS variables are implicitly the RHS free variables. $\endgroup$
    – philipxy
    Commented Jan 5, 2022 at 20:48

2 Answers 2

0
$\begingroup$

Note: in the following I assume that a tuple has a fixed set of values, and its order is significant: in other words, if R(a, b) has a tuple t1 = (2, 4), then t1.a = 2 and t1.b = 4.

The basic idea behind the tuple relational calculus is that each relation represents a certain predicate, and a relation extension (the tuples) represents a model (i.e. a set of objects) that makes true such predicate. So for instance if R in your example has only three tuples,

("John", "Rean", 19)
("Mary", "Rean", 24)
("Mary", "June", 18)

this means that it is true that John Rean, Mary Rean, and Mary June satisfy the predicate R, and only them.

A query is expressed as a (well-formed) first order formula, and its “result” is obtained by finding in the model the objects that, substituted to the free variables of the formula, make it true.

So the query:

{t | P(t) }

means: the set of tuples t that satisfy the predicate P (remember that we want always, as result, a set of tuples, that is a relation).

So, in your example, the formula:

{𝑡 ∣ ∃𝑧(𝑅(𝑧) ∧ 𝑡.name = 𝑧.name}

means: “all the tuples t for which exists at least a tuple true for R with the same name of t”; in other words, all the tuples that have a name among the names of the tuples model of R. So, note that if we have more than one tuple with the same name, in the result we will have only a tuple with such name.

Remember that we are looking for all the possible tuples that can be retrieved by the model that makes the predicate true: this means that we are looking for all the tuples such that:

∃𝑧(𝑅(𝑧) ∧ 𝑡.name = 𝑧.name)

is true. And so there are two and only two tuples that satisfy this predicate:

("John")
("Mary")

so this is the result of our query (note that we assume that a tuple returned has only the "fields" mentioned in its predicate, so t has only the “field” name).

$\endgroup$
5
  • 1
    $\begingroup$ note that we assume that a tuple returned has only the "fields" mentioned in its predicate is the problem - is this true by definition? If we do not specify to which relation a tuple $t$ belongs we only retrieve tuples $t$ with the fields mentioned iby $t.field$, right? My point was that ("Mary"), ("Mary", "Rean"), ("Mary", "Rean", 24), ("Mary", "June"), ("Mary", "June", 18), ("Mary", 18), ("Mary", 24), ("John", "Rean", 19), ("John", "Rean"), ("John"), ("John", 19) are all the tuples that seem to satisfy the given predicate and they could form a relation containing any combination of columns $\endgroup$ Commented Sep 28, 2021 at 16:14
  • $\begingroup$ t does not belong to any relation. It is a set of tuples such that the following defining predicate is true. So, if the predicate mentions only certain fields, then the tuples t have only those field. I have seen also notations in which the type of t is specified (something like t:<name:string> | ..., but this is not a common notation. So, we could say that this fact (the tuples has only the component specified in the predicate) is implicitly true by definition. $\endgroup$
    – Renzo
    Commented Sep 28, 2021 at 16:19
  • $\begingroup$ See for instance in wikipedia the two examples, t:{field-name}. $\endgroup$
    – Renzo
    Commented Sep 28, 2021 at 16:24
  • $\begingroup$ As a nitpick, the order of fields is not significant in relational algebra (because disregard of order allows the relational operators to acquire certain mathematical properties), and rows or records in this context are therefore explicitly not tuples. $\endgroup$
    – Steve
    Commented Feb 26, 2022 at 10:47
  • $\begingroup$ "If we do not specify to which relation a tuple t belongs we only retrieve tuples t with the fields mentioned" That is your personal notational convention that you don't make clear in the post. The question isn't clear about it either, and the asker seems to have quoted from a context where either the formula is wrongly not typing t or such a convention is used but not made clear or it is used & clear but the asker missed it.. $\endgroup$
    – philipxy
    Commented Nov 11, 2023 at 0:26
-1
$\begingroup$

Equation for projection:

${ t ∣ ∃z ( R(z) ∧ t.name = z.name }$

Now, here we don't specify anywhere that $R(t)$ or $t \ belongs \ to \ relation \ R$. So, $t$ is basically just empty tuple with no specified attributes. The only thing we specified here is that $R(z)$ which makes $z$ a tuple with all other attributes.

And other way around we say that $z.name = t.name$, which makes $t$ a new tuple with only $name$ attribute. And that $name$ only is the output with $t$.

In simple words, $z$ has all attributes, but we gave $t$ only $name$ attribute ($t$ was basically empty before). And that's what we want to project here.

$\endgroup$
1
  • $\begingroup$ That "equation" is not an equation or query & it is also not a relational algebra definition of projection & the expression in the question post that contains your expression is not a legal calculus query or algebra expression. This post is not clear, especially in your uses of "empty" or "new" or "other way around". In a calculus query & algebra operator definition every tuple & table has a clearly given set of attributes. Read my comments on the question post. PS A "basically" or "in simple words" that isn't accompanied by a clear full explanation just means "unclearly". You do not give one. $\endgroup$
    – philipxy
    Commented Nov 10, 2023 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.