Deductive Databases
Total Page:16
File Type:pdf, Size:1020Kb
Deductive Databases FernandoFernando SSááenzenz PPéérezrez GrupoGrupo dede ProgramaciProgramacióónn DeclarativaDeclarativa (GPD)(GPD) UniversidadUniversidad ComplutenseComplutense dede MadridMadrid FacultadFacultad dede InformInformááticatica 9/21/2011 PROMETIDOS-CM Summer School 1 / 141 ContentsContents 1. Introduction DES 2. Data Models Relational Logic 3. Datalog Fixpoint Semantics Completeness of Datalog w.r.t. RA Stratified Negation 4. Deductive Systems Expressions Constraints Duplicates Aggregates Outer Joins Current DBMS's Limitations 5. Debugging Declarative Debugging Tracers Test Case Generator 6. Other Features 7. Conclusions 9/21/2011 PROMETIDOS-CM Summer School 2 / 141 IntroductionIntroduction DatabasesDatabases (as(as earlyearly asas 1965):1965): Data banks Network (Codasyl model) – Mid 60s BF Goodrich IDMS Hierarchic – 1969 IBM IMS-DB Inverted files – 1970 Software AG ADABAS Relational – 1970 Codd - 1974 IBM System R Deductive – Mid 70s IBM DEDUCE 2 Object oriented – 1988 Objectivity/DB Constraint – 1990 CQL Geodatabases – 1992 ESRI Arc/Info Active – 1996 ACT-Net Consortium Relational object-oriented – 2000 ODMG 3.0 SUN Oracle (Native) XML – 2003 MonetDB/XQuery 9/21/2011 PROMETIDOS-CM Summer School 3 / 141 IntroductionIntroduction SomeSome concepts:concepts: DatabaseDatabase (DB)(DB) DatabaseDatabase ManagementManagement SystemSystem (DBMS)(DBMS) DataData modelmodel (Abstract) data structures Operations QueryQuery languagelanguage 9/21/2011 PROMETIDOS-CM Summer School 4 / 141 IntroductionIntroduction QueryQuery languages:languages: OlderOlder Navigational:Navigational: IMSIMS -- CobolCobol RARA TRCTRC TRDTRD SQLSQL (SEQUEL(SEQUEL IBMIBM SystemSystem R)R) DatalogDatalog NewerNewer Navigational:Navigational: XPath/XQueryXPath/XQuery 9/21/2011 PROMETIDOS-CM Summer School 5 / 141 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 9/21/2011 PROMETIDOS-CM Summer School 6 / 141 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 Leuven, and Uppsala Universitet) DES (Complutense University) 9/21/2011 PROMETIDOS-CM Summer School 7 / 141 Introduction.Introduction. 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 wouldwould askask forfor suchsuch aa system?system? A system oriented at teaching User-friendly: Installation Usability Multiplatform (Windows, Linux, Mac, …) Interactive Query languages … 9/21/2011 PROMETIDOS-CM Summer School 8 / 141 DESDES ConcreteConcrete FeaturesFeatures (1/2)(1/2) Free,Free, OpenOpen--source,source, Multiplatform,Multiplatform, PortablePortable QueryQuery languageslanguages sharingsharing EDB/IDB:EDB/IDB: Datalog following ISO Prolog standard (Recursive) SQL following ANSI/ISO standard DatabaseDatabase updates:updates: SQL DML Commands TemporaryTemporary DatalogDatalog viewsviews DuplicatesDuplicates DeclarativeDeclarative debuggingdebugging ofof DatalogDatalog programsprograms TestTest casecase generationgeneration forfor SQLSQL viewsviews DatalogDatalog andand SQLSQL tracerstracers 9/21/2011 PROMETIDOS-CM Summer School 9 / 141 DESDES ConcreteConcrete FeaturesFeatures (2/2)(2/2) Null value support à la SQL Outer joins for both SQL and Datalog Aggregates Stratified Negation Integrity constraints: Domain Referential integrity Functional dependencies Uniqueness Full-fledged arithmetic Type system for SQL tables and views, and Datalog programs Source-to-source program transformations: Safety Performance (simplifications) Tabling-based implementation 9/21/2011 PROMETIDOS-CM Summer School 10 / 141 SQLSQL Follows ISO Standard DQL: SELECT … FROM … WHERE WITH RECURSIVE … DML: INSERT … UPDATE … DELETE … DDL: CREATE [OR REPLACE] TABLE … CREATE [OR REPLACE] VIEW … DROP … 9/21/2011 PROMETIDOS-CM Summer School 11 / 141 DatalogDatalog andand SQLSQL inin DESDES Deductive engine (DE): Tabling implementation Datalog programs are solved by DE Compilation of SQL views and queries to Datalog programs 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 9/21/2011 PROMETIDOS-CM Summer School 12 / 141 ODBCODBC ConnectionsConnections New feature since version 2.0 Access to Relational DBMS MySQL MS Access Oracle … SQL statements injected to the DBMS engine Query results are cached by the Datalog engine 9/21/2011 PROMETIDOS-CM Summer School 13 / 141 DESDES asas aa TestTest--BedBed forfor ResearchResearch TestTest casecase generationgeneration forfor SQLSQL viewsviews DatalogDatalog declarativedeclarative (algorithmic)(algorithmic) debuggingdebugging DatalogDatalog andand SQLSQL tracerstracers NovelNovel proposalproposal forfor outerouter joinsjoins inin DatalogDatalog Theses,Theses, Papers,Papers, AcademiaAcademia…… SeeSee DESDES FactsFacts atat itsits webweb pagepage 9/21/2011 PROMETIDOS-CM Summer School 14 / 141 "Impact"Impact factor"factor" Up to more than 1,500 downloads a month More than 36,000 downloads since 2004 Month downloads greater than XSB, GNU Prolog, YAP, … More than 10,000 entries in Google First positions in search engines when looking for "Datalog" Moved at the very first position in Datalog entry at Wikipedia It was not me! ☺ 9/21/2011 PROMETIDOS-CM Summer School 15 / 141 InstallingInstalling DESDES DistroDistro underunder GPLGPL inin Sourceforge:Sourceforge: Sources Portable Executables (Windows, Linux, Mac OS X) Portable Bundle including Java IDE (Windows) StartingStarting thethe system.system. Either:Either: From a Prolog interpreter Ciao 1.14.2 GNU Prolog 1.4.0 SICStus Prolog 4.2.0 (Complete support for all features) SWI-Prolog 5.10.5 (Complete support for all features) Simply execute the binary Start the Java application 9/21/2011 PROMETIDOS-CM Summer School 16 / 141 DESDES runningrunning underunder ACIDEACIDE DESDES runningrunning underunder ACIDEACIDE 9/21/2011 PROMETIDOS-CM Summer School 17 / 141 DESDES runningrunning underunder EmacsEmacs 9/21/2011 PROMETIDOS-CM Summer School 18 / 141 DESDES runningrunning asas aa WindowsWindows applicationapplication 9/21/2011 PROMETIDOS-CM Summer School 19 / 141 DESDES runningrunning underunder MacMac OSOS XX SnowSnow LeopardLeopard 9/21/2011 PROMETIDOS-CM Summer School 20 / 141 DESDES runningrunning inin aa LinuxLinux terminalterminal 9/21/2011 PROMETIDOS-CM Summer School 21 / 141 ImplementationImplementation DES command-line interpreter: Prolog Tabling (Bottom-up Top-down driven) Computation by strata saturations (negation and aggregates) Type system: CLP(FD) Datalog Debugger: Prolog + Java [CGS07] R. Caballero, Y. García-Ruiz, and F. Sáenz-Pérez, A new proposal for debugging datalog programs. WFLP’07 SQL Debugger: CLP(FD) [CGS11b] R. Caballero, Y. García-Ruiz and F. Sáenz-Pérez, "Algorithmic Debugging of SQL Views", Eigth Ershov Invormatics Conference, PSI'11 Test Case Generator: CLP(FD) [CGS10a] R. Caballero, Y. García-Ruiz, and F. Sáenz-Pérez, Applying Constraint Logic Programming to SQL Test Case Generation, FLOPS 2010 ACIDE: Java A Configurable IDE (LaTeX, SQL, Prolog, Datalog, …) [Sae07b] F. Sáenz-Pérez, “ACIDE: An Integrated Development Environment Configurable for LaTeX”, The PracTeX Journal, 2007 9/21/2011 PROMETIDOS-CM Summer School 22 / 141 IntroductionIntroduction GoalsGoals ofof thisthis talk:talk: Databases:Databases: FromFrom relationalrelational toto deductivedeductive (Declarative)(Declarative) QueryQuery Languages:Languages: FromFrom SQLSQL toto DatalogDatalog SQL: Many functionalities Datalog: Neater formulations How:How: DataData modelsmodels ConcreteConcrete system:system: DESDES 9/21/2011 PROMETIDOS-CM Summer School 23 / 141 RelationalRelational ModelModel Edgar.Edgar. F.F. (Ted)(Ted) CoddCodd (1923(1923--2003)2003) inin thethe earlyearly seventies.seventies. [[ TuringTuring AwardAward ––19811981 ]] SimpleSimple andand elegantelegant modelmodel withwith aa mathematicalmathematical basis.basis. Language:Language: RelationalRelational algebraalgebra operationsoperations QueryQuery optimizationoptimization andand executionexecution DatabaseDatabase standardstandard ANSI/ISOANSI/ISO SQLSQL CurrentCurrent DBMSsDBMSs supportsupport relationalrelational modelmodel Warning:Warning: TheyThey areare flawedflawed extensions.extensions. 9/21/2011 PROMETIDOS-CM Summer School 24 / 141 RelationalRelational Model.Model. ConceptsConcepts RelationRelation schemaschema RelationRelation