{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

Himanshu Gupta CSE 532–DLog–1 Recap and Schedule Till Now: Query Languages: Relational Algebra; SQL Today: Datalog – A logical query language. SQL Recursion.

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

View Full Document
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.
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

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

View Full Document
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 .
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)

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

View Full Document
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.
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 .

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online