datalog - Recap and Schedule Till Now: Query Languages:...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Himanshu Gupta CSE 532–DLog–1 Recap and Schedule Till Now: Query Languages: Relational Algebra; SQL Today: Datalog – A logical query language. SQL Recursion.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Himanshu Gupta CSE 532–DLog–2 Logical Query Languages Motivation: 1. Logical rules extend more naturally to recursive queries than does relational algebra. Used in SQL recursion. 2. Logical rules form the basis for many information-integration systems and applications.
Background image of page 2
Himanshu Gupta CSE 532–DLog–3 Tables as Predicates The basic premise of logical data model is to view tables as predicates . Given a table R(A,B,C) = {(1,2,4), (1,2,3), (1,1,1)} (i.e, a table with three tuples). View the table R as a predicate R(x,y,z) which is true/false depending on whether <x,y,z> is a tuple in R. Therefore, R(1,2,4) is TRUE R(1,3,3) is FALSE
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Himanshu Gupta CSE 532–DLog–4 Datalog Example Likes(drinker , beer ); Sells(bar , beer , price); Frequents(drinker , bar ) Happy(d) <- Frequents(d,bar) AND Likes(d,beer) AND Sells(bar,beer,p) Above = rule . Left side = head . Right side = AND of subgoals = body Head and subgoals consist of: Predicates: Relation name or arithmetic predicate Arguments : Variables or constants. Subgoals (not head) may optionally be negated by NOT .
Background image of page 4
Himanshu Gupta CSE 532–DLog–5 Meaning of Rules Head is true if: Some values for variables make all the subgoals true. If no negation or arithmetic comparisons, then natural join of subgoals and project the head variables. Example Previous rule equivalent to Happy(d) = π drinker (Frequents Likes Sells)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Himanshu Gupta CSE 532–DLog–6 Evaluation of (Non-Recursive) Rules Consider all possible assignments of values to variables. For each assignment: If all subgoals are true, add the head to the result relation.
Background image of page 6
Himanshu Gupta CSE 532–DLog–7 Example: Variable-Based Assignment S(x,y) <- R(x,z) AND R(z,y) AND NOT R(x,y) R = A B 1 2 2 3 First subgoal true for: 1. x 1, z 2. 1. x 2, z 3. Case (1) : y 3 makes 2 nd and 3 rd subgoals true. Thus, add ( x , y ) = (1,3) to relation S .
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 532–DLog–8 Example: Variable-Based (Contd) S(x,y) <- R(x,z) AND R(z,y) AND NOT R(x,y) R = A B 1 2 2 3 1. x 2, z 3. Case (2) : No y value makes the 2 nd subgoal true. Thus, no other tuple added to
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/26/2010 for the course CSE 532 taught by Professor Badr,h during the Fall '08 term at SUNY Stony Brook.

Page1 / 32

datalog - Recap and Schedule Till Now: Query Languages:...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online