R-SQL: An SQL Database System with Extended Recursion



Similar documents
CSE 880. Advanced Database Systems. Active Database Design Issues

SQL Tables, Keys, Views, Indexes

Databases 2011 The Relational Model and SQL

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

A Brief Introduction to MySQL

What Is Recursion? Recursion. Binary search example postponed to end of lecture

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Relational Databases

Transaction Management Overview

SQL is capable in manipulating relational data SQL is not good for many other tasks

How To Create A Table In Sql (Ahem)

Oracle 10g PL/SQL Training

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

EECS 647: Introduction to Database Systems

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

IT2304: Database Systems 1 (DBS 1)

William E. Hart Carl Laird Jean-Paul Watson David L. Woodruff. Pyomo Optimization. Modeling in Python. ^ Springer

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Maintaining Stored Procedures in Database Application

Data exchange. L. Libkin 1 Data Integration and Exchange

CS 564: DATABASE MANAGEMENT SYSTEMS

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

SQL NULL s, Constraints, Triggers

SQL: Programming. Introduction to Databases CompSci 316 Fall 2014

Outline. SAS-seminar Proc SQL, the pass-through facility. What is SQL? What is a database? What is Proc SQL? What is SQL and what is a database

Data Structure [Question Bank]

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:

Database Systems. Lecture Handout 1. Dr Paolo Guagliardo. University of Edinburgh. 21 September 2015

IT2305 Database Systems I (Compulsory)

Programming in Python V: Accessing a Database

µz An Efficient Engine for Fixed points with Constraints

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

3. Relational Model and Relational Algebra

The Import & Export of Data from a Database

Chapter 13. Introduction to SQL Programming Techniques. Database Programming: Techniques and Issues. SQL Programming. Database applications

SQL injection: Not only AND 1=1. The OWASP Foundation. Bernardo Damele A. G. Penetration Tester Portcullis Computer Security Ltd

PostgreSQL Business Intelligence & Performance Simon Riggs CTO, 2ndQuadrant PostgreSQL Major Contributor

Programming Using Python

On a Hadoop-based Analytics Service System

Programming Database lectures for mathema

Advance DBMS. Structured Query Language (SQL)

Instant SQL Programming

In-Memory Database: Query Optimisation. S S Kausik ( ) Aamod Kore ( ) Mehul Goyal ( ) Nisheeth Lahoti ( )

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

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Programming Exercises

Schema Mappings and Data Exchange

Database Systems. Lecture 1: Introduction

Databases. DSIC. Academic Year

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

The Guru's Guide to Transact-SQL

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Big Data and Big Analytics

Logic in general. Inference rules and theorem proving

CSE 233. Database System Overview

ML for the Working Programmer

SQL Query Evaluation. Winter Lecture 23

N3458: Simple Database Integration in C++11

Shroudbase Technical Overview

Core Fittings C-Core and CD-Core Fittings

The Sins of SQL Programming that send the DB to Upgrade Purgatory Abel Macias. 1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

Cassandra. References:

5.1 Database Schema Schema Generation in SQL

Execution Strategies for SQL Subqueries

Cobol. By: Steven Conner. COBOL, COmmon Business Oriented Language, one of the. oldest programming languages, was designed in the last six

Database Design and Programming

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

CS346: Database Programming.

Knowledge Engineering for Business Rules in PROLOG

T Tutorial D - A Short Summary

In This Lecture. Security and Integrity. Database Security. DBMS Security Support. Privileges in SQL. Permissions and Privilege.

Normal Form vs. Non-First Normal Form

adaptive loading adaptive indexing dbtouch 3 Ideas for Big Data Exploration

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Extending Data Processing Capabilities of Relational Database Management Systems.

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

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

Translating WFS Query to SQL/XML Query

Databases in Engineering / Lab-1 (MS-Access/SQL)

Database Query 1: SQL Basics

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

Data Structures and Algorithms Written Examination

Introduction to IR Systems: Supporting Boolean Text Search. Information Retrieval. IR vs. DBMS. Chapter 27, Part A

Programming the SQL Way with Common Table Expressions

Part VI. Object-relational Data Models

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Darshan Institute of Engineering & Technology PL_SQL

Inside the PostgreSQL Query Optimizer

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

Geodatabase Programming with SQL

Query Processing C H A P T E R12. Practice Exercises

Python for Rookies. Example Examination Paper

MySQL Command Syntax

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Transcription:

R-SQL: An SQL Database System with Extended Recursion Gabriel Aranda-López, Susana Nieva, Fernando Saénz-Pérez and Jaime Sánchez-Hernández Universidad Complutense, Madrid XVIII Jornadas de Programación y Lenguajes Madrid, 20 de Septiembre, 2013

The Structured Query Language (SQL) SQL is a programming language designed for managing data in relational database management systems (DBMS) and it became an ANSI standard in 1986, and an ISO standard in 1987. It is widely considered a declarative language, but most of the DBMS include 4th generation languages. Since then, the standard has been enhanced several times with added features.

Limited Expression of Recursion of SQL Recursion was included in SQL-99 standard, but: Only linear recursion is allowed. Mutual recursion is not supported. Cycles in graphs makes SQL systems go into an infinite loop. In this work, we present R-SQL system to solve these limitations.

Plan of the talk Introduction. System Overview. Database definition. Syntax. Some examples. Fixpoint computation. Dependency Graph and Stratification. Python Code Generation An algorithm to compute the fixpoint. Integration into a DBMS. System Demostration

System Structure

Database Definition

R-SQL Syntax (I) Main Idea To define recursive relations as: R Sch := SELECT... FROM R1... R... Rn...

R-SQL Syntax (II) sql db ::= R sch := sel stm;... R sch := sel stm; sel stm ::= select exp,..,exp [from R,..,R [where c]] sel stm union sel stm sel stm except R sch ::= (A T,...,A T) exp ::= C R.A exp opm exp - exp c ::= true false exp opc exp not (c) c [ and or ] c

Example 1: Mutual Recursion Even/Odd Numbers in 0...100 even(x float) := SELECT 0 UNION SELECT odd.x+1 FROM odd WHERE odd.x<100; odd(x float) := SELECT even.x+1 FROM even WHERE even.x<100;

Example 2: Non-Linear Recursion Fibonacci Numbers fib1(n float, f float) := SELECT fib.n, fib.f FROM fib; fib2(n float, f float) := SELECT fib.n, fib.f FROM fib; fib(n float, f float) := SELECT 0,1 UNION SELECT 1,1 UNION SELECT fib1.n+1,fib1.f+fib2.f FROM fib1,fib2 WHERE fib1.n=fib2.n+1 AND fib1.n<10;

Example 3: Cycle in Graph arc(ori varchar(1), des varchar(1)) := SELECT a, b UNION SELECT b, c UNION SELECT c, a ; path(ori varchar(1), des varchar(1)) := SELECT arc.ori, arc.des FROM arc UNION SELECT arc.ori, path.des FROM arc,path WHERE arc.des=path.ori;

Fixpoint Computation

Stratified Fixpoint Semantics for R-SQL Analogously to Datalog: A depencency graph is defined using relation definitions. An except clause plays the role of negation. A stratification of the database relations is obtained from the dependency graph. The stratification is used to compute the least fixpoint interpretation, stratum by stratum.

System Structure

Example 3: Extended Graph arc(ori varchar(1), des varchar(1)) := SELECT a, b UNION SELECT b, c UNION SELECT c, a ; path(ori varchar(1), des varchar(1)) := SELECT arc.ori, arc.des FROM arc UNION SELECT arc.ori, path.des FROM arc,path WHERE arc.des=path.ori; bpath(ori varchar(10), des varchar(10)) := SELECT path.ori, path.des FROM path WHERE (path.ori = b OR path.des = b ); avoid_b(ori varchar(10), des varchar(10)) := SELECT path.ori, path.des FROM path EXCEPT bpath;

Dependency Graph and Stratification arc := select a, b union select b, c union select c, a ; path := select * from arc union select... from arc, path...; bpath := select path.ori, path.des from path where...; avoid b := select path.ori, path.des from path except bpath; Stratification [(arc, 1), (path, 1), (bpath, 1), (avoid_b, 2)]

System Structure

Interpretation of Select Statements Given an interpretation I: {R1,..., Rn} P(T ), we define the semantics of a sel stm in the context of I as: [[select exp 1,..., exp k ]] I = {(exp 1,..., exp k )}. [[select exp 1,..., exp k from R 1,..., R m where c]] I = {(exp 1 [a/a],..., exp k [a/a]) a I(R 1 )... I(R m ) and c[a/a] is satisfied}. [[sel stm 1 union sel stm 2 ]] I = [[sel stm 1 ]] I [[sel stm 2 ]] I. [[sel stm except R]] I = [[sel stm]] I \ I(R).

Example 1: Even/Odd Numbers Given I(even) = {(0), (2)} and I(odd)=. Semantics of odd in the context of I [[SELECT even.x+1 FROM even WHERE even.x<100]] I = {(even.x+1)[a/even.x] (a) I(even) and (even.x<100) [a/even.x]is satisfied} = {(1), (3)}.

Example 1: Even/Odd Numbers, Intended Semantics I(even) = {(0), (2),..., (100)} = [[SELECT 0 UNION SELECT odd.x+1 FROM odd WHERE x<100]] I I(odd) = {(1), (3),..., (99)} = [[SELECT even.x+1 FROM even WHERE even.x<100]] I

Fixpoint Interpretation We define an operator over the set of interpretations of stratum i. T i is successively applied to minimal interpretations to obtain the interpretation fixpoint. For a definition of the form R sch := sel stm, in stratum i: T i (I)(R) = [[sel stm]] I The database semantics is a fixpoint fix i = n 0 T n i (fix i 1 ) where i is the number of strata.

Example of the Computation of the Fixpoint T1 n( )(path) Added tuples at each iteration T1 1 ( )(path) {( a, b ), ( b, c ), ( c, a ) }, T1 2 ( )(path) {( a, c ), ( b, a ), ( c, b ) }, ( )(path) {( a, a ), ( b, b ), ( c, c ) }, T 3 1

Example of the Computation of the Fixpoint T1 n( )(path) Added tuples at each iteration T1 1 ( )(path) {( a, b ), ( b, c ), ( c, a ) }, T1 2 ( )(path) {( a, c ), ( b, a ), ( c, b ) }, ( )(path) {( a, a ), ( b, b ), ( c, c ) }, T 3 1 All these tuples are fix 1 ( )(path).

Example of the Computation of the Fixpoint T1 n( )(path) Added tuples at each iteration T1 1 ( )(path) {( a, b ), ( b, c ), ( c, a ) }, T1 2 ( )(path) {( a, c ), ( b, a ), ( c, b ) }, ( )(path) {( a, a ), ( b, b ), ( c, c ) }, T 3 1 All these tuples are fix 1 ( )(path). Similarly, we obtain tuples for arc y bpath to complete fix 1.

Example of the Computation of the Fixpoint T1 n( )(path) Added tuples at each iteration T1 1 ( )(path) {( a, b ), ( b, c ), ( c, a ) }, T1 2 ( )(path) {( a, c ), ( b, a ), ( c, b ) }, ( )(path) {( a, a ), ( b, b ), ( c, c ) }, T 3 1 All these tuples are fix 1 ( )(path). Similarly, we obtain tuples for arc y bpath to complete fix 1. Then, fix 2 (fix 1 )(avoid b) is computed to obtain fix 2, which is the database fixpoint.

Algorithm for Computing the Fixpoint str:=1 while str numstr do for each R i R str do create table R i sch i change := true while change do size := rel size sum(r str) for each R i R str do insert into R i select * from sel stm i except select * from R i ; change = (size rel size sum(r str)) end while str:=str+1 end while

System Structure

Example of Code Generation (I) 1 st stratum arc(ori varchar(1), des varchar(1)) := SELECT a, b UNION SELECT b, c UNION SELECT c, a ; path(ori varchar(1), des varchar(1)) := SELECT arc.ori, arc.des FROM arc UNION SELECT arc.ori, path.des FROM arc,path WHERE arc.des=path.ori; bpath(ori varchar(10), des varchar(10)) := SELECT path.ori, path.des FROM path WHERE (path.ori = b OR path.des = b ); 2 nd stratum avoid_b(ori varchar(1), des varchar(1)) := SELECT path.ori, path.des FROM path EXCEPT bpath;

Example of Code Generation (I) Python code produced by R-SQL for Stratum 2 cursor.execute("create table avoid_b (...);") ch = True while ch: size1=0 size2=0 ch=false cursor.execute("select * from avoid_b;") res=cursor.fetchall() size1= size1 + len(res) cursor.execute("insert into avoid_b (((select * from path) except (select * from bpath)) except (select * from avoid_b));") cursor.execute("select * from avoid_b;") res=cursor.fetchall() size2= size2 + len(res) ch = (size1!= size2)

System Structure

Integrating R-SQL into a DBMS Once a R-SQL database definition has been processed, the tables obtained are stored as a database instance of PostgreSQL and the user can: Formulate queries that will be solved using those tables. Define views that can be used in conjunction with other regular views that can either computed on demand or can be materialized.

Integrating R-SQL into a DBMS Once a R-SQL database definition has been processed, the tables obtained are stored as a database instance of PostgreSQL and the user can: Formulate queries that will be solved using those tables. Define views that can be used in conjunction with other regular views that can either computed on demand or can be materialized. But, the main goal of the proposal is to allow less-restricted recursive relation definitions in existing SQL engines.

System Demostration The implementation is available at: https://gpd.sip.ucm.es/trac/gpd/wiki/gpdsystems/rsql.

Thanks!