Foundations of Query Languages



Similar documents
Schema Mappings and Data Exchange

Relational Calculus. Module 3, Lecture 2. Database Management Systems, R. Ramakrishnan 1

SQL Database queries and their equivalence to predicate calculus

µz An Efficient Engine for Fixed points with Constraints

3. Relational Model and Relational Algebra

Relational Databases

Question Answering and the Nature of Intercomplete Databases

Relational Database Systems 1

Fixed-Point Logics and Computation

EQUATIONAL LOGIC AND ABSTRACT ALGEBRA * ABSTRACT

Cassandra. References:

Relational Algebra. Basic Operations Algebra of Bags

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

Relational Algebra. Module 3, Lecture 1. Database Management Systems, R. Ramakrishnan 1

A Modeling Methodology for Scientific Processes

Relational Algebra and SQL

Applying Constraint Logic Programming to SQL Test Case Generation

Query Processing in Data Integration Systems

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

A Modular Representation of a Business Process Planner

Data exchange. L. Libkin 1 Data Integration and Exchange

Relational Algebra 2. Chapter 5.2 V3.0. Napier University Dr Gordon Russell

Database Management Systems. Chapter 1

Translating SQL into the Relational Algebra

Certamen 1 de Representación del Conocimiento

On the Decidability and Complexity of Query Answering over Inconsistent and Incomplete Databases

Consistent Answers from Integrated Data Sources

Logical Foundations of Relational Data Exchange

CHAPTER 7 GENERAL PROOF SYSTEMS

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

P NP for the Reals with various Analytic Functions

Temporal Database System

Relational Division and SQL

Repair Checking in Inconsistent Databases: Algorithms and Complexity

Software Engineering

Databaser den relationelle model

The Relational Algebra

Introduction to tuple calculus Tore Risch

Relational Algebra and SQL Query Visualisation


Bounded Treewidth in Knowledge Representation and Reasoning 1

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out today start early! Relational Model Continued, and Schema Design and Normalization

An Effective and Efficient Inference Control System for Relational Database Queries

Functorial Data Migration. Categorical Informatics, Inc. December 1, C i

Object Oriented Databases (OODBs) Relational and OO data models. Advantages and Disadvantages of OO as compared with relational

SQL: Queries, Programming, Triggers

Introduction to Databases

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

On the Modeling and Verification of Security-Aware and Process-Aware Information Systems

Data Integration. Maurizio Lenzerini. Universitá di Roma La Sapienza

EECS 647: Introduction to Database Systems

From Causes for Database Queries to Repairs and Model-Based Diagnosis and Back

Databases 2011 The Relational Model and SQL

A Beginner s Guide to Modern Set Theory

Using Temporary Tables to Improve Performance for SQL Data Services

Consistent Query Answering in Databases Under Cardinality-Based Repair Semantics

! " # The Logic of Descriptions. Logics for Data and Knowledge Representation. Terminology. Overview. Three Basic Features. Some History on DLs

Propagating Functional Dependencies with Conditions

An Extension of the Relational Data Model to Incorporate Ordered Domains

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

Chapter One Introduction to Programming

Towards a Data Model for Quality Management Web Services: An Ontology of Measurement for Enterprise Modeling

Physical Design. Meeting the needs of the users is the gold standard against which we measure our success in creating a database.

Logic and Database Queries

Automatic Verification of Data-Centric Business Processes

Computational Methods for Database Repair by Signed Formulae

CSE 233. Database System Overview

A Reference Schema for LDAP-based Identity Management Systems

Algorithmic Software Verification

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

Advance DBMS. Structured Query Language (SQL)

CSE132A Solutions HW 1

Maintaining Stored Procedures in Database Application

Computational Logic and Cognitive Science: An Overview


COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

CSE 132A. Database Systems Principles

The Relational Model. Why Study the Relational Model?

Testing LTL Formula Translation into Büchi Automata

Program Transformation and Its Applications to Software Synthesis and Verification

Lecture 8: Resolution theorem-proving

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

Normalisation in the Presence of Lists

Core Components Data Type Catalogue Version October 2011

The composition of Mappings in a Nautural Interface

Number of hours in the semester L Ex. Lab. Projects SEMESTER I 1. Economy Philosophy Mathematical Analysis Exam

SQLMutation: A tool to generate mutants of SQL database queries

Instant SQL Programming

Semantic Enrichment of OLAP Cubes Multidimensional Ontologies and their Representation in SQL and OWL

4 Logical Design : RDM Schema Definition with SQL / DDL

Advanced Relational Database Design

Product: DQ Order Manager Release Notes

Model Driven Security: Foundations, Tools, and Practice

This asserts two sets are equal iff they have the same elements, that is, a set is determined by its elements.

Conceptual Data Model for a Central Patient Database

SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6


Integrating Pattern Mining in Relational Databases

How to Improve Database Connectivity With the Data Tools Platform. John Graham (Sybase Data Tooling) Brian Payton (IBM Information Management)

Transcription:

Foundations of Query Languages SS 2011 2. 2. Foundations of Query Languages Dr. Fang Wei Lehrstuhl für Datenbanken und Informationssysteme Universität Freiburg SS 2011 Dr. Fang Wei 22. Mai 2011 Seite 1

Relational Query Languages Formal languages with syntax and semantics. Syntax: algebraic or logical formalism or specific query language (SQL). Uses DB schema vocabulary. Semantics: M[Q] a mapping that transforms a database (instance) D into a database (instance) D = M[Q](D). We always disregard queries that are dependent on the particular representation of domain values. We thus restrict our attention to Generic queries: Queries that Produce isomorphic results on isomorphic databases. Dr. Fang Wei 22. Mai 2011 Seite 2

Expressive Power Expressive power of a query language L: E(L) = {M[Q] Q L} This way we can compare query languages, e.g.: if E(L) E(L ) then L is strictly more expressive than L. One often writes L = L instead of E(L) = E(L ). Dr. Fang Wei 22. Mai 2011 Seite 3

Relational Algebra σ Selection * π Projection * Cross product * Join ρ Rename * Difference * Union * Intersection *: Primitive operations, all others can be obtained from these. Dr. Fang Wei 22. Mai 2011 Seite 4

First-order Formulas (Relational Calculus) Quantifiers:, Boolean connectives,, Parentheses (, ) Atoms R(t 1,..., t n ) Dr. Fang Wei 22. Mai 2011 Seite 5

Example Schema Author (AID integer, name string, age integer) Paper (PID string, title string, yearinteger) Write (AID integer, PID integer) Instance {(h142, Knuth, 70), (h123, Ullman, 60),...} {(h181140pods, Query containment, 1998),...} {(h123, 181140pods), (h142, 193214algo),...} Dr. Fang Wei 22. Mai 2011 Seite 6

Example PID s of the papers that Knuth is NOT writing. π PID Paper π PID (Write σ name= Knuth Author) Rules: {PID title, year.paper(pid, title, year) age, AID.(Write(AID, PID) Author(AID, Knuth, age))} KnuthPapers(P) Write(A, P), Author(A, Knuth, age). NoKnuthPapers(P) Paper(P, T, Y ), KnuthPapers(P). Dr. Fang Wei 22. Mai 2011 Seite 7

Example PID s of the papers that Knuth is NOT writing. π PID Paper π PID (Write σ name= Knuth Author) Rules: {PID title, year.paper(pid, title, year) age, AID.(Write(AID, PID) Author(AID, Knuth, age))} KnuthPapers(P) Write(A, P), Author(A, Knuth, age). NoKnuthPapers(P) Paper(P, T, Y ), KnuthPapers(P). Dr. Fang Wei 22. Mai 2011 Seite 8

Example PID s of the papers that Knuth is NOT writing. π PID Paper π PID (Write σ name= Knuth Author) Rules: {PID title, year.paper(pid, title, year) age, AID.(Write(AID, PID) Author(AID, Knuth, age))} KnuthPapers(P) Write(A, P), Author(A, Knuth, age). NoKnuthPapers(P) Paper(P, T, Y ), KnuthPapers(P). Dr. Fang Wei 22. Mai 2011 Seite 9

Example PID s of the papers that Knuth is NOT writing. π PID Paper π PID (Write σ name= Knuth Author) Rules: {PID title, year.paper(pid, title, year) age, AID.(Write(AID, PID) Author(AID, Knuth, age))} KnuthPapers(P) Write(A, P), Author(A, Knuth, age). NoKnuthPapers(P) Paper(P, T, Y ), KnuthPapers(P). Dr. Fang Wei 22. Mai 2011 Seite 10

Example AID s of authors who wrote exactly one paper S2 = ρ Write (AID1, PID1) AID1=AID2,PID1 PID2 ρ Write (AID2, PID2) S = π AID Write π AID1 S2 {AID PID.(Write(AID, PID) PID2.(Write(AID, PID2) PID PID2))} Rules: MoreThanOne(A) Write(A, P1), Write(A, P2), P1 P2. OnlyOne(A) Write(A, P), MoreThanOne(A). Dr. Fang Wei 22. Mai 2011 Seite 11

Example AID s of authors who wrote exactly one paper S2 = ρ Write (AID1, PID1) AID1=AID2,PID1 PID2 ρ Write (AID2, PID2) S = π AID Write π AID1 S2 {AID PID.(Write(AID, PID) PID2.(Write(AID, PID2) PID PID2))} Rules: MoreThanOne(A) Write(A, P1), Write(A, P2), P1 P2. OnlyOne(A) Write(A, P), MoreThanOne(A). Dr. Fang Wei 22. Mai 2011 Seite 12

Example AID s of authors who wrote exactly one paper S2 = ρ Write (AID1, PID1) AID1=AID2,PID1 PID2 ρ Write (AID2, PID2) S = π AID Write π AID1 S2 {AID PID.(Write(AID, PID) PID2.(Write(AID, PID2) PID PID2))} Rules: MoreThanOne(A) Write(A, P1), Write(A, P2), P1 P2. OnlyOne(A) Write(A, P), MoreThanOne(A). Dr. Fang Wei 22. Mai 2011 Seite 13

Example AID s of authors who wrote exactly one paper S2 = ρ Write (AID1, PID1) AID1=AID2,PID1 PID2 ρ Write (AID2, PID2) S = π AID Write π AID1 S2 {AID PID.(Write(AID, PID) PID2.(Write(AID, PID2) PID PID2))} Rules: MoreThanOne(A) Write(A, P1), Write(A, P2), P1 P2. OnlyOne(A) Write(A, P), MoreThanOne(A). Dr. Fang Wei 22. Mai 2011 Seite 14

Example: True or False? Dr. Fang Wei 22. Mai 2011 Seite 15

Example: True or False? Dr. Fang Wei 22. Mai 2011 Seite 16

RA to FO R(A, B)S(C, D) σ A=3 R {(x, y) R(x, y) x = 3} rule: R (x, y) R(x, y), x = 3 π A R {x y.r(x, y)} R B R (x, y, z) R(x, y), S(y, z) union? difference? Dr. Fang Wei 22. Mai 2011 Seite 17

FO to RA S(x, y) z(r(x, y) (P(y, z) Q(z, x))) Dr. Fang Wei 22. Mai 2011 Seite 18

Unsafe FO Queries Sometimes FO queries can express queries which are unsafe. {x yr(x, y)} R = {(1, 1)}, dom= {1, 2}, x = R = {(1, 1)}, dom= {1}, x = {1} What query returns depends on the domain, not on the database! Dr. Fang Wei 22. Mai 2011 Seite 19

Unsafe FO Queries Another unsafe query. {x R(x)} R = {(1)}, dom= {1, 2}, x = {2} R = {(1)}, dom= {1}, x = What query returns depends on the domain, not on the database! Dr. Fang Wei 22. Mai 2011 Seite 20

Active Domain The active domain interpretation restricts quantified variables of the query to range over the active domain of the query and the input Given the database and the query, the domain is determined using the active domain semantics R = {(1, 1)} dom(r)={1, 2} adom = {1} not {1, 2}! x = {1} Dr. Fang Wei 22. Mai 2011 Seite 21

Active Domain The active domain interpretation is a viable solution. Under this interpretation, every query in FO is expressible in RA, and thus FO and RA have the same expressive Power: RA=FO (See AHV, Section 5). The same is true for safe, i.e., domain independent queries. But it is unfortunately undecidable whether a query is safe. (We will come back to this later) It is even true for a subset of the safe queries, the range restricted queries (see AHV) Dr. Fang Wei 22. Mai 2011 Seite 22