Datalog - Database Systems - Lecture Slides, Slides of Database Management Systems (DBMS)

Some concepts of Database Systems are Algebra, Call-Level Interface, Concurrency, Concurrency Control, Constraints, Controlling Concurrent Behavior.Main points of this lecture are: Datalog , Important Example, Logical Rules, Nonrecursive, Relational Algebra, Extend Relational, Relational Algebra, Appear, Recursive Rules, Relational Algebra

Typology: Slides

2012/2013

Uploaded on 04/26/2013

parina
parina 🇮🇳

4.4

(67)

222 documents

1 / 51

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Datalog
Logical Rules
Recursion
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Partial preview of the text

Download Datalog - Database Systems - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Datalog

Logical Rules

Recursion

Logic As a Query Language

  • If-then logical rules have been used in many systems. - Important example: EII (Enterprise Information Integration).
  • Nonrecursive rules are equivalent to the core relational algebra.
  • Recursive rules extend relational algebra and appear in SQL-99.

EII – (2)

  • Approach 2: Describe how JoeMenu can be used as a view to help answer queries about Sells and other relations.

JoeMenu(b, p) <- Sells(’Joe’’s Bar’, b, p)

  • More about information integration later.

A Logical Rule

  • Our first example of a rule uses the relations Frequents(drinker, bar), Likes(drinker, beer), and Sells(bar, beer, price).
  • The rule is a query asking for “happy” drinkers --- those that frequent a bar that serves a beer that they like.

Subgoals Are Atoms

  • An atom is a predicate , or relation name with variables or constants as arguments.
  • The head is an atom; the body is the AND of one or more atoms.
  • Convention: Predicates begin with a capital, variables begin with lower-case.

Example: Atom

Sells(bar, beer, p)

8

The predicate = name of a relation

Arguments are variables (or constants).

Example: Interpretation

Happy(d) <- Frequents(d,bar) AND

Likes(d,beer) AND Sells(bar,beer,p)

10

Distinguished variable

Nondistinguished variables

Interpretation: drinker d is happy if there exist a bar, a beer, and a price p such that d frequents the bar, likes the beer, and the bar sells the beer at price p.

Applying a Rule

  • Approach 1: consider all combinations of values of the variables.
  • If all subgoals are true, then evaluate the head.
  • The resulting head is a tuple in the result.

A Glitch (Fixed Later)

  • Relations are finite sets.
  • We want rule evaluations to be finite and lead to finite results.
  • “Unsafe” rules like P(x)<-Q(y) have infinite results, even if Q is finite.
  • Even P(x)<-Q(x) requires examining an infinity of x -values.

Applying a Rule – (2)

  • Approach 2: For each subgoal, consider all tuples that make the subgoal true.
  • If a selection of tuples define a single value for each variable, then add the head to the result.
  • Leads to finite search for P(x)<-Q(x), but P(x)<- Q(y) is problematic.

Arithmetic Subgoals

  • In addition to relations as predicates, a predicate for a subgoal of the body can be an arithmetic comparison.
  • We write arithmetic subgoals in the usual way, e.g., x < y.

Example: Arithmetic

  • A beer is “cheap” if there are at least two bars that sell it for under $2.

Cheap(beer) <- Sells(bar1,beer,p1) AND

Sells(bar2,beer,p2) AND p1 < 2. AND p2 < 2.00 AND bar1 <> bar

Safe Rules

  • A rule is safe if:
    1. Each distinguished variable,
    2. Each variable in an arithmetic subgoal, and
    3. Each variable in a negated subgoal, also appears in a nonnegated, relational subgoal.
  • Safe rules prevent infinite results.

Example: Unsafe Rules

  • Each of the following is unsafe and not allowed:
  1. S(x) <- R(y)
  2. S(x) <- R(y) AND NOT R(x)
  3. S(x) <- R(y) AND x < y
  • In each case, an infinity of x ’s can satisfy the rule, even if R is a finite relation.