230 likes | 244 Views
Understand domain independence, FO queries, relational algebra, and calculus in database theory. Learn to weed out meaningless queries and achieve relational completeness. Explore FO examples and domain-independent queries.
E N D
Datenbanktheorie VU FO Queries; domain independence, algebra vs. calculus
FO-Queries • Relational domain calculus (FO queries) = relational algebra. • Weed out meaningless queries in calculus – domain independence. • “Relationally complete” query languages (Codd). • Does not mean that all queries can be expressed.
Relational Algebra • SPC + set union + set difference • SQL: select – from – where – union – difference. • select Name from Empdifference select Name from Manager;
Relational (Domain) Calculus • First-order logic over the database relations • Same as SQL queryselect e.x from Emp ewhere e.y not in (select * from Manager);
Domain Independence • Exclude “unsafe” queries.
Domain Independence • We would like to be able to require domain independence in queries but… • Domain independence is an undecidable property for first-order queries. • Usual solution: syntactic restrictions. • E.g. the “range-restricted queries” • Sufficient condition for domain independence
Range-restricted queries • Safe-range normal form (SRNF) • Var. substitution: no distinct pair of quantifiers may bind same variable. • Remove universal quantifiers • Remove implications • Flatten and/or
Range restriction check • Input formula Q in SRNF • If all free variables of Q appear in rr(Q), then Q is range-restricted. • Fact: for every domain-independent FO query, there is an equivalent RR FO query.
From the Algebra to the Calculus • Almost by definition • Analogously for union and difference
From RR Queries to the Algebra • Start with SRNF • Put into Relational-Algebra NF (RANF):Each subexpression of the formula must be self-contained = locally range-restricted. • This means that a relational algebra formulacan be computed by induction from leaf of the parse tree of the formula to the root.