DOC PREVIEW
SJSU CMPE 226 - Datalog Queries

This preview shows page 1-2-3-24-25-26 out of 26 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Database DesignPowerPoint PresentationSlide 3DatalogDatalog Queries: SyntaxDatalog Queries: Syntax – Example (1)Datalog Queries: Syntax – Example (2)Datalog Queries: Syntax – Example (3)Datalog Queries: Syntax – Example (4)Slide 10Slide 11Slide 12Datalog with Sets (1)Datalog with Sets (2)Datalog with Sets (3)Datalog with Sets (4)Datalog with Sets (5)Datalog with Abstract Data Types (1)Datalog with Abstract Data Types (2)Datalog with Abstract Data Types (3)Semantics (1)Semantics: Example (1)Semantics: Example (2)Proof Trees (1)Proof Trees (2)Discussion Questions2003SJSU -- CmpE L8-S1 Datalog QueriesDatabase Design Dr. M.E. Fayad, ProfessorComputer Engineering Department, Room #283I College of EngineeringSan José State UniversityOne Washington SquareSan José, CA 95192-0180 http://www.engr.sjsu.edu/~fayad2003SJSU – CmpE --- M.E. Fayad L8-S2 Datalog Queries2Lesson 08:Datalog Queries2003SJSU – CmpE --- M.E. Fayad L8-S3 Datalog Queries Lesson ObjectivesObjectives3 Understand datalog langauge Learn about:  Syntax of Datalog Rules Datalog with Sets Datalog with Abstract Data Types Semantics Recursive Datalog Queries2003SJSU – CmpE --- M.E. Fayad L8-S4 Datalog QueriesDatalog is a rule-based language that is related to PrologEach rule is a statement has some points that belong to some relations and other points must belong to a defined relation.Each Datalog query contains a Datalog program and an input database.4Datalog2003SJSU – CmpE --- M.E. Fayad L8-S5 Datalog QueriesDatalog query – a finite set of rules of the form:R0(x1,…,xk) :– R1(x1,1,…, x1,k1),..., Rn(xn,1,…, xn,kn)where each Ri is either an input or a defined relation name. including built-in relations such as +(x,y,z) which meansx + y = z. (We normally use the latter syntax.)The preceding rule is read “R0 is true if R1 and .. and Rn are all true. head of the rule – R0body of the rule – R1,…,Rn 5Datalog Queries: Syntax2003SJSU – CmpE --- M.E. Fayad L8-S6 Datalog Queries[4.1.1] See Taxrecord and Taxtable (Page 8)Find the SSN and the tax.Tax_Due(s, t) :– Taxrecord(s, w, i, c), Taxtable(inc, t), w+i+c = inc.Requires one rule where Taxrecord and Taxtable are input database relations and Tax_Due is the only defined relation.6Datalog Queries: Syntax – Example (1)2003SJSU – CmpE --- M.E. Fayad L8-S7 Datalog Queries[4.1.2] Suppose that relation Street (n, x, y) contains all combinations of street name n and locations (x, y) such that a location belongs to the street. Find the streets that can be reached from (x0,y0).Reach(n) :– Street(n, x0, y0). -- Rule 1This rule says that street n is reachable if it contains the initial point.Reach(n) :– Reach(m), Street(m, x, y), Street(n, x, y). – Rule 2 This rule says that if m is reachable and m and n intersect on some point, than n is also reachable.7Datalog Queries: Syntax – Example (2)2003SJSU – CmpE --- M.E. Fayad L8-S8 Datalog Queries[4.1.3] Find the time to travel from x to y. Travel(x, y, t) :– Go(x, 0, y, t).Travel(x, y, t) :– Travel(x, z, t2), Go(z, t2, y, t).The head defines the travel(x, y, t) relation, which is true if it is possible to travel from city x to city y in time t.8Datalog Queries: Syntax – Example (3)2003SJSU – CmpE --- M.E. Fayad L8-S9 Datalog Queries[4.1.8] Find town points covered by a radio station or find every place in town that can e reached by at least one broadcast station.A kind of “map overlay problem”In this kind of problems, the scales and the points of the maps to be overlayed are not the same.Suppose that a relation Parameters(ID, Scale, X0, Y0) records for each map it scale and point of origin.9Datalog Queries: Syntax – Example (4)2003SJSU – CmpE --- M.E. Fayad L8-S10 Datalog QueriesSuppose a town map where each point corresponds to a half kilometer, and in the broadcast map each point corresponds to a kilometer and the points of origin are the same for both maps.Then (1, 1, 0, 0), (2, 1, 0, 0), (3, 1, 0, 0), and (San Jose, 0.5, 0, 0) would be parameters relation. 10Datalog Queries: Syntax – Example (4)2003SJSU – CmpE --- M.E. Fayad L8-S11 Datalog QueriesWe can find the points in town that are covered using the following queryCovered(x2, y2) :– Broadcast(n, x, y), Town(t, x2, y2), Parameters(n, s, blat, blong), Parameters(t, s2, tlat, tlong), x2 = s/ s2 x + (tlat – blat), y2 = s/ s2 y + (tlong – blong).This query at first scales up and shift every point (x, y) in the broadcast map n to match the scale and point of the town map. If it corresponds to a point (x2, y2) in the town map, then it is added to relation Covered. 11Datalog Queries: Syntax – Example (4)2003SJSU – CmpE --- M.E. Fayad L8-S12 Datalog Queries12Datalog Queries: Syntax – Example (4)2003SJSU – CmpE --- M.E. Fayad L8-S13 Datalog QueriesWe think of the domain of each attribute is a set.We can represent an undirected graph in two relations: Vertices and Edge (X1, X2) that contains a pair of singleton sets of city names iff there is an edge between them. For example:Edge ({San Jose}, {San Francisco}) would be one tuple in the Edge relation.13Datalog with Sets (1)2003SJSU – CmpE --- M.E. Fayad L8-S14 Datalog QueriesHamiltonian Cycle inAn Undirected graph is a path that starts and ends with the same vertex and goes through each vertex exactly once.Assume Start (X) is an input relation where X is a singleton set containing the name of starting vertex of the cycle. Find a Hamiltonian Cycle where a set of vertices A not yet visited.14Datalog with Sets (2)2003SJSU – CmpE --- M.E. Fayad L8-S15 Datalog QueriesExample: Hamiltonian CycleInput: •Vertices(S) where S is a set of vertices•Edge ({c1}, {c2}) if there is an edge from c1 to c2•Start({c}) where c is start city nameOutput:•Path ({c}, B) if there is a path from c that uses all vertices except those in B.•Hamiltonian ({c}) if there is a Hamiltonian path.15Datalog with Sets (3)2003SJSU – CmpE --- M.E. Fayad L8-S16 Datalog QueriesBase case – Path is a single vertex. All vertices except the start vertex is unvisited. Path(X1, B) :– Vertices(A), Start(X1), B = A \ X1.Recursion – a path to


View Full Document

SJSU CMPE 226 - Datalog Queries

Documents in this Course
SQL-99

SQL-99

71 pages

XML

XML

52 pages

XML

XML

14 pages

Chapter 9

Chapter 9

45 pages

Load more
Download Datalog Queries
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Datalog Queries and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Datalog Queries 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?