Optimization of Nested Queries in a Complex Object Model

Size: px
Start display at page:

Download "Optimization of Nested Queries in a Complex Object Model"

Transcription

1 Optimization of Nested Queries in a Complex Object Model Based on the papers: From Nested loops to Join Queries in OODB and Optimisation if Nested Queries in a Complex Object Model by Department of Computer Science, University of Twente 1

2 Overview: - Introduction - OOSQL and SQL - Translation of the queries into the ADL - Optimisation of the Nested Algebra Queries - Unnesting strategies - Conclusion 2

3 Introduction: It is advantageous to replace nested SQL queries by flat, or join queries. Flat SQL queries are SFW-blocks not containing subqueries in the WHERE clause. So the optimizer has better possibilities to choose the most appropriate join implementation. We distinguished five types of nesting and saw the algorithm to transform nested queries into join queries for each type. Still in case aggregate functions occur between query blocks (one of the types of nesting) SQL s GROUP BY clause is employed to compute the aggregates needed. But Kim s algorithm is not correct if the aggregate function COUNT occurs between query blocks (COUNT bug). 3

4 Introduction: SELECT * FROM R WHERE = SELECT COUNT (*) FROM S WHERE R.C = S.C Following Kim s algorithm, we get the following queries: 1. T(C,CNT) = SELECT S.C, COUNT (*) FROM S GROUP BY S.C Grouping of the inner operand and computation of the aggregate SELECT R.A, R.B, R.C precedesthe join operation FROM R.S WHERE R.B = T. CNT AND R.C = T.C Alternatively, if the R does not contain duplicates, the nested query may be transformed into: 2. SELECT R.A, R.B, R.C FROM R.S Join is executed first. WHERE R.C = S.C GROUP BY R.A, R.B, R.C HAVING R.B = COUNT (S.C) DO NOT GIVE THE CORRECT RESULT 4

5 Introduction: To solve the COUNT bug, it has been proposed to use 1. outerjoins instead of joins if COUNT function occurs. The right outerjoin operator preserves dangling tuples of the left join operand: unmatched left operand tuples are extended with NULL values in the right operand attribute positions. 2. two types of join predicates: - a regular join predicate and - an additional,so-called antijoin predicate, to be applied to the dangling tuples. 5

6 OOSQL and SQL An OOSQL query facility is inherently more complex than one for SQL: nesting is allowed in all clauses, SELECT, FROM, and WHERE. expressions in the FROM-clause may be base tables as well as setvalued attributes. predicates that are used in the WHERE-clause are more complex, because comparisons between set-valued attributes, or set-valued attributes and base table expressions are allowed. As in relational systems supporting SQL, in OO data models supporting an SQL-like query language (OOSQL), optimization of nested queries is an important issue. A naive way to handle nested queries is by nested-loop processing (tuple-oriented query processing), however, it is better to transform nested queries into join queries, because join queries can be implemented in many different ways. 6

7 Main Approach: Two approaches in the logical optimization of a declarative query language: (1) rewriting expressions in the query language itself (2) translation into and rewriting in some intermediate language, for example an algebraic language. The goal in translation and optimization of OOSQL is to move from tuple- to set-oriented query processing. Our approach is to translate nested OOSQL queries into nested algebraic expressions, and then to try to rewrite nested algebraic expressions into join expressions (algebraic language ADL). 7

8 The Complex Object Algebra ADL: ADL is a typed algebra for complex objects, allowing for nesting of expressions. Among the constructors supported are the tuple (( )) and set ({ }) type constructor; Roughly, the algebraic operators of the language ADL are: - the standard set (comparison) operators - extended Cartesian product(in which operand tuples are concatenated) - division, - map operator, - selection, - projection, - renaming operator, + aggregate functions sure - nest, - unnest, semantics is omitted because of the - regular join, lack of space - semijoin, - and the antijoin. 8

9 Translation of OOSQL into ADL: Translation of OOSQL queries into the algebra is done in a simple, almost one-to-one way. In the translation phase, nested OOSQL queries are translated into nested algebraic expressions. Following translation, in the phase of logical optimization, nested expressions are rewritten into set operations. In the translation phase, an SFW-query block is mapped to an algebraic expression consisting of a selection followed by a map: select e1 from x in e2 where e3 α[x : e1] (σ[x : e3](e2)) σ computes the selection e3 α projection e1 9

10 Optimization Of Nested Algebra Queries: The example queries given below concern the database which in ADL, have the types of SUPPLIER and PART defined as follows: SUPPLIER : { < eid : oid, sname : string, parts : { <pid : oid>}>} PART : {< pid : oid, pname : string, price : int, color : string>} We distinguish three ways of optimizing nested ADL queries: (1) the unnesting of attributes by using the unnest operator, (2) the unnesting of nested expressions by transforming them into relational join queries, (3) using new operators that are defined especially to enhance performance. 10

11 1. Unnesting Of Attributes Disadvantages: - nesting and unnesting are inverse to each other not for all relations - first unnesting and later nesting again will be expensive due to duplication of attribute values and overhead caused by restructuring. Query : Select the identifiers of suppliers supplying non-existing parts π sid( σ[s : z s.parts p PART z = p[pid]])(supplier)) The set-valued attribute parts is not needed in the result, so the above query may be rewritten into the antijoin query: ( (SUPPLIER )) > πsid µparts Note that because z is existentially quantified, the loss of tuples with empty set-valued attribute parts causes no problem (existential quantification over the empty set delivers false). PART s,p:s.pid=p.pid 11

12 2. Transformation into join queries In some cases two or more consecutive levels of nesting can be replaced by a join, antijoin, or semijoin operator, reducing the number of levels of nesting. In the ideal case all nesting has disappeared. Query: Select the suppliers supplying red parts. σ[ s : tz s.parts p PART z = p[pid]] p.color = "red"](supplier) This query can be rewritten into the semijoin query: SUPPLIER >< σ[p.color = "red"](part) s,p:p[pid] є s.parts Note that because z is existentially quantified, the loss of tuples with empty set-valued attribute parts causes no problem (existential quantification over the empty set delivers false). 12

13 3. Using Special Operators The following query cannot be rewritten into a relational join query. New operators is really necessary toobtain an efficient implementation. Query: Select suppliers names together with the parts supplied. α[s : < sname = s.name, parts_suppl = σ[p : p[pid] s.parts](part) > ](SUPPLIER) query can be rewritten into the efficient set operation with nestjoin query: πsname. parts _ sup pl (SUPPLIER Note that each of the options above can be applied to the top level expression as well as to subexpressions thereof. s,p:p[pid] є s.parts;parts_suppl PART) 13

14 Rewrite strategy 1. Try to rewrite to the various relational join operators (join, antijoin, or semijoin). 2. If the above is not possible, try to flatten set valued attributes; if the nesting phase can be skipped, this may be a strategy worthwhile considering. 3. If the above is not possible, try to rewrite to one of the newly defined operators, because they were introduced to get a better performance compared to nested-loop processing. 4. If none of the above works, leave the query as it is, which means that it is executed by means of nested loops. 14

15 Rewriting into flat relational algebra: nesting in the WHERE-clause in the presence of set-valued attributes. The general format of a two-block OOSQL query with nesting in the WHERE-clause The goal of the transformation is the following: process is to transform the predicate P(x,Y ), whose second argument is set valued, into a predicate P, where values v are the members of Y. The types of P and P clearly differ: SELECT F(x) from the second argument of P a set FROM x X, y Y constructor is removed, resulting in predicate P WHERE P (x, v)λq(x, v) WITH v = G(x, y) SELECT F(x) FROM x X WHERE P(x, Y ) WITH Y = SELECT G(x, y) FROM y Y WHERE Q(x, v) 15

16 Rewriting into flat relational algebra: General formatof SFW Guery : α[x : F(x)](σ[x : P(x,Y )](X)) with Y = α[y : G(x,y)](σ[y : Q(x,y)](Y)), for simplisity F and G identity Then we have: σ[x : P(x,Y )](X) with Y = σ[y : Q(x,y)](Y) The query above is a nested query involving nested iteration over a base table: the outer selection predicate contains a subquery, which is a selection on base table Y. We want to transform this nested query into a join query, i.e. a query having no subqueries with base table operands. 16

17 Set Comparison Operations We concentrate on two-block nested expressions with set comparison operations between query blocks. Two unnesting techniques: - unnesting by rewriting into quantifier expressions, - unnesting by grouping,a technique well-known from the relational model however, to be of good use in complex models, they have to be adapted. We will do so by defining a new algebraic operator, the nestjoin operator. 17

18 Unnesting By Rewriting Into Quantifier Expressions 1 Rewriting Example 1: SET MEMBERSHIP σ[x : x.c є σ [y : q](y)](x) σ[x : y є σ [y : q](y) y = x.c](x) σ[x : y є Y y = x.cλq](x) X x x,y:y=x.c Λq Y E E - operator є is rewritten into an existential quantification. - select operation is removed from the operand (the range expression) of the existential quantifier, providing the possibility to translate the existential subquery into a semijoin operation In the last rewrite step. Rule 1 UNNESTING QUANTIFIER EXPRESSIONS Le t X and Y be table expressions, and let x not be free in Y, then: 1. σ[x : y є Y p](x) X x x,y:p Y 2. σ[x : y є Y p](x) X x,y:p Y E E A nested query with existential quantification is translated into a semijoin operation; negated existential (i.e.universal) quantification is dealt with by means of the antijoin operator. 18

19 Unnesting By Rewriting Into Quantifier Expressions 2 Rewriting Example 1: SET INCLUSION All set comparison operators can be rewritten into quantifier expressions, 19

20 Unnesting By Grouping Another way to deal with set comparison operators is to use grouping. Used in transforming nested queries with aggregate functions between query blocks. Consider the following nested query, 20 in Database Query Processing Universität Konstanz, 2005

21 Unnesting By Grouping The nested query is transformed into a flat join query consisting of (1) a join to evaluate the inner query block predicate, (2) a nest operation for grouping, (3) a selection for evaluating P, the predicate between blocks, (4) a final projection. 21

22 Nesting In The Map Operator Another example of the strategy of rewriting nested expressions into relational join expressions, but now concerning nesting in the map operator (i.e. in the SELECT-clause). The following equivalence rule can be used to transform a nested map operation into a join query:. Unnesting by grouping is a transformation technique that is generally applicable, if not for the occurrence of bugs. In the next section, we show how to avoid the occurrence of bugs by using the nestjoin operator. 22

23 New Algebraic Operators It is worthwhile to define new logical algebra operators whenever there can be found new access algorithms that are an improvement over nested-loop query processing. The Nestjoin Operator Materializing Set-Valued Attributes The PNHL Algorithm 23

24 The Nestjoin Operator The nestjoin operator is to be used for the unnesting of nested queries that cannot be rewritten into flat relational join operations. The nestjoin operator as defined above can be used for the transformation of two-block select expressions with arbitrary predicates between blocks. The simplified version of the two-block select query: 24

25 The Nest Join operator Is simply a modification of the join operator. Instead of producing the concatenation of every pair of matching tuples, for each left operand tuple a set is created to hold the (possibly modified) right operand tuples that match. The nest join of two tables X and Y on predicate Q with function G (the function applied to the right-hand tuples satisfying the join predicate) is defined as: In this expression, x++ <a=z> denotes the concatenation of the tuple x and the unary tuple <a=z>, in which a is an arbitrary label not occurring on the top level of X. An example of the nest join operation is found in Table 1, where flat relations X and Y are equijoined on the second attribute (the join function is the identity function). Note that or dangling tuples, the tuple x++<a=0> is present in the result. 25

26 The Nest Join operator 26

27 The PNHL Algorithm algorithm of for efficiently processing a nested expression in which a setvalued attribute is joined with a base table. The following query expresses a nested natural join (*) operation: The algorithm builds a hash table for those segments of operand PART that fit into main memory and then probes operand SUPPLIER against each segment of the hash table, thus building partial results. Partial results are merged in the second phase of the algorithm. Compared to the unnest-join-nest processing method, the algorithm achieves better performance. 27

28 Conclusion: In OOSQL, nesting may occur in the where-, from-, and selectclause. An additional complication in complex object models is the support for iteration over set-valued attributes. The goal is to transform nested OOSQL queries having correlated subqueries with base table expressions as operands into join queries in which base tables occur only at top level. We have shown that transformation of nested OOSQL queries dealing with set-valued attributes into relational join queries is not always possible To improve matters we have defined a new operator called the nestjoin operator. 28

29 Processing a General Nested Query: 6 Thank you for the attention!!! 29

execution. In this paper, we deal with the problem of trying to translate nested OOSQL queries to join queries in ADL, taking advantage of ecient impl

execution. In this paper, we deal with the problem of trying to translate nested OOSQL queries to join queries in ADL, taking advantage of ecient impl From Nested-Loop to Join Queries in OODB Hennie J. Steenhagen Peter M.G. Apers Henk M. Blanken Rolf A. de By Department of Computer Science, University of Twente PO Box 217, 7500 AE Enschede, The Netherlands

More information

Relational Databases

Relational Databases Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 49 Plan of the course 1 Relational databases 2 Relational database design 3 Conceptual database design 4

More information

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and Chapter 6 The Relational Algebra and Relational Calculus Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Outline Unary Relational Operations: SELECT and PROJECT Relational

More information

Plan for today. Query Processing/Optimization. Parsing. A query s trip through the DBMS. Validation. Logical plan

Plan for today. Query Processing/Optimization. Parsing. A query s trip through the DBMS. Validation. Logical plan Plan for today Query Processing/Optimization CPS 216 Advanced Database Systems Overview of query processing Query execution Query plan enumeration Query rewrite heuristics Query rewrite in DB2 2 A query

More information

Relational Algebra and SQL

Relational Algebra and SQL Relational Algebra and SQL Relational Algebra. This algebra is an important form of query language for the relational model. The operators of the relational algebra: divided into the following classes:

More information

Relational Model, Relational Algebra, and SQL

Relational Model, Relational Algebra, and SQL Relational Model, Relational Algebra, and SQL August 29, 2007 1 Relational Model Data model. constraints. Set of conceptual tools for describing of data, data semantics, data relationships, and data integrity

More information

CS122 Lecture 4 Winter Term,

CS122 Lecture 4 Winter Term, CS122 Lecture 4 Winter Term, 2014-2015 2 SQL Query Transla.on Last time, introduced query evaluation pipeline SQL query SQL parser abstract syntax tree SQL translator relational algebra plan query plan

More information

CSE 344 JANUARY 26 TH DATALOG

CSE 344 JANUARY 26 TH DATALOG CSE 344 JANUARY 26 TH DATALOG ADMINISTRATIVE MINUTIAE HW3 and OQ3 out HW3 due next Friday OQ3 due next Wednesday HW4 out next week: on Datalog Midterm reminder: Feb 9 th RELATIONAL ALGEBRA Set-at-a-time

More information

The query processor turns user queries and data modification commands into a query plan - a sequence of operations (or algorithm) on the database

The query processor turns user queries and data modification commands into a query plan - a sequence of operations (or algorithm) on the database query processing Query Processing The query processor turns user queries and data modification commands into a query plan - a sequence of operations (or algorithm) on the database from high level queries

More information

Introduction to Database Systems CSE 444

Introduction to Database Systems CSE 444 Introduction to Database Systems CSE 444 Lecture 18: Query Processing Overview CSE 444 - Summer 2010 1 Where We Are We are learning how a DBMS executes a query How come a DBMS can execute a query so fast?

More information

CSE 344 JANUARY 19 TH SUBQUERIES 2 AND RELATIONAL ALGEBRA

CSE 344 JANUARY 19 TH SUBQUERIES 2 AND RELATIONAL ALGEBRA CSE 344 JANUARY 19 TH SUBQUERIES 2 AND RELATIONAL ALGEBRA ASSORTED MINUTIAE Winter storm Inga Online quiz out after class Still due Wednesday, will be shorter but through today s lecture For SQLite submissions,

More information

Lecture Query evaluation. Combining operators. Logical query optimization. By Marina Barsky Winter 2016, University of Toronto

Lecture Query evaluation. Combining operators. Logical query optimization. By Marina Barsky Winter 2016, University of Toronto Lecture 02.03. Query evaluation Combining operators. Logical query optimization By Marina Barsky Winter 2016, University of Toronto Quick recap: Relational Algebra Operators Core operators: Selection σ

More information

Lecture 17: Query execution. Wednesday, May 12, 2010

Lecture 17: Query execution. Wednesday, May 12, 2010 Lecture 17: Query execution Wednesday, May 12, 2010 1 Outline of Next Few Lectures Query execution Query optimization 2 Steps of the Query Processor SQL query Parse & Rewrite Query Query optimization Select

More information

Announcements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table

Announcements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table Announcements (September 14) 2 SQL: Part I Books should have arrived by now Homework #1 due next Tuesday Project milestone #1 due in 4 weeks CPS 116 Introduction to Database Systems SQL 3 Creating and

More information

Database Systems CSE 414

Database Systems CSE 414 Database Systems CSE 414 Lecture 6: Nested Queries in SQL 1 Announcements WQ2 is due on Sunday 11pm no late days HW2 is due on Tuesday 11pm 2 Lecture Goals Today we will learn how to write (even) more

More information

Relational Model: History

Relational Model: History Relational Model: History Objectives of Relational Model: 1. Promote high degree of data independence 2. Eliminate redundancy, consistency, etc. problems 3. Enable proliferation of non-procedural DML s

More information

Algebraic XQuery Decorrelation with Order Sensitive Operations

Algebraic XQuery Decorrelation with Order Sensitive Operations Worcester Polytechnic Institute Digital WPI Computer Science Faculty Publications Department of Computer Science 2-2005 Algebraic XQuery Decorrelation with Order Sensitive Operations Song Wang Worcester

More information

Query Processing SL03

Query Processing SL03 Distributed Database Systems Fall 2016 Query Processing Overview Query Processing SL03 Distributed Query Processing Steps Query Decomposition Data Localization Query Processing Overview/1 Query processing:

More information

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls Today s topics CompSci 516 Data Intensive Computing Systems Lecture 4 Relational Algebra and Relational Calculus Instructor: Sudeepa Roy Finish NULLs and Views in SQL from Lecture 3 Relational Algebra

More information

Missing Information. We ve assumed every tuple has a value for every attribute. But sometimes information is missing. Two common scenarios:

Missing Information. We ve assumed every tuple has a value for every attribute. But sometimes information is missing. Two common scenarios: NULL values Missing Information We ve assumed every tuple has a value for every attribute. But sometimes information is missing. Two common scenarios: Missing value. E.g., we know a student has some email

More information

CMP-3440 Database Systems

CMP-3440 Database Systems CMP-3440 Database Systems Relational DB Languages Relational Algebra, Calculus, SQL Lecture 05 zain 1 Introduction Relational algebra & relational calculus are formal languages associated with the relational

More information

Optimized Query Plan Algorithm for the Nested Query

Optimized Query Plan Algorithm for the Nested Query Optimized Query Plan Algorithm for the Nested Query Chittaranjan Pradhan School of Computer Engineering, KIIT University, Bhubaneswar, India Sushree Sangita Jena School of Computer Engineering, KIIT University,

More information

EECS 647: Introduction to Database Systems

EECS 647: Introduction to Database Systems EECS 647: Introduction to Database Systems Instructor: Luke Huan Spring 2009 External Sorting Today s Topic Implementing the join operation 4/8/2009 Luke Huan Univ. of Kansas 2 Review DBMS Architecture

More information

Announcements. Subqueries. Lecture Goals. 1. Subqueries in SELECT. Database Systems CSE 414. HW1 is due today 11pm. WQ1 is due tomorrow 11pm

Announcements. Subqueries. Lecture Goals. 1. Subqueries in SELECT. Database Systems CSE 414. HW1 is due today 11pm. WQ1 is due tomorrow 11pm Announcements Database Systems CSE 414 Lecture 6: Nested Queries in SQL HW1 is due today 11pm WQ1 is due tomorrow 11pm no late days WQ3 is posted and due on Oct. 19, 11pm 1 2 Lecture Goals Today we will

More information

Agenda. Discussion. Database/Relation/Tuple. Schema. Instance. CSE 444: Database Internals. Review Relational Model

Agenda. Discussion. Database/Relation/Tuple. Schema. Instance. CSE 444: Database Internals. Review Relational Model Agenda CSE 444: Database Internals Review Relational Model Lecture 2 Review of the Relational Model Review Queries (will skip most slides) Relational Algebra SQL Review translation SQL à RA Needed for

More information

More on SQL Nested Queries Aggregate operators and Nulls

More on SQL Nested Queries Aggregate operators and Nulls Today s Lecture More on SQL Nested Queries Aggregate operators and Nulls Winter 2003 R ecom m en ded R eadi n g s Chapter 5 Section 5.4-5.6 http://philip.greenspun.com/sql/ Simple queries, more complex

More information

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 7 - Query execution

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 7 - Query execution CSE 544 Principles of Database Management Systems Magdalena Balazinska Fall 2007 Lecture 7 - Query execution References Generalized Search Trees for Database Systems. J. M. Hellerstein, J. F. Naughton

More information

Announcements. Agenda. Database/Relation/Tuple. Discussion. Schema. CSE 444: Database Internals. Room change: Lab 1 part 1 is due on Monday

Announcements. Agenda. Database/Relation/Tuple. Discussion. Schema. CSE 444: Database Internals. Room change: Lab 1 part 1 is due on Monday Announcements CSE 444: Database Internals Lecture 2 Review of the Relational Model Room change: Gowen (GWN) 301 on Monday, Friday Fisheries (FSH) 102 on Wednesday Lab 1 part 1 is due on Monday HW1 is due

More information

L22: The Relational Model (continued) CS3200 Database design (sp18 s2) 4/5/2018

L22: The Relational Model (continued) CS3200 Database design (sp18 s2)   4/5/2018 L22: The Relational Model (continued) CS3200 Database design (sp18 s2) https://course.ccs.neu.edu/cs3200sp18s2/ 4/5/2018 256 Announcements! Please pick up your exam if you have not yet HW6 will include

More information

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity COSC 416 NoSQL Databases Relational Model (Review) Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was proposed by E. F. Codd

More information

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 16th January 2014 Time: 09:45-11:45. Please answer BOTH Questions

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 16th January 2014 Time: 09:45-11:45. Please answer BOTH Questions Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE Advanced Database Management Systems Date: Thursday 16th January 2014 Time: 09:45-11:45 Please answer BOTH Questions This is a CLOSED book

More information

Database System Concepts

Database System Concepts Chapter 14: Optimization Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and Sudarshan.

More information

The Extended Algebra. Duplicate Elimination. Sorting. Example: Duplicate Elimination

The Extended Algebra. Duplicate Elimination. Sorting. Example: Duplicate Elimination The Extended Algebra Duplicate Elimination 2 δ = eliminate duplicates from bags. τ = sort tuples. γ = grouping and aggregation. Outerjoin : avoids dangling tuples = tuples that do not join with anything.

More information

CSE 344 APRIL 20 TH RDBMS INTERNALS

CSE 344 APRIL 20 TH RDBMS INTERNALS CSE 344 APRIL 20 TH RDBMS INTERNALS ADMINISTRIVIA OQ5 Out Datalog Due next Wednesday HW4 Due next Wednesday Written portion (.pdf) Coding portion (one.dl file) TODAY Back to RDBMS Query plans and DBMS

More information

CSE344 Midterm Exam Fall 2016

CSE344 Midterm Exam Fall 2016 CSE344 Midterm Exam Fall 2016 November 7, 2016 Please read all instructions (including these) carefully. This is a closed book exam. You are allowed a one page handwritten cheat sheet. Write your name

More information

CIS 330: Applied Database Systems

CIS 330: Applied Database Systems 1 CIS 330: Applied Database Systems Lecture 7: SQL Johannes Gehrke johannes@cs.cornell.edu http://www.cs.cornell.edu/johannes Logistics Office hours role call: Mondays, 3-4pm Tuesdays, 4:30-5:30 Wednesdays,

More information

A Nested Relational Approach to Processing SQL Subqueries

A Nested Relational Approach to Processing SQL Subqueries A Nested Relational Approach to Processing SQL Subqueries Bin Cao bin.cao@louisville.edu Antonio Badia abadia@louisville.edu Computer Engineering and Computer Science Department University of Louisville

More information

SQL: Data Manipulation Language. csc343, Introduction to Databases Diane Horton Winter 2017

SQL: Data Manipulation Language. csc343, Introduction to Databases Diane Horton Winter 2017 SQL: Data Manipulation Language csc343, Introduction to Databases Diane Horton Winter 2017 Introduction So far, we have defined database schemas and queries mathematically. SQL is a formal language for

More information

Introduction SQL DRL. Parts of SQL. SQL: Structured Query Language Previous name was SEQUEL Standardized query language for relational DBMS:

Introduction SQL DRL. Parts of SQL. SQL: Structured Query Language Previous name was SEQUEL Standardized query language for relational DBMS: Introduction SQL: Structured Query Language Previous name was SEQUEL Standardized query language for relational DBMS: SQL The standard is evolving over time SQL-89 SQL-9 SQL-99 SQL-0 SQL is a declarative

More information

SQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji. Winter 2018

SQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji. Winter 2018 SQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji Winter 2018 Introduction So far, we have defined database schemas and queries mathematically. SQL is a

More information

Database Design and Tuning

Database Design and Tuning Database Design and Tuning Chapter 20 Comp 521 Files and Databases Spring 2010 1 Overview After ER design, schema refinement, and the definition of views, we have the conceptual and external schemas for

More information

Contents Contents Introduction Basic Steps in Query Processing Introduction Transformation of Relational Expressions...

Contents Contents Introduction Basic Steps in Query Processing Introduction Transformation of Relational Expressions... Contents Contents...283 Introduction...283 Basic Steps in Query Processing...284 Introduction...285 Transformation of Relational Expressions...287 Equivalence Rules...289 Transformation Example: Pushing

More information

4. SQL - the Relational Database Language Standard 4.3 Data Manipulation Language (DML)

4. SQL - the Relational Database Language Standard 4.3 Data Manipulation Language (DML) Since in the result relation each group is represented by exactly one tuple, in the select clause only aggregate functions can appear, or attributes that are used for grouping, i.e., that are also used

More information

4/10/2018. Relational Algebra (RA) 1. Selection (σ) 2. Projection (Π) Note that RA Operators are Compositional! 3.

4/10/2018. Relational Algebra (RA) 1. Selection (σ) 2. Projection (Π) Note that RA Operators are Compositional! 3. Lecture 33: The Relational Model 2 Professor Xiannong Meng Spring 2018 Lecture and activity contents are based on what Prof Chris Ré of Stanford used in his CS 145 in the fall 2016 term with permission

More information

Chapter 14: Query Optimization

Chapter 14: Query Optimization Chapter 14: Query Optimization Database System Concepts 5 th Ed. See www.db-book.com for conditions on re-use Chapter 14: Query Optimization Introduction Transformation of Relational Expressions Catalog

More information

2. Make an input file for Query Execution Steps for each Q1 and RQ respectively-- one step per line for simplicity.

2. Make an input file for Query Execution Steps for each Q1 and RQ respectively-- one step per line for simplicity. General Suggestion/Guide on Program (This is only for suggestion. You can change your own design as needed and you can assume your own for simplicity as long as it is reasonable to make it as assumption.)

More information

SQL Data Querying and Views

SQL Data Querying and Views Course A7B36DBS: Database Systems Lecture 04: SQL Data Querying and Views Martin Svoboda Faculty of Electrical Engineering, Czech Technical University in Prague Outline SQL Data manipulation SELECT queries

More information

Parser: SQL parse tree

Parser: SQL parse tree Jinze Liu Parser: SQL parse tree Good old lex & yacc Detect and reject syntax errors Validator: parse tree logical plan Detect and reject semantic errors Nonexistent tables/views/columns? Insufficient

More information

Chapter 5. Relational Algebra and Relational Calculus

Chapter 5. Relational Algebra and Relational Calculus Chapter 5 Relational Algebra and Relational Calculus Overview The previous chapter covers the relational model, which provides a formal description of the structure of a database This chapter covers the

More information

CSE 544 Principles of Database Management Systems

CSE 544 Principles of Database Management Systems CSE 544 Principles of Database Management Systems Alvin Cheung Fall 2015 Lecture 6 Lifecycle of a Query Plan 1 Announcements HW1 is due Thursday Projects proposals are due on Wednesday Office hour canceled

More information

Advanced Database Systems

Advanced Database Systems Lecture IV Query Processing Kyumars Sheykh Esmaili Basic Steps in Query Processing 2 Query Optimization Many equivalent execution plans Choosing the best one Based on Heuristics, Cost Will be discussed

More information

Chapter 19 Query Optimization

Chapter 19 Query Optimization Chapter 19 Query Optimization It is an activity conducted by the query optimizer to select the best available strategy for executing the query. 1. Query Trees and Heuristics for Query Optimization - Apply

More information

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions. COSC 304 Introduction to Database Systems Relational Model and Algebra Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was

More information

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2006 Lecture 3 - Relational Model

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2006 Lecture 3 - Relational Model CSE 544 Principles of Database Management Systems Magdalena Balazinska Fall 2006 Lecture 3 - Relational Model References E.F. Codd. A relational model of data for large shared data banks. Communications

More information

CS122 Lecture 5 Winter Term,

CS122 Lecture 5 Winter Term, CS122 Lecture 5 Winter Term, 2017-2018 2 Last Time: SQL Join Expressions Last time, began discussing SQL join syntax Original SQL form: SELECT FROM t1, t2, WHERE P Any join conditions are specified in

More information

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation!

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation! Chapter 3: Formal Relational Query Languages CS425 Fall 2013 Boris Glavic Chapter 3: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational Calculus Textbook:

More information

Introduction. 1. Introduction. Overview Query Processing Overview Query Optimization Overview Query Execution 3 / 591

Introduction. 1. Introduction. Overview Query Processing Overview Query Optimization Overview Query Execution 3 / 591 1. Introduction Overview Query Processing Overview Query Optimization Overview Query Execution 3 / 591 Query Processing Reason for Query Optimization query languages like SQL are declarative query specifies

More information

Introduction Alternative ways of evaluating a given query using

Introduction Alternative ways of evaluating a given query using Query Optimization Introduction Catalog Information for Cost Estimation Estimation of Statistics Transformation of Relational Expressions Dynamic Programming for Choosing Evaluation Plans Introduction

More information

Fighting Redundancy in SQL: the For-Loop Approach

Fighting Redundancy in SQL: the For-Loop Approach Fighting Redundancy in SQL: the For-Loop Approach Antonio Badia and Dev Anand Computer Engineering and Computer Science department University of Louisville, Louisville KY 40292 July 8, 2004 1 Introduction

More information

Lyublena Antova, Christoph Koch, and Dan Olteanu Saarland University Database Group Saarbr ucken, Germany Presented By: Rana Daud

Lyublena Antova, Christoph Koch, and Dan Olteanu Saarland University Database Group Saarbr ucken, Germany Presented By: Rana Daud Lyublena Antova, Christoph Koch, and Dan Olteanu Saarland University Database Group Saarbr ucken, Germany 2007 1 Presented By: Rana Daud Introduction Application Scenarios I-SQL World-Set Algebra Algebraic

More information

CMPUT 391 Database Management Systems. An Overview of Query Processing. Textbook: Chapter 11 (first edition: Chapter 14)

CMPUT 391 Database Management Systems. An Overview of Query Processing. Textbook: Chapter 11 (first edition: Chapter 14) CMPUT 391 Database Management Systems Winter Semester 2006, Section B1, Dr. Jörg Sander An Overview of Query Processing Textbook: Chapter 11 (first edition: Chapter 14) Based on slides by Lewis, Bernstein

More information

Polls on Piazza. Open for 2 days Outline today: Next time: "witnesses" (traditionally students find this topic the most difficult)

Polls on Piazza. Open for 2 days Outline today: Next time: witnesses (traditionally students find this topic the most difficult) L04: SQL 124 Announcements! Polls on Piazza. Open for 2 days Outline today: - practicing more joins and specifying key and FK constraints - nested queries Next time: "witnesses" (traditionally students

More information

CSC 261/461 Database Systems Lecture 19

CSC 261/461 Database Systems Lecture 19 CSC 261/461 Database Systems Lecture 19 Fall 2017 Announcements CIRC: CIRC is down!!! MongoDB and Spark (mini) projects are at stake. L Project 1 Milestone 4 is out Due date: Last date of class We will

More information

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

More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

More information

SQL QUERY EVALUATION. CS121: Relational Databases Fall 2017 Lecture 12

SQL QUERY EVALUATION. CS121: Relational Databases Fall 2017 Lecture 12 SQL QUERY EVALUATION CS121: Relational Databases Fall 2017 Lecture 12 Query Evaluation 2 Last time: Began looking at database implementation details How data is stored and accessed by the database Using

More information

CS317 File and Database Systems

CS317 File and Database Systems CS317 File and Database Systems Lecture 3 Relational Calculus and Algebra Part-2 September 10, 2017 Sam Siewert RDBMS Fundamental Theory http://dilbert.com/strips/comic/2008-05-07/ Relational Algebra and

More information

Querying Data with Transact SQL

Querying Data with Transact SQL Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including

More information

Database Tuning and Physical Design: Basics of Query Execution

Database Tuning and Physical Design: Basics of Query Execution Database Tuning and Physical Design: Basics of Query Execution Spring 2018 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Query Execution 1 / 43 The Client/Server

More information

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe Introduction to Query Processing and Query Optimization Techniques Outline Translating SQL Queries into Relational Algebra Algorithms for External Sorting Algorithms for SELECT and JOIN Operations Algorithms

More information

SQL: Data Querying. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 4

SQL: Data Querying. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 4 B0B36DBS, BD6B36DBS: Database Systems h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 4 SQL: Data Querying Mar n Svoboda mar n.svoboda@fel.cvut.cz 20. 3. 2018 Czech Technical University

More information

SQL: Queries, Programming, Triggers

SQL: Queries, Programming, Triggers SQL: Queries, Programming, Triggers CSC343 Introduction to Databases - A. Vaisman 1 Example Instances We will use these instances of the Sailors and Reserves relations in our examples. If the key for the

More information

CS 377 Database Systems

CS 377 Database Systems CS 377 Database Systems Relational Algebra and Calculus Li Xiong Department of Mathematics and Computer Science Emory University 1 ER Diagram of Company Database 2 3 4 5 Relational Algebra and Relational

More information

Announcements. Agenda. Database/Relation/Tuple. Schema. Discussion. CSE 444: Database Internals

Announcements. Agenda. Database/Relation/Tuple. Schema. Discussion. CSE 444: Database Internals Announcements CSE 444: Database Internals Lecture 2 Review of the Relational Model Lab 1 part 1 is due on Friday Lab 1 is due next week on Friday git commit a and git push often! HW1 is due on Wednesday,

More information

CPS 216 Spring 2003 Homework #1 Assigned: Wednesday, January 22 Due: Monday, February 10

CPS 216 Spring 2003 Homework #1 Assigned: Wednesday, January 22 Due: Monday, February 10 CPS 216 Spring 2003 Homework #1 Assigned: Wednesday, January 22 Due: Monday, February 10 Note: This is a long homework. Start early! If you have already taken CPS 196.3 or an equivalent undergraduate course

More information

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query

More information

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

More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries

More information

CSE 544 Principles of Database Management Systems

CSE 544 Principles of Database Management Systems CSE 544 Principles of Database Management Systems Alvin Cheung Fall 2015 Lecture 2 SQL and Schema Normalization 1 Announcements Paper review First paper review is due on Wednesday 10:30am Details on website

More information

The Relational Algebra

The Relational Algebra The Relational Algebra Relational Algebra Relational algebra is the basic set of operations for the relational model These operations enable a user to specify basic retrieval requests (or queries) 27-Jan-14

More information

Chapter 6: Formal Relational Query Languages

Chapter 6: Formal Relational Query Languages Chapter 6: Formal Relational Query Languages Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational

More information

CSC 261/461 Database Systems Lecture 13. Fall 2017

CSC 261/461 Database Systems Lecture 13. Fall 2017 CSC 261/461 Database Systems Lecture 13 Fall 2017 Announcement Start learning HTML, CSS, JavaScript, PHP + SQL We will cover the basics next week https://www.w3schools.com/php/php_mysql_intro.asp Project

More information

Ian Kenny. November 28, 2017

Ian Kenny. November 28, 2017 Ian Kenny November 28, 2017 Introductory Databases Relational Algebra Introduction In this lecture we will cover Relational Algebra. Relational Algebra is the foundation upon which SQL is built and is

More information

What happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques

What happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques 376a. Database Design Dept. of Computer Science Vassar College http://www.cs.vassar.edu/~cs376 Class 16 Query optimization What happens Database is given a query Query is scanned - scanner creates a list

More information

Project. Building a Simple Query Optimizer with Performance Evaluation Experiment on Query Rewrite Optimization

Project. Building a Simple Query Optimizer with Performance Evaluation Experiment on Query Rewrite Optimization Project CIS611 SS Chung Building a Simple Query Optimizer with Performance Evaluation Experiment on Query Rewrite Optimization This project is to simulate a simple Query Optimizer that: 1. Evaluates query

More information

QUERY OPTIMIZATION FOR DATABASE MANAGEMENT SYSTEM BY APPLYING DYNAMIC PROGRAMMING ALGORITHM

QUERY OPTIMIZATION FOR DATABASE MANAGEMENT SYSTEM BY APPLYING DYNAMIC PROGRAMMING ALGORITHM QUERY OPTIMIZATION FOR DATABASE MANAGEMENT SYSTEM BY APPLYING DYNAMIC PROGRAMMING ALGORITHM Wisnu Adityo NIM 13506029 Information Technology Department Institut Teknologi Bandung Jalan Ganesha 10 e-mail:

More information

Avoiding Sorting and Grouping In Processing Queries

Avoiding Sorting and Grouping In Processing Queries Avoiding Sorting and Grouping In Processing Queries Outline Motivation Simple Example Order Properties Grouping followed by ordering Order Property Optimization Performance Results Conclusion Motivation

More information

Query processing. Query analysis logical query plan Query transformation Physical plan generation and optimization Query execution

Query processing. Query analysis logical query plan Query transformation Physical plan generation and optimization Query execution Architecture Query processing Understanding query processing helps producing better applications SQL is a declarative language: it describes the query result, but not how to get it. Query processing: Query

More information

The SQL data-definition language (DDL) allows defining :

The SQL data-definition language (DDL) allows defining : Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries

More information

CSE 344 MAY 7 TH EXAM REVIEW

CSE 344 MAY 7 TH EXAM REVIEW CSE 344 MAY 7 TH EXAM REVIEW EXAMINATION STATIONS Exam Wednesday 9:30-10:20 One sheet of notes, front and back Practice solutions out after class Good luck! EXAM LENGTH Production v. Verification Practice

More information

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1) Chapter 19 Algorithms for Query Processing and Optimization 0. Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution strategy for processing a query. Two

More information

CSE 344 Midterm Nov 1st, 2017, 1:30-2:20

CSE 344 Midterm Nov 1st, 2017, 1:30-2:20 1 SQL 1. (36 points) Acompanymaintainsadatabaseabouttheiremployeesandprojectswiththefollowing schema. Employee(eid, name, salary) Project(pid, title, budget) WorksOn(eid, pid, year) WorksOn records which

More information

Chapter 14 Query Optimization

Chapter 14 Query Optimization Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming

More information

Chapter 14 Query Optimization

Chapter 14 Query Optimization Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming

More information

Chapter 14 Query Optimization

Chapter 14 Query Optimization Chapter 14: Query Optimization Chapter 14 Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Non è possibile visualizzare l'immagine. Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns)

More information

CMPS 277 Principles of Database Systems. Lecture #4

CMPS 277 Principles of Database Systems.  Lecture #4 CMPS 277 Principles of Database Systems http://www.soe.classes.edu/cmps277/winter10 Lecture #4 1 First-Order Logic Question: What is First-Order Logic? Answer: Informally, First-Order Logic = Propositional

More information

Midterm Review. Winter Lecture 13

Midterm Review. Winter Lecture 13 Midterm Review Winter 2006-2007 Lecture 13 Midterm Overview 3 hours, single sitting Topics: Relational model relations, keys, relational algebra expressions SQL DDL commands CREATE TABLE, CREATE VIEW Specifying

More information

Query Processing & Optimization

Query Processing & Optimization Query Processing & Optimization 1 Roadmap of This Lecture Overview of query processing Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions Introduction

More information

SQL relations are multisets (bags) of tuples (i.e., they can contain duplicates)

SQL relations are multisets (bags) of tuples (i.e., they can contain duplicates) 3.2 SQL SQL: Structured (Standard) Query Language Literature: A Guide to the SQL Standard, 3rd Edition, C.J. Date and H. Darwen, Addison-Wesley 1993 History: about 1974 as SEQUEL (IBM System R, INGRES@Univ.

More information

Administrivia. Physical Database Design. Review: Optimization Strategies. Review: Query Optimization. Review: Database Design

Administrivia. Physical Database Design. Review: Optimization Strategies. Review: Query Optimization. Review: Database Design Administrivia Physical Database Design R&G Chapter 16 Lecture 26 Homework 5 available Due Monday, December 8 Assignment has more details since first release Large data files now available No class Thursday,

More information

Chapter 4: SQL. Basic Structure

Chapter 4: SQL. Basic Structure Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL

More information