0
$\begingroup$

Let's for the sake of simplicity only focus on tuple relational calculus.

Every relational algebra query can be broken down into the 5 atomic operations - projection, selection, set union, set difference, cartesian product (I'm excluding renaming as it is not possible to do in relational calculus).

Let $P(x)$ be an arbitrary predicate and $r$, $s$ relations with attributes $a_1,\dots,a_n$ and $b_1,\dots,b_n$ respectively.

For the 5 atomic operations, we have a conversion: $\newcommand{\Set}[2]{% \{\, #1 \mid #2 \, \}% }$ \begin{align} \Pi_{a_{1},\dots,a_{n}}(r) &\iff \Set{t}{\exists p \in r \left(\bigwedge\limits_{i=1}^n t.a_i = p.a_i \right)}, \\ \sigma_{P(x)}(r) &\iff \Set{t}{t \in r \land P(x)},\\ r \cup s &\iff \Set{t}{t \in r \lor t \in s}, \\ r \setminus s &\iff \Set{t}{t \in r \land t \notin s}, \\ r \times s &\iff \Set{t}{\exists p \in r \; \exists q \in s \left( \bigwedge\limits_{i=1}^n t.a_i = p.a_i \land \bigwedge\limits_{i=1}^n t.b_i = p.b_i \right)}. \end{align}

But we only used $r$ and $s$ which are relations. What if we have an expression in a form of $Q_{1} \bigoplus Q_{2}$ where $Q_1$, $Q_2$ are also queries?

Is it possible to write a general formula for the 5 main operations while only using the most general $Q_1$, $Q_2$?

$\endgroup$
6
  • $\begingroup$ You need to clearly distinguish between relation values vs relation programming/DB variable names vs logic variables vs query expressions, for both algebra & calculus. That includes dealing properly with what attributes a relation/tuple value or programming or logic variable involving some has. Also &\iff is not appropriate, figure out what exact statement you want to make about what things. This applies to both whatever you think you've said formally now & your final mapping. PS Please put your question in your post body, not just the title. PS Mapping calculus to algebra [sic] is harder. $\endgroup$
    – philipxy
    Commented Jul 11, 2021 at 12:20
  • $\begingroup$ There are many versions of relational algebra & tuple (& domain) relational calculi. They differ in operators & even what a relation is. Give definitions & a reference (textbook name, edition & page) for yours. (It wouldn't matter so much if you were defining some calculus queries in terms of algebra queries but here we don't know whether you are using a given calculus correctly.) $\endgroup$
    – philipxy
    Commented Jul 11, 2021 at 12:21
  • $\begingroup$ Different versions? Where did you see that? I clearly stated the 5 atomic operations and their counterparts. Is the definiton of a relation relevant? I'm not really sure how to respond to that. I'm just trying to find out how to connect the two languages when there are nested queries in the epxressions. If you have some references to different version of relational algebra and relational calculus, please show me so I can restate my question more clearly. I haven't been able to find any. $\endgroup$ Commented Jul 11, 2021 at 15:08
  • $\begingroup$ Just about any collection of presentations of algebras or of calculi will differ. Dozens of textbooks are free online in pdf & html. (But typically presentations are poor.) But what is stopping you from quoting/summarizing the reference you are using? If you can't give your definitions, how do you expect to map between expressions?--Rhetorical. Re mapping: Map an algebra query that is just a DB variable name, then map expressions referencing just 1 operator. But as I said you need to be clearer re what you are dealing with. (Eg it's not even clear what you think the line re union is saying.) $\endgroup$
    – philipxy
    Commented Jul 11, 2021 at 15:32
  • $\begingroup$ Ok. I can't send you my sources since you don't understand Czech. I looked into wikipedia en.wikipedia.org/wiki/Relational_algebra and en.wikipedia.org/wiki/Tuple_relational_calculus and they're using identical definitions and operators as we do. Or I can come later and construct a full grammar if that's what is needed. I really can't find any good source for the definition as it is ambiguous everywhere. $\endgroup$ Commented Jul 11, 2021 at 15:45

0

Your Answer

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