A Deductive Database with Datalog and SQL Query Languages
FernandoFernando SSááenzenz PPéérez,rez, RafaelRafael CaballeroCaballero andand YolandaYolanda GarcGarcííaa--RuizRuiz GrupoGrupo dede ProgramaciProgramacióónn DeclarativaDeclarativa (GPD)(GPD) UniversidadUniversidad ComplutenseComplutense dede MadridMadrid (Spain)(Spain)
12/5/2011 APLAS 2011 1 ~ ContentsContents 1.1. IntroductionIntroduction 2.2. QueryQuery LanguagesLanguages 3.3. IntegrityIntegrity ConstraintsConstraints 4.4. DuplicatesDuplicates 5.5. OuterOuter JoinsJoins 6.6. AggregatesAggregates 7.7. DebuggersDebuggers andand TracersTracers 8.8. SQLSQL TestTest CaseCase GeneratorGenerator 9.9. ConclusionsConclusions
12/5/2011 APLAS 2011 2 ~ 1.1. IntroductionIntroduction
SomeSome concepts:concepts: DatabaseDatabase (DB)(DB) DatabaseDatabase ManagementManagement SystemSystem (DBMS)(DBMS) DataData modelmodel (Abstract) data structures Operations Constraints
12/5/2011 APLAS 2011 3 ~ IntroductionIntroduction
DeDe--factofacto standardstandard technologiestechnologies inin databases:databases: “Relational” model SQL But,But, aa currentcurrent trendtrend towardstowards deductivedeductive databases:databases: Datalog 2.0 Conference The resurgence of Datalog inin academiaacademia andand industryindustry Ontologies Semantic Web Social networks Policy languages
12/5/2011 APLAS 2011 4 ~ Introduction.Introduction. SystemsSystems
Classic academic deductive systems: LDL++ (UCLA) CORAL (Univ. of Wisconsin) NAIL! (Stanford University) Ongoing developments Recent commercial deductive systems: DLV (Italy, University of Calabria) LogicBlox (USA) Intellidimension (USA) Semmle (UK) Recent academic deductive systems: 4QL (Warsaw University) bddbddb (Stanford University) ConceptBase (Passau, Aachen, Tilburg Universities, since 1987) XSB (Stony Brook University, Universidade Nova de Lisboa, XSB, Inc., Katholieke Universiteit LeuvLeuven,en, and Uppsala Universitet) DES (Complutense University)
12/5/2011 APLAS 2011 5 ~ DatalogDatalog EducationalEducational SystemSystem (DES)(DES)
YetYet anotheranother system,system, Why?Why? WeWe neededneeded anan interactiveinteractive systemsystem targetedtargeted atat teachingteaching DatalogDatalog inin classroomsclassrooms So,So, whatwhat aa wholewhole setset ofof featuresfeatures wewe werewere askingasking forfor suchsuch aa system?system? A system oriented at teaching User-friendly: Installation Usability Multiplatform (Windows, Linux, Mac, …) Interactive Query languages …
12/5/2011 APLAS 2011 6 ~ DESDES ConcreteConcrete FeaturesFeatures (1/4)(1/4) Free,Free, OpenOpen--source,source, Multiplatform,Multiplatform, PortablePortable QueryQuery languages:languages: (Extended)(Extended) DatalogDatalog (Recursive)(Recursive) SQLSQL followingfollowing ANSI/ISOANSI/ISO standardstandard StratifiedStratified NegationNegation IntegrityIntegrity constraintsconstraints DuplicatesDuplicates NullNull valuevalue supportsupport àà lala SQLSQL OuterOuter joinsjoins forfor bothboth SQLSQL andand DatalogDatalog AggregatesAggregates 12/5/2011 APLAS 2011 7 ~ DESDES ConcreteConcrete FeaturesFeatures (2/4)(2/4) DeclarativeDeclarative debuggersdebuggers andand tracerstracers TestTest casecase generatorgenerator forfor SQLSQL viewsviews FullFull--fledgedfledged arithmeticarithmetic DatabaseDatabase updatesupdates TemporaryTemporary DatalogDatalog viewsviews TypeType systemsystem BatchBatch processingprocessing TextualTextual APIAPI
12/5/2011 APLAS 2011 8 ~ DESDES ConcreteConcrete FeaturesFeatures (3/4)(3/4) ProgramProgram analysis:analysis: Safe rules (classical safety for range restriction) Negation Head variables Safe metapredicates Aggregates Duplicate elimination SourceSource--toto--sourcesource programprogram transformations:transformations: Safety (command /safe on) Aggregates (solving) Performance (/simplification on) ...
12/5/2011 APLAS 2011 9 ~ DESDES ConcreteConcrete FeaturesFeatures (4/4)(4/4)
But,But, quitequite relevantrelevant featuresfeatures are:are: InteractivenessInteractiveness Database updates A wide set of commands (>70) EasyEasy toto installinstall andand useuse des.sourceforge.net RobustRobust (up(up toto bugs)bugs)
12/5/2011 APLAS 2011 10 ~ DESDES allowsallows
TeachTeach (Declarative)(Declarative) QueryQuery Languages:Languages: FromFrom SQLSQL toto DatalogDatalog ButBut alsoalso forfor rapidrapid prototyping:prototyping: NovelNovel features:features: SQL hypothetical queries Outer joins in Datalog Datalog and SQL declarative (algorithmic) debuggers and tracers Test case generation for SQL views ...... andand ExperimentExperiment withwith DatalogDatalog forfor researchresearch Theses,Theses, Papers,Papers, …… SeeSee DESDES FactsFacts atat itsits webweb pagepage
12/5/2011 APLAS 2011 11 ~ 2.2. QueryQuery Languages.Languages. DatalogDatalog
AA databasedatabase queryquery languagelanguage stemmingstemming fromfrom PrologProlog
Prolog Datalog Predicate Relation Goal Query
Goals are solved one answer at a time (backtracking) Queries are solved by computing its meaning once DeductiveDeductive database:database: Extensional database: Facts Intensional database: Rules. 12/5/2011 APLAS 2011 12 ~ DatalogDatalog
DatalogDatalog differsdiffers fromfrom Prolog:Prolog: Datalog does not allow function symbols in arguments Facts are ground (safety) Datalog is truly declarative: Clause order is irrelevant Order of literals in a body is irrelevant No extra-logical constructors as the feared cut
12/5/2011 APLAS 2011 13 ~ DatalogDatalog SyntaxSyntax
Program: Set of rules. Rule: head :- body. ground_head. Head: Positive atom. Body: Conjunctions (,) and disjunctions (;) of literals Literal: Atom, Built-in (>, <, …). Query: Literal with variables or constants in arguments Body (Conjunctive queries, …)
12/5/2011 APLAS 2011 14 ~ QueryQuery Languages.Languages. SQLSQL
Follows ISO Standard DQL: SELECT Expressions FROM Relations WHERE Condition WITH RECURSIVE LocalViewDefs Statement ASSUME LocalViewDefs IN Statement (ongoing work) DML: INSERT … UPDATE … DELETE … DDL: CREATE [OR REPLACE] TABLE … CREATE [OR REPLACE] VIEW … DROP …
12/5/2011 APLAS 2011 15 ~ DatalogDatalog andand SQLSQL inin DESDES DES
Datalog SQL
Deductive engine (DE): Deductive Engine
Tabling implementation Cache Datalog programs are solved by DE ODBC In-memory Compilation of SQL views and Prolog (MySQL, Access, SQL Server, queries to Datalog programs DB Oracle, DB2,...) SQL queries are also solved by DE Interoperability is allowed: SQL and Datalog do share the deductive database! Datalog queries ↔ SQL queries Datalog typed relations ↔ SQL tables and views
12/5/2011 APLAS 2011 16 ~
DatalogDatalog tom grace
ExampleExample jack amy tony carolI
Facts: fred carolII father(tom,amy). father(jack,fred). carolIII father(tony,carolII). father(fred,carolIII). mother(graceI,amy). mother(amy,fred). mother(carolI,carolII). Query: mother(carolII,carolIII). parent(X,Y)
Rules: Minimal model for parent: { parent(X,Y) :- father(X,Y). (tom,amy), (grace,amy), (jack,fred), parent(X,Y) :- mother(X,Y). (amy,fred), … }
12/5/2011 APLAS 2011 17 ~
tom grace RecursionRecursion jack amy tony carolI father(tom,amy). fred carolII father(jack,fred). father(tony,carolII). father(fred,carolIII). carolIII mother(graceI,amy). mother(amy,fred). DES implements a fixpoint semantics for recursive mother(carolI,carolII). Datalog, finding the least fixpoint as answer mother(carolII,carolIII). parent(X,Y) :- father(X,Y). ancestor(tom,X) parent(X,Y) :- mother(X,Y). { ancestor(X,Y) :- ancestor(tom,amy), parent(X,Y). ancestor(tom,carolIII), ancestor(X,Y) :- ancestor(tom,fred) parent(X,Z), } ancestor(Z,Y).
12/5/2011 APLAS 2011 18 ~ SQLSQL RecursionRecursion asas ofof CurrentCurrent DBMS'sDBMS's
CREATE VIEW parent(parent,child) AS SELECT * FROM father UNION SELECT * FROM mother;
CREATE OR REPLACE VIEW ancestor(ancestor,descendant) AS WITH RECURSIVE rec_ancestor(ancestor,descendant) AS SELECT * FROM parent UNION SELECT parent,descendant FROM parent,rec_ancestor WHERE parent.child=rec_ancestor.ancestor SELECT * FROM rec_ancestor;
DES-SQL> SELECT * FROM ancestor WHERE ancestor='tom';
12/5/2011 APLAS 2011 19 ~ SQLSQL SimplifiedSimplified SyntaxSyntax inin DESDES Simply:Simply: CREATE OR REPLACE VIEW ancestor(ancestor, descendant) AS SELECT * FROM parent UNION SELECT parent, descendant FROM parent, ancestor WHERE parent.child=ancestor.ancestor; InsteadInstead ofof resortingresorting toto WITH:WITH: CREATE OR REPLACE VIEW ancestor(ancestor,descendant) AS WITH RECURSIVE rec_ancestor(ancestor,descendant) AS SELECT * FROM parent UNION SELECT parent, descendant FROM parent, rec_ancestor WHERE parent.child=rec_ancestor.ancestor SELECT * FROM rec_ancestor;
12/5/2011 APLAS 2011 20 ~ SQLSQL HypotheticalHypothetical QueriesQueries
CREATE TABLE flight(origin string, destination string, time real)
INSERT INTO flight VALUES('lon','ny',9.0); INSERT INTO flight VALUES('mad','par',1.5); INSERT INTO flight VALUES('par','ny',10.0);
CREATE VIEW travel(origin,destination,time) AS WITH connected(origin,destination,time) AS SELECT * FROM flight UNION SELECT flight.origin, connected.destination, flight.time+connected.time FROM flight, connected WHERE flight.destination = connected.origin SELECT * FROM connected;
12/5/2011 APLAS 2011 21 ~ SQLSQL HypotheticalHypothetical QueriesQueries
DES-Datalog> SELECT * FROM travel { answer(lon,ny,9.0), answer(mad,ny,11.5), answer(mad,par,1.5), answer(par,ny,10.0) } Info: 4 tuples computed.
DES-Datalog> ASSUME SELECT 'mad','lon',2.0 IN flight(origin,destination,time) SELECT * FROM travel; { answer(lon,ny,9.0), answer(mad,lon,2.0), answer(mad,ny,11.0), answer(mad,ny,11.5), answer(mad,par,1.5), answer(par,ny,10.0) } 12/5/2011 APLAS 2011 22 ~ Info: 6 tuples computed. 3.3. IntegrityIntegrity ConstraintsConstraints IntegrityIntegrity constraintsconstraints (IC):(IC): Strong constraints as known in databases Do not mix up with constraints as in CLP(D) ! UsualUsual IC:IC: Type (domain) Primary key Foreign key Existency constraints Check constraints NotNot soso--usualusual IC:IC: Candidate key Functional dependencies User-defined integrity constraints 12/5/2011 APLAS 2011 23 ~ TypesTypes vs.vs. DomainsDomains ImposingImposing typetype constraints:constraints: SQL table creation Interactive type assertions (even at the command prompt)
SQL: CREATE TABLE s(sno INT, name VARCHAR(10));
Datalog: :-type(s(sno:int, name:varchar(10))).
DES-Datalog> /dbschema Info: Table(s): * s(sno:number(integer),name:string(varchar(10))) Info: No views. Info: No integrity constraints. 12/5/2011 APLAS 2011 24 ~ UserUser--defineddefined IntegrityIntegrity ConstraintsConstraints
SQL:SQL: CHECK constraints (not supported by DES, yet) Triggers
CREATE TABLE t(c INT CHECK (c BETWEEN 0 AND 10));
Datalog:
DES-Datalog> :-type(t,[c:int]) DES-Datalog> :-t(X),(X<0;X>10) DES-Datalog> /assert t(11) Error: Integrity constraint violation. ic(X) :- t(X),(X < 0 ; X > 10). Offending values in database: [ic(11)]
12/5/2011 APLAS 2011 25 ~ UserUser--defineddefined IntegrityIntegrity ConstraintsConstraints
DES-Datalog> /consult paths Info: Consulting paths... edge(a,b). a edge(a,c). edge(b,a). b c edge(b,d). path(X,Y) :- path(X,Z), edge(Z,Y). path(X,Y) :- edge(X,Y). d end_of_file. Info: 6 rules consulted. DES-Datalog> :-path(X,X) Error: Integrity constraint violation. ic(X) :- path(X,X). Offending values in database: [ic(b),ic(a)] Info: Constraint has not been asserted.
12/5/2011 APLAS 2011 26 ~ 4.4. DuplicatesDuplicates
SQLSQL isis notnot setset--oriented,oriented, ratherrather itit allowsallows duplicatesduplicates inin basebase relationsrelations andand queryquery outcomesoutcomes So,So, forfor supportingsupporting SQLSQL asas DatalogDatalog programsprograms wewe need:need: MultisetsMultisets DuplicateDuplicate eliminationelimination
12/5/2011 APLAS 2011 27 ~ DuplicatesDuplicates asas ofof DESDES
Duplicates are disabled by default DES-Datalog> /duplicates on DES-Datalog> /assert t(1) DES-Datalog> /assert t(1) DES-Datalog> t(X) { t(1), t(1) } Info: 2 tuples computed.
Rules can also be source of duplicates, as in: DES-Datalog> /assert s(X):-t(X) DES-Datalog> s(X) { s(1), s(1) } Info: 2 tuples computed. 12/5/2011 APLAS 2011 28 ~ DuplicatesDuplicates asas ofof DESDES
Duplicates even in recursive rules (LDL does not allow this)
DES-Datalog> /assert t(X):-t(X) DES-Datalog> t(X) { t(1), t(1), t(1), t(1) } Info: 4 tuples computed.
No SQL implementation support this
12/5/2011 APLAS 2011 29 ~ DuplicatesDuplicates asas ofof DESDES DiscardingDiscarding duplicatesduplicates withwith metapredicates:metapredicates: distinct/1 distinct/2
DES-Datalog> distinct(t(X)) Info: Processing: answer(X) :- distinct(t(X)). { answer(1) } Info: 1 tuple computed.
SQLSQL
DES-Datalog> select distinct * from t
12/5/2011 APLAS 2011 30 ~ SafetySafety andand DuplicatesDuplicates
SetSet variablesvariables inin duplicateduplicate metapredicatesmetapredicates areare notnot boundbound
distinct([X],t(X,Y))
Unsafe goal:
distinct([X],t(X,Y)), s(Y)
DES-Datalog> distinct([X],t(X,Y)), s(Y) Error: Incorrect use of shared set variables in metapredicate: [Y] DES-Datalog> /safe on DES-Datalog> distinct([X],t(X,Y)), s(Y) Info: Processing: answer(X,Y,C) :- s(Y), distinct([X],t(X,Y)).
12/5/2011 APLAS 2011 31 ~ 5.5. OuterOuter JoinsJoins
NullNull values:values: Cte.: null Functions: is_null(Var) is_not_null(Var) OuterOuter joinjoin builtbuilt--ins:ins: Left ( ): lj(Left_Rel, Right_Rel, ON_Condition) Right ( ): rj(Left_Rel, Right_Rel, ON_Condition) Full ( ): fj(Left_Rel, Right_Rel, ON_Condition)
12/5/2011 APLAS 2011 32 ~ OuterOuter JoinJoin ExamplesExamples
SQL: SELECT * FROM a LEFT JOIN b ON x=y; Datalog: lj(a(X), b(Y), X=Y)
SQL: SELECT * FROM a LEFT JOIN b WHERE x=y; Datalog: lj(a(X), b(X), true)
SQL: SELECT * FROM a LEFT JOIN (b RIGHT JOIN c ON y=u) ON x=y; Datalog: lj(a(X), rj(b(Y), c(U,V), Y=U), X=Y)
12/5/2011 APLAS 2011 33 ~ 6.6. AggregatesAggregates
DESDES offersoffers twotwo possibilities:possibilities: AA 'group'group by'by' metapredicatemetapredicate withwith expressionsexpressions includingincluding aggregateaggregate functionsfunctions AggregateAggregate predicatespredicates withwith groupinggrouping criteriacriteria atat thethe rulerule headhead
12/5/2011 APLAS 2011 34 ~ AggregatesAggregates
AggregateAggregate functions:functions: countcount –– COUNT(*)COUNT(*) count(V)count(V) –– COUNT(C)COUNT(C) min(V)min(V) -- MIN(C)MIN(C) max(V)max(V) -- MAX(C)MAX(C) sum(V)sum(V) -- SUM(C)SUM(C) avg(Var)avg(Var) -- AVG(C)AVG(C) times(Var)times(Var) -- NoNo SQLSQL counterpartcounterpart
12/5/2011 APLAS 2011 35 ~ AggregatesAggregates
MetapredicateMetapredicate group_by/3
group_by( Relation, % FROM / WHERE [Var_1,…,Var_n], % GroupingGrouping columnscolumns Condition) % HAVING / ProjectionProjection
12/5/2011 APLAS 2011 36 ~ AggregatesAggregates ExampleExample employee Number of employees for each department: Name Department Salary
DES-Datalog> group_by(employee(N,D,S), anderson accounting 1200 [D], andrews accounting 1200
R=count). arlingon accounting 1000 Info: Processing: answer(D,R) :- nolan null null group_by(employee(N,D,S),[D],R=count). norton null null
{ randall resources 800 answer(accounting,3), answer(null,2), sanders sales null answer(resources,1), silver sales 1000
answer(sales,5) smith sales 1000 } Info: 4 tuples computed. Steel sales 1020 Sullivan sales null
12/5/2011 APLAS 2011 37 ~ AggregatesAggregates ExampleExample (contd.)(contd.) employee Active employees of departments with Name Department Salary more than one active employee: anderson accounting 1200
DES-Datalog> group_by(employee(N,D,S), andrews accounting 1200 [D], arlingon accounting 1000 count(S)>1). Info: Processing: nolan null null answer(D) :- norton null null group_by(employee(N,D,S), randall resources 800 [D], (A = count(S), A > 1)). sanders sales null { silver sales 1000 answer(accounting), smith sales 1000 answer(sales) } Steel sales 1020 Info: 2 tuples computed. Sullivan sales null
12/5/2011 APLAS 2011 38 ~ AggregatesAggregates
AggregateAggregate metapredicates:metapredicates: count(Relation,Result) count(Relation,CountedVar,Result) min(Relation,Result) max(Rel,Result) sum(Rel,SummedVar,Result) avg(Rel,AvgdVar,Result) times(Rel,MultdVar,Var)
DES-Datalog> count(employee(_,_,_),C) Info: Processing: answer(C) :- count(employee(_,_,_),[],C). 12/5/2011 APLAS 2011 39 ~ AggregateAggregate PredicatesPredicates andand GroupGroup ByBy
Number of employees for each department. Recall predicate group_by and functions:
DES-Datalog> group_by(employee(N,D,S), [D], C=count)
With aggregate predicates:
DES-Datalog> c(D,C) :- count(employee(N,D,S),S,C) { c(accounting,3), c(null,0), c(resources,1), c(sales,3) }
12/5/2011 APLAS 2011 40 ~ AggregatesAggregates andand RecursionRecursion
% SQL Program % Datalog Program
CREATE OR REPLACE VIEW path(X,Y,1) :- shortest_paths(Origin,Destination,Length) AS edge(X,Y). WITH RECURSIVE path(X,Y,L) :- path(Origin,Destination,Length) AS path(X,Z,L0), (SELECT edge.*,1 FROM edge) edge(Z,Y), UNION count(edge(A,B),Max), (SELECT L0 % SQL Query % Datalog Query: SELECT * FROM shortest_paths; shortest_paths(X,Y,L) :- min(path(X,Y,Z),Z,L). 12/5/2011 APLAS 2011 41 ~ SafetySafety andand AggregatesAggregates SetSet variablesvariables inin aggregateaggregate metapredicatesmetapredicates areare notnot boundbound group_by(t(X,Y),[X],C=count) Unsafe goal: group_by(t(X,Y),[X],C=count), s(Y) DES-Datalog> group_by(t(X,Y),[X],C=count), s(Y) Error: Incorrect use of shared set variables in metapredicate: [Y] DES-Datalog> /safe on DES-Datalog> group_by(t(X,Y),[X],C=count), s(Y) Info: Processing: answer(X,Y,C) :- s(Y), group_by(t(X,Y),[X],C = count). 12/5/2011 APLAS 2011 42 ~ AggregatesAggregates andand DISTINCTDISTINCT ForFor discardingdiscarding duplicatesduplicates (functions(functions andand metapredicates):metapredicates): sum_distinct count_distinct - SELECT DISTINCT COUNT(*) count_distinct(V) - SELECT COUNT(DISTINCT C) avg_distinct times_distinct No need for min_distinct and max_distinct 12/5/2011 APLAS 2011 43 ~ 7.7. DeguggersDeguggers andand Tracers.Tracers. DatalogDatalog DeclarativeDeclarative DebuggerDebugger Motivation:Motivation: AbstractAbstract thethe solvingsolving--orientedoriented debuggingdebugging procedureprocedure Roots:Roots: [Shaphiro83],[Shaphiro83], AlgorithmicAlgorithmic ProgramProgram DebuggingDebugging SemanticsSemantics--orientedoriented 12/5/2011 APLAS 2011 44 ~ DeclarativeDeclarative DebuggerDebugger between(X,Z):- br(X),br(Y),br(Z),X odd(Y) :- even(Z), next(Z,Y). Elements in an odd position br_is_even :- even(X), not(next(X,Y)). Succeeds if the cardinality is even br(a). Base relation (sequence of elements) br(b). 12/5/2011 APLAS 2011 45 ~ DeclarativeDeclarative Debugging:Debugging: SemanticSemantic GraphGraph br_is_even = { } next(nil, Y) = {next(nil,b)} even(X) = {even(nil)} br(nil) = { } odd(X) = {odd(b)} Non-valid br(Y) = {br(a), br(b)} next(b, X) = { } Unknown has_preceding(a)= {has_preceding(a)} br(b) = {br(b)} br(a)= {br(a)} has_preceding(b)= {} 12/5/2011 APLAS 2011 46 ~ DeclarativeDeclarative Debugging:Debugging: AA PracticalPractical SessionSession DES> /debug_datalog br_is_even Debugger started ... Is br(b) = {br(b)} valid(v)/non-valid(n) [v]? v Is has_preceding(b) = {} valid(v)/non-valid(n) [v]? n Is br(X) = {br(b),br(a)} valid(v)/non-valid(n) [v]? v ! Error in relation: has_preceding/1 ! Witness query: has_preceding(b) = { } 12/5/2011 APLAS 2011 47 ~ SQLSQL DebuggerDebugger MotivationMotivation asas ofof DatalogDatalog DebuggerDebugger AddsAdds traversingtraversing strategiesstrategies DivideDivide && QueryQuery /debug_sql Guest order(dq) Also,Also, trustedtrusted tablestables /debug_sql Guest trust_tables(no) AndAnd trustedtrusted specifications:specifications: /debug_sql Guest trust_file(pets_trust) 12/5/2011 APLAS 2011 48 ~ SQLSQL DebuggerDebugger Owner( id integer primary key, DES-SQL> /debug_sql Guest name varchar(50)); Info: Outcome of view 'LessThan6': Pet( code integer primary key, { name varchar(50), specie 'LessThan6'(1), varchar(20)); 'LessThan6'(1), 'LessThan6'(2), PetOwner( id integer, code 'LessThan6'(2), integer, primary key (id,code), 'LessThan6'(3), Info: Outcome of view 'AnimalOwner': foreign key (id) references 'LessThan6'(4) { Owner(id), foreign key (code) } references Pet(code)) AnimalOwner(1,'Kitty',cat), Input: Is this view valid? (y/n/a) [y]: y AnimalOwner(1,'Wilma',dog), Info: Outcome of view AnimalOwner(2,'Lucky',dog), AnimalOwner 'NoCommonName':'NoCommonName': AnimalOwner(2,'Wilma',cat), LessThan6 (AnimalOwner) { AnimalOwner(3,'Oreo',cat), CatsAndDogsOwner 'NoCommonName'(1), (AnimalOwner) AnimalOwner(3,'Rocky',dog), (AnimalOwner) 'NoCommonName'(2), NoCommonName AnimalOwner(4,'Cecile',turtle), NoCommonName 'NoCommonName'(3) (CatsAndDogsOwner) AnimalOwner(4,'Chelsea',dog) } Guest (NoCommonName, } LessThan6 ) Input: Is this view valid? (y/n/a) [y]: n LessThan6 ) Input: Is this view valid? (y/n/a) [y]: y Info: Outcome of view DES-SQL> select * from Guest 'CatsAndDogsOwner':'CatsAndDogsOwner': Info: Buggy view found: CatsAndDogsOwner/2. answer(Guest.id, Guest.name) -> { { 'CatsAndDogsOwner'(1,'Wilma'), answer(1,'Mark Costas'), 'CatsAndDogsOwner'(2,'Lucky'), answer(2,'Helen Kaye'), 'CatsAndDogsOwner'(3,'Rocky') answer(3,'Robin Scott') } } Input: Is this view valid? (y/n/a) [y]: n Info: 3 tuples computed. 12/5/2011 APLAS 2011 49 ~ DatalogDatalog TracerTracer a a :- not(b). b c b :- c,d. c :- b. c. d DES-Datalog> /c negation Info : Remaining predicates: DES-Datalog> /trace_datalog a [c/0,d/0] Info: Tracing predicate 'a'. Input: Continue? (y/n) [y]: { Info: Tracing predicate 'c'. a { } c Info: 1 tuple in the answer table. } Info : Remaining predicates: Info: 1 tuple in the answer table. [b/0,c/0,d/0] Info : Remaining predicates: [d/0] Input: Continue? (y/n) [y]: Input: Continue? (y/n) [y]: Info: Tracing predicate 'b'. Info: Tracing predicate 'd'. { { not(b) } } Info: No more predicates to trace. Info: 1 tuple in the answer table. 12/5/2011 APLAS 2011 50 ~ SQLSQL TracerTracer DES-SQL> /trace_sql ancestor Info: Tracing view 'ancestor'. { Info : Remaining views: [mother/2] ancestor(amy,carolIII), ... Input: Continue? (y/n) [y]: ancestor(tony,carolIII) Info: Tracing view 'mother'. } { Info: 16 tuples in the answer table. { Info : Remaining views: mother(amy,fred), ... [parent/2,father/2,mother/2] mother(grace,amy) Input: Continue? (y/n) [y]: } Info: Tracing view 'parent'. Info: 4 tuples in the answer table. { Info: No more views to trace. parent(amy,fred), ... DES-SQL> /trace_datalog father(X,Y) parent(tony,carolII) } Info: Tracing predicate 'father'. Info: 8 tuples in the answer table. { Info : Remaining views: [father/2,mother/2] father(fred,carolIII), ... Input: Continue? (y/n) [y]: father(tony,carolII) Info: Tracing view 'father'. } { Info: 4 tuples in the answer table. father(fred,carolIII), ... Info: No more predicates to trace. father(tony,carolII) } Info: 4 tuples in the answer table. 12/5/2011 APLAS 2011 51 ~ 8.8. SQLSQL TestTest CaseCase GeneratorGenerator ProvidesProvides tuplestuples thatthat cancan bebe matchedmatched toto thethe intendedintended interpretationinterpretation ofof aa viewview TestTest casescases Positive (PTC) Negative (NTC) QueryingQuerying aa viewview w.r.t.w.r.t. PTC: One tuple, at least NTC: One tuple, at least, which does not match the WHERE condition PredicatePredicate coverage:coverage: PNTC: Contains both PTC and NTC tuples 12/5/2011 APLAS 2011 52 ~ SQLSQL TestTest CaseCase GeneratorGenerator PNTCPNTC DES-SQL> create table t(a int primary key) DES-SQL> create view v(a) as select a from t where a=5 DES-SQL> /test_case v Info: Test case over integers: [t(5),t(-5)] NoNo PNTCPNTC create view v(a) as select a from t where a=1 and not exists (select a from t where a<>1); SupportSupport for:for: Integer and string types Aggregates, UNION Options: Adding/replacing results to a table Kind of generated test case (PTC, NTC, PNTC) Test case size 12/5/2011 APLAS 2011 53 ~ 9.9. ConclusionsConclusions SuccessfulSuccessful implementationimplementation guidedguided byby needneed WidelyWidely used,used, bothboth forfor teachingteaching andand researchresearch More than 35,000 downloads Up to more than 1,500 downloads/month IncludesIncludes novelnovel featuresfeatures Hypothetical SQL Declarative debuggers Outer joins ButBut keykey factorsfactors areare also:also: Datalog and SQL integration Interactive, user-friendly, multiplatform system Just download it and play! 12/5/2011 APLAS 2011 54 ~ LimitationsLimitations (Future(Future Work)Work) DataData areare constants,constants, nono termsterms (functions)(functions) areare allowedallowed DatalogDatalog databasedatabase updatesupdates BeyondBeyond 2.5VL2.5VL SQLSQL coveragecoverage stillstill incompleteincomplete PrecisePrecise syntaxsyntax errorerror reportsreports ConstraintsConstraints ((àà lala CLP)CLP) PerformancePerformance …… onlyonly toto namename aa few!few! 12/5/2011 APLAS 2011 55 ~ Canada University of California, at Los Angeles Efficient Integrity Checking for Databases with Recursive CS240A: Databases and Knowledge Bases Views Davide Martinenghi and Henning Christiansen The University of Arizona In Advances in Databases and Information Systems: 9th CsC372 East European Conference, ADBIS 2005, Tallinn, Estonia, The State University of New York September 12-15, 2005 : Proceedings Autor Johann Eder, Hele-Mai Haav, Ahto DESDESKalja, Jaan FactsFactsUniversity at Buffalo Penjam CSE 636: Data Integration ISBN 3540285857, 9783540285854 The University of British Columbia PhD CS304: Introduction to Relational Databases Computer Science and Engineering Department University of Nebraska - Lincoln, USA Datalog Tutorial PhD Master's of Information Technology in University of Texas at San Antonio, USA Arkansas Tech University, Russellville Industry: The University of Texas at Austin XLOG Technologies GmbH, Zürich CS2 CaseLab : Applied Operations Research Ideacube Australia: Links to DES: INFO2820: Database Systems 1 (Advanced) (2010 - ACM SIGMOD Online Publicly Available Database Semester 1) Software from Nonprofit Organizations Engineering and Information Technologies The ALP Newsletter. vol. 21 n. 1 The University of Sydney Datalog Wikipedia German Tab “Resources” Datalog Wikipedia English INFO2120/2820: Database Systems 1 (2009 - Semester 1) Wapedia School of Information Technologies SWI-Prolog. Related Web Resources The University of Sydney SICStus Prolog. Third Party Software. Other Research Systems Tutorial 3 SOFTPEDIA. Datalog Educational System 1.7.0 Allan Hancock College >> INFO >> 2120 Fall, 2009 Famouswhy Description: School of Information Technologies DBpedia INFO2120/2820: Database Systems I 1.Sem./2009 BDD-Based Deductive DataBase (bddbddb) Tutorial 3: SQL and Relational Algebra 23.03.2009 Other implementations of Datalog/Prolog Reach Information Africa: Ask a Word Faculty of Sciences and Technologies of Acronym finder Mohammedia (FSTM) - Morocco 12/5/2011Acronym Geek APLAS 2011 56 ~ .