Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Tuple relational calculus
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Semantic and syntactic restriction == === Domain-independent queries === Because the semantics of the quantifiers is such that they quantify over all the tuples over the domain in the schema it can be that a query may return a different result for a certain database if another schema is presumed. For example, consider the two schemas ''S<sub>1</sub>'' = ( ''D<sub>1</sub>'', ''R'', ''h'' ) and ''S<sub>2</sub>'' = ( ''D<sub>2</sub>'', ''R'', ''h'' ) with domains ''D<sub>1</sub>'' = { 1 }, ''D<sub>2</sub>'' = { 1, 2 }, relation names ''R'' = { "r<sub>1</sub>" } and headers ''h'' = { ("r<sub>1</sub>", {"a"}) }. Both schemas have a common instance: : ''db'' = { ( "r<sub>1</sub>", { ("a", 1) } ) } If we consider the following query expression : { ''t'' : {a} | ''t''.a = ''t''.a } then its result on ''db'' is either { (a : 1) } under ''S<sub>1</sub>'' or { (a : 1), (a : 2) } under ''S<sub>2</sub>''. It will also be clear that if we take the domain to be an infinite set, then the result of the query will also be infinite. To solve these problems we will restrict our attention to those queries that are ''domain independent'', i.e., the queries that return the same result for a database under all of its schemas. An interesting property of these queries is that if we assume that the tuple variables range over tuples over the so-called ''active domain'' of the database, which is the subset of the domain that occurs in at least one tuple in the database or in the query expression, then the semantics of the query expressions does not change. In fact, in many definitions of the tuple calculus this is how the semantics of the quantifiers is defined, which makes all queries by definition domain independent. === Safe queries === In order to limit the query expressions such that they express only domain-independent queries a syntactical notion of ''safe query'' is usually introduced. To determine whether a query expression is safe we will derive two types of information from a query. The first is whether a variable-column pair ''t''.''a'' is ''bound'' to the column of a relation or a constant, and the second is whether two variable-column pairs are directly or indirectly equated (denoted ''t''.''v'' == ''s''.''w''). For deriving boundedness we introduce the following reasoning rules: # in " ''v''.''a'' = ''w''.''b'' " no variable-column pair is bound, # in " ''v''.''a'' = ''k'' " the variable-column pair ''v''.''a'' is bound, # in " ''r''(''v'') " all pairs ''v''.''a'' are bound for ''a'' in ''type''(''v''), # in " ''f''<sub>1</sub> β§ ''f''<sub>2</sub> " all pairs are bound that are bound either in ''f''<sub>1</sub> or in ''f''<sub>2</sub>, # in " ''f''<sub>1</sub> β¨ ''f''<sub>2</sub> " all pairs are bound that are bound both in ''f''<sub>1</sub> and in ''f''<sub>2</sub>, # in " Β¬ ''f'' " no pairs are bound, # in " β ''v'' : ''H'' ( ''f'' ) " a pair ''w''.''a'' is bound if it is bound in ''f'' and ''w'' <> ''v'', and # in " β ''v'' : ''H'' ( ''f'' ) " a pair ''w''.''a'' is bound if it is bound in ''f'' and ''w'' <> ''v''. For deriving equatedness we introduce the following reasoning rules (next to the usual reasoning rules for equivalence relations: reflexivity, symmetry and transitivity): # in " ''v''.''a'' = ''w''.''b'' " it holds that ''v''.''a'' == ''w''.''b'', # in " ''v''.''a'' = ''k'' " no pairs are equated, # in " ''r''(''v'') " no pairs are equated, # in " ''f''<sub>1</sub> β§ ''f''<sub>2</sub> " it holds that ''v''.''a'' == ''w''.''b'' if it holds either in ''f''<sub>1</sub> or in ''f''<sub>2</sub>, # in " ''f''<sub>1</sub> β¨ ''f''<sub>2</sub> " it holds that ''v''.''a'' == ''w''.''b'' if it holds both in ''f''<sub>1</sub> and in ''f''<sub>2</sub>, # in " Β¬ ''f'' " no pairs are equated, # in " β ''v'' : ''H'' ( ''f'' ) " it holds that ''w''.''a'' == ''x''.''b'' if it holds in ''f'' and ''w''<>''v'' and ''x''<>''v'', and # in " β ''v'' : ''H'' ( ''f'' ) " it holds that ''w''.''a'' == ''x''.''b'' if it holds in ''f'' and ''w''<>''v'' and ''x''<>''v''. We then say that a query expression { v : H | f(v) } is ''safe'' if * for every column name ''a'' in ''H'' we can derive that ''v''.''a'' is equated with a bound pair in ''f'', * for every subexpression of ''f'' of the form " β ''w'' : ''G'' ( ''g'' ) " we can derive that for every column name ''a'' in ''G'' we can derive that ''w''.''a'' is equated with a bound pair in ''g'', and * for every subexpression of ''f'' of the form " β ''w'' : ''G'' ( ''g'' ) " we can derive that for every column name ''a'' in ''G'' we can derive that ''w''.''a'' is equated with a bound pair in ''g''. The restriction to safe query expressions does not limit the expressiveness since all domain-independent queries that could be expressed can also be expressed by a safe query expression. This can be proven by showing that for a schema ''S'' = (''D'', ''R'', ''h''), a given set ''K'' of constants in the query expression, a tuple variable ''v'' and a header ''H'' we can construct a safe formula for every pair ''v''.''a'' with ''a'' in ''H'' that states that its value is in the active domain. For example, assume that ''K''={1,2}, ''R''={"r"} and ''h'' = { ("r", {"a, "b"}) } then the corresponding safe formula for ''v''.b is: : ''v''.b = 1 β¨ ''v''.b = 2 β¨ β ''w'' ( r(w) β§ ( ''v''.b = ''w''.a β¨ ''v''.b = ''w''.b ) ) This formula, then, can be used to rewrite any unsafe query expression to an equivalent safe query expression by adding such a formula for every variable ''v'' and column name ''a'' in its type where it is used in the expression. Effectively this means that we let all variables range over the active domain, which, as was already explained, does not change the semantics if the expressed query is domain independent.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)