8-datalog

# 8-datalog - DATALOG CS273 Data and Knowledge Bases Xifeng Y...

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

DATALOG CS273 - Data and Knowledge Bases Xifeng Yan Computer Science niversity of California at Santa Barbara University of California at Santa Barbara

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

View Full Document
Department of Computer Science QL is Not Enough! SQL is Not Enough! CS273: Data and Knowledge Bases | University of California at Santa Barbara 2
Department of Computer Science Domain Relational Calculus Queries have form: 1 x2 n p} predicate {x1,x2, …, xn| p } Predicate: boolean expression over x1,x2, …, xn domain variables We have the following operations: x i op x j x i op const const op x i p p x i . p x j . p p q, p q p, p q where op is , , , , , and x i ,x j ,… are domain variables; p,q are predicates ecall that this captures the same expressiveness as the Recall that this captures the same expressiveness as the relational algebra CS273: Data and Knowledge Bases | University of California at Santa Barbara 3 slides by courtesy of Ives with modifications

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

View Full Document
Department of Computer Science Logic-Based Language: Datalog Borrows the flavor of the relational calculus Based on the Prolog logic-programming language A “datalog program” will be a series of if-then rules that define relations from predicates Rules are generally of the form: R out (T 1 ) R 1 (T 2 ), R 2 (T 3 ), …, c(T 2 ,…T n ) where R out is the relation representing the query result, R i are predicates representing relations , c is an expression using arithmetic/boolean predicates over vars, and T are tuples of variables i p CS273: Data and Knowledge Bases | University of California at Santa Barbara 4
Department of Computer Science Datalog Terminology An example datalog rule: idb(x,y) r1(x,z), r2(z,y), z < 10 body head subgoals Irrelevant variables can be replaced by _ ( anonymous var) xtensional relations r database schemas ( dbs are Extensional relations or database schemas ( edbs ) are relations only occurring in rules’ bodies – these are base relations with “ground facts” Intensional relations ( idbs ) appear in the heads – these are basically views istinguished variables re the ones output in the head CS273: Data and Knowledge Bases | University of California at Santa Barbara 5 Distinguished variables are the ones output in the head Ground facts only have constants, e.g., r1(“abc”, 123)

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

View Full Document