Relational calculus

For the theoretical analysis and semantically precise definition of query languages ​​for databases calculus expressions are used, specifically the Tupelkalkül ( engl. tuple calculus ), and the region calculus (also domain calculus, English. Calculus domain ). Because of their similarity, they are considered together. However, there are still more calculus -like query languages ​​.

The starting point is the fact that data are stored in a database in a number of tuples ( ratios ) of the same type, i.e., the components of the tuple in the set of tuples of all have the same data type, and thus the same operations apply to it. Since the calculi "only" constitute a theoretical foundation, data types are here but not further considered, but assumed that the usual operations apply.

Questions which can be specified with the calculi are then constructed as sets. This construction follows a certain form: When Tupelkalkül quantities of tuples are constructed, the area calculus quantities from the so-called " areas " that are free variables, in essence, can take the values ​​from the range of Tupelkomponenten. Generally, however, can be defined, where the data come from, how they are linked to and what additional conditions should apply.

Calculi provide a very powerful query language, which is not desired in the area of ​​databases. For example it is no problem using calculus expressions to specify an infinite result set, which violates a design principle of query languages ​​. Therefore is of interest to the general database theory the definition of safe calculus expressions that correspond to the thickness of the relational algebra. Calculus expressions are still strictly relationally complete.

For SQL there is a formal definition by the Tupelkalküls. QBE is based on the region calculus, QUEL is a relatively direct translation of parts of the Tupelkalküls.

General form

In mathematics, one can construct a set by specifying what is to count for each item. The simple form of this is { x | formula }, ​​that is, I choose all x for which the formula applies, eg, to preserve the natural numbers between 2 and 8. Specified here, firstly where the data comes ( natural numbers ), and secondly, what is to count for they (the formula ). x is a free variable whose value range was determined by the formula. Instead of a simple formula, a free variables can be specified, as a result, eg x ², to obtain the squares of the numbers 2-8. The general form of construction is that quantity { f (X) | G (y) }, where f and g are the respective formulas, and X and Y are sets of the free variables.

The ranges of values ​​are for the database range is now not set arbitrarily, but they come from the mentioned Tupelmengen (typically relations, but also quite entities or sets of objects ). The results can be expressed either as variables or quantities as tuples, that is, we construct the set as " all free variables is true for the ... " or " all tuples that applies to the ... ". The former leads to the region calculus; the latter more for Tupelkalkül.

Calculus formulas

The set of possible formulas is also limited to a specific shape that is very similar for the two calculations. Here are terms to atomic formulas, and these in turn assembled into formulas. Ranges of values ​​of free variables are given by database predicates, thereby determining where the data come (range calculus: CUSTOMER (x, y, z), Tupelkalkül: CUSTOMER (k)).

  • Terms: variables, constants, function applications
  • Atomic formulas: Application of operations of the data types, such as <, > to the value range of the natural numbers and database predicates
  • Formulas: Linking atomic formulas using operators of Boolean logic, ∧, ∨, ¬, ∀, ∃

The calculi are extended so that it is comparatively simple with them to formalize database languages ​​such as SQL. To do this, instead of a lot of semantics leads a multi-set semantics and the additional option of formulas - in particular the aggregate functions - to use the results pane. Furthermore, it is conceivable to allow for database queries predicates in turn, so that the calculations are completed.

Region calculus

The mold is { x1, ..., xn | φ (x1, ..., xn ) }, where xi are the result Tupelmengen and φ is a formula. These formulas are established as stated above. In database predicates, not all variables are assigned, instead, can also be '_' written, what is that they are each different, unnamed free variables.

Examples

Places where there are customers: { x | CUSTOMER (_, _, _, x) }

All customers from Bremen: { x, y, z | CUSTOMER (x, y, z, w) ∧ w = 'Bremen' } or { short x, y, z | CUSTOMER (x, y, z, 'Bremen' ) }

Customers with order: { x, y, z | CUSTOMER (x, y, z, _) ∧ CONTRACT (_, x, _, _) }

Goods without ordering: { x, y | PRODUCT ( x, y, _) ∧ ¬ CONTRACT (_, _, x, _) }

Tupelkalkül

The form is { t | φ (t)}. t is a Tupelvariable, φ a formula as above. Database predicates as R ( t) or t ∈ R written on individual elements of the tuple (attributes ) are accessed by a dot notation to stating the name of the schema, ie, tA, or by using the index t [ i].

Examples

With the O.A. scheme,

Places where there are customers: { t.ort | CUSTOMER (t)}

All customers from Bremen: { t | CUSTOMER (t ) ∧ t.ort = 'Bremen '}

Customers with order: { t | CUSTOMER (t ) ∧ ∃ s ( CONTRACT ( s ) ∧ s.kdnr = t.kdnr ) }

Goods without ordering: { t | PRODUCT ( t) ∧ ¬ ∃ s ( CONTRACT ( s ) ∧ s.warennr = t.warennr ) }

As you can see, the bond conditions to be specified explicitly in the Tupelkalkül, while a composite is formed in the region calculus by gleichbenannte variables.

116775
de