0% found this document useful (0 votes)
2 views

14. DB - Lecture Query Optimization

The document discusses query processing and optimization in database management systems, focusing on transforming high-level queries into low-level execution strategies. It outlines the major phases of query processing, including parsing, optimization, and execution, as well as techniques for optimizing queries to minimize resource usage. Additionally, it covers selection and join strategies, the importance of statistics in query optimization, and the use of both cost-based and rule-based optimization algorithms.

Uploaded by

i233052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

14. DB - Lecture Query Optimization

The document discusses query processing and optimization in database management systems, focusing on transforming high-level queries into low-level execution strategies. It outlines the major phases of query processing, including parsing, optimization, and execution, as well as techniques for optimizing queries to minimize resource usage. Additionally, it covers selection and join strategies, the importance of statistics in query optimization, and the use of both cost-based and rule-based optimization algorithms.

Uploaded by

i233052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

Query Processing and

Optimization

1
Objectives

• Introduction
• Major Phases in Query Processing
• Optimizing Queries

2
Introduction

• With declarative languages such as SQL, the user


specifies what data is required rather than how it
is retrieved

• Relieves user of knowing what constitutes a good


execution strategy

• Also gives the DBMS more control over system


performance.

3
Query Processing
• It is a procedure of transforming high-level query
(SQL) into low level language.
• Parsing and Translation
• Optimization
• Evaluation

Query:
select salary from Employee where
salary>10000;

Relational Algebra:
σsalary>10000 (πsalary (Employee))
πsalary (σsalary>10000 (Employee))
4
Indexes and Query
Optimization

5
Processing a High-Level
Query
Query in high level language

Scanning, parsing And Validating

Intermediate form of query

Query Optimizer

Execution plan

Query code Generator

Code to execute the query

Run time DB Processor

Query result
6
Processing a High-Level
Query
• The scanner identifies the query tokens—such as SQL
keywords, attribute names, and relation names—that
appear in the text of the query, whereas the
• parser checks the query syntax to determine whether it
is formulated according to the syntax rules (rules of
grammar) of the query language. The query must also be
• validated by checking that all attribute and relation
names are valid and semantically meaningful names in
the schema of the particular database being
• queried.
7
Processing a High-Level
Query
• An internal representation of the query is then
created, usually as a tree data structure called a
query tree.
• It is also possible to represent the query using a
graph data structure called a query graph, which is
generally a directed acyclic graph (DAG).
• The DBMS must then devise an execution strategy or
query plan for retrieving the results of the query from
the database files.
• A query has many possible execution strategies, and
the process
8
Major Phases in Query
Processing
• Scan, Parse, and Validate Query: Transform query written in
high level language (e g. SQL), into correct efficient execution
strategy expressed in low-level language (e. g. Relational
Algebra)

• Optimize query and generate code: produce an execution


strategy or plan and run-time code.

• Execute query: Implement the plan to retrieve required data.

9
Example: Translating SQL Queries into
Relational Algebra
SELECT LNAME, FNAME
FROM EMPLOYEE
WHERE SALARY > ( SELECT MAX (SALARY)
FROM EMPLOYEE
WHERE DNO = 5);

SELECT LNAME, FNAME SELECT MAX (SALARY)


FROM EMPLOYEE FROM EMPLOYEE
WHERE SALARY > C WHERE DNO = 5

10
Example: Translating SQL Queries into
Relational Algebra
SELECT LNAME, FNAME
FROM EMPLOYEE
WHERE SALARY > ( SELECT MAX (SALARY)
FROM EMPLOYEE
WHERE DNO = 5);

SELECT LNAME, FNAME SELECT MAX (SALARY)


FROM EMPLOYEE FROM EMPLOYEE
WHERE SALARY > C WHERE DNO = 5

πLNAME, FNAME (σSALARY>C(EMPLOYEE)) ℱMAX SALARY (σDNO=5 (EMPLOYEE))

11
Optimizing Queries
• The process of choosing a suitable execution strategy for
processing a query
• As there are many equivalent transformations from same high-
level query, aim is to choose the one that minimizes resource
usage
• Generally, an efficient execution plan reduces the total execution
time of a query; thereby reducing the response time of a query
• The problem is computationally intractable with large number of
relations, so the strategy adopted is reduced to finding a near
optimum solution
• Two main techniques for query optimization are:
• Heuristic rules that order operations in a query
• Comparing different strategies based on relative cost, and
selecting one that minimizes resource usage. 12
Steps in Query
Optimization
• Process for heuristics optimization
1. The parser of a high-level query generates an initial
internal representation;
2. Apply heuristics rules to optimize the internal
representation.
3. A query execution plan is generated to execute groups
of operations based on the access paths available on
the files involved in the query.

• The main heuristic is to apply first the operations that


reduce the size of intermediate results.
• E.g., Apply SELECT and PROJECT operations before
applying the JOIN or other binary operations. 13
Library Database
Schema
book
call_numbe copy_numbe accession_numb title
r r er
book_author
call_number author

checked_out
call_numbe copy_numbe borrower_i date_du
r r d e
borrower
borrower_i name
d

14
Example Query

• Find the titles of all books written by


"Bruce Schneier"

• SELECT title
FROM book NATURAL JOIN
book_author WHERE author = "Bruce
Schneier"
• Many possible execution plans. For
example:
A. πtitle (σ author = ‘Bruce Schneier’
(Book ⋈ BookAuthor))

B. πtitle (Book ⋈ (σ author = ‘Bruce 15


Evaluating Execution Plans

• Compare:
A. πtitle (σ author = ‘Bruce Schneier’ (Book ⋈

BookAuthor))

B. πtitle (Book ⋈ (σ author = ‘Bruce Schneier’


BookAuthor))

• Relevant information:
• How many records are in each table?
• What indexes do we have?
• How many books did Bruce Schneier write?

16
Evaluating Execution Plans
• Compare:
A. πtitle (σauthor = ‘Bruce Schneier’ (Book ⋈ BookAuthor))
B. πtitle (Book ⋈ (σauthor = ‘Bruce Schneier’ BookAuthor))
• Suppose:
• BookAuthor has 20K tuples
• Book has 10K tuples (an average of two authors per book)
• Only 2 BookAuthor tuples contain “Bruce Schneier”
• Relevant indexes exist

• What’s the performance difference?


A. Processes all 10K book tuples and 20K bookAuthor
tuples to create a temporary relation with 20K tuples.
Processes at least 50K tuples.
B. Uses indexes to locate 2 BookAuthor tuples
and 2 corresponding book tuples. Processes
just 4 tuples!
17
Outline

• Selection Strategies

• Join Strategies

• Join Size Estimation


• Rules of Equivalence

18
Selection Strategies
• How to perform selection (σ)?

• Linear search is always an option


• Full table scan
• Potentially requires accessing every disk block
in the table

• Alternatively, use an index


• Binary search, tree search, or hash table lookup
• Indexes themselves require disk accesses,
but it's usually worth it
• Indexes may be partly or entirely stored in
memory
19
Join Strategies

• Joins are most expensive part of query


processing
•Number of tuples examined can approach
the product of the number of records in
tables being joined
• Example
• σ Borrower.name =
BookAuthor.authorBorrower × BookAuthor
•Where BookAuthor has 10K tuples and
Borrower has 2K tuples
•Cartesian join yields 20 million tuples to 20
Order of Joins
• For multiple joins, performance can be greatly
impacted by the order of the joins
• Example: π last, first, authorName Borrower ⋈ BookAuthor ⋈
CheckedOut
• Assume:
• 2K Borrower, 1K CheckedOut, and 10K Author tuples
• Each book has an average of 2 authors

A. ( Borrower ⋈ BookAuthor ) ⋈ CheckedOut


• Three ways to do the join operations:

B. ( BookAuthor ⋈ CheckedOut ) ⋈ Borrower


C. ( Borrower ⋈ CheckedOut ) ⋈ BookAuthor
• Final number of tuples is the same, but intermediate
joins create temporary tables. Which order is most
efficient? 21
Order of Joins
• Assume:
• 2K Borrower, 1K CheckedOut, and 10K Author tuples
• Each book has an average of 2 authors

• Three ways to do the (binary commutative) join

A. ( Borrower ⋈ BookAuthor ) ⋈ CheckedOut


operations:

B. ( BookAuthor ⋈ CheckedOut ) ⋈ Borrower


C. ( Borrower ⋈ CheckedOut ) ⋈ BookAuthor

• Example:
A. Borrower and BookAuthor have no attributes in
common, so a cartesian product is formed. This
results in a temporary table with 20 million tuples!
22
Statistics and
Query
Optimization
• Using statistics about database objects can
help speed up queries

• Maintaining statistics as the data in the


database changes is a manageable
process
• Types of statistics
• Table statistics
• Column statistics
23
Table Statistics

• On a relation r:
• nr = number of tuples in the relation
• lr = size (in bytes) of a tuple in the relation
• fr = blocking factor, number of tuples per block
• br = number of blocks used by the relation

• Thus:
• fr = floor( block size / lr ) if tuples do not span
blocks
• br = ceiling( nr / fr ) if tuples in r reside in a
single file and are not clustered with other
relations 24
Table Statistics

Block 1 Block 2 Block 3


Tuple 1 Tuple 2 Tuple 3 Tuple 4 Tuple 5 Tuple 6

• The relation contains 6 tuples (n r =6)

• Each tuple occupies 200 bytes (l r =200)

• Each block holds 2 tuples (fr=2)

• The relation occupies 3 blocks


(br=3)
25
Example Statistics
book_author borrower
call_number author borrower_i name
d
checked_out
call_numbe copy_numbe borrower_i date_du
r r d e

Table nr lr V( A , r )
borrower 2000 58 bytes V( borrower_id, Borrower ) =
checked_ou 1000 74 bytes 2000
t V( borrower_id, CheckedOut ) =
book_autho 10,000 100 100
r bytes V( callNo, CheckedOut ) = 500
V( callNo, BookAuthor ) = 5000
26
Calculating the Size
of a Cartesian
Product
• Cartesian product: r × s
• Number of tuples in join: nr × s = nr * ns
• Size of each tuple in join: lr × s = lr + ls

• Example: borrower × checked_out


•nborrower × checked_out
•lborrower × checked_out

27
Estimating the Size of a
Join
• Natural join: r ⋈ s, where r and s have A in common
• Estimated number of tuples in join:
nr ⋈ s = ns * nr / max( V(A, r), V(A, s) )
• Number of unique values: V(A, r ⋈ s) = min( V(A, r),
V(A, s) )
• Some tuples in the relation with the larger number of
column values do not join with any tuples in the other
relation

• If r and s have no attributes in common, then a


cartesian product is performed

28
Example Join Estimation
• π name, author Borrower ⋈ BookAuthor ⋈ CheckedOut

• Which evaluation plan generates the fewest


tuples in the intermediate table?
A. ( Borrower ⋈ BookAuthor ) ⋈ CheckedOut
B. ( BookAuthor ⋈ CheckedOut ) ⋈ Borrower
C. ( Borrower ⋈ CheckedOut ) ⋈ BookAuthor

29
Rules of Equivalence
• Reordering the joins improved performance,
without changing the results!
• More generally, two formulations of a
query are "equivalent" if they produce the
same set of results
• Tuples aren't necessarily in the same order

• The "rules of equivalence" describe when


reordering is allowed
• For a given query, a good DBMS will
create several "equivalent" evaluation plans
and choose the most efficient one
30
Rules of Equivalence
• Example: find the titles of all books
written by "Bruce Schneier"

• SELECT title
FROM book NATURAL JOIN
book_author WHERE author = "Bruce
Schneier"
• "Equivalent" execution plans:

A. πtitle (σauthor = ‘Bruce Schneier’ (Book ⋈


BookAuthor))

B. πtitle (Book ⋈ (σauthor = ‘Bruce Schneier’ 31


Math Review

• Commutativity:
• A binary operation * is commutative if for all 𝑥, 𝑦:
𝑥∗𝑦=𝑦∗𝑥

• Associativity
• A binary operation * is associative if for all 𝑥, 𝑦, 𝑧:
𝑥∗𝑦 ∗ 𝑧 = 𝑥 ∗𝑦 ∗ 𝑧

32
Rules of Equivalence

33
Rules of Equivalence

34
Rules of Equivalence

35
Rules of Equivalence

36
Push Selections Inward
• Do selections as early as possible
• Reduces (“flattens”) the number of records in the
relation(s) being joined
• Example:
• πtitle (σauthor = ‘Bruce Schneier’ (Book ⋈ BookAuthor))
• πtitle (Book ⋈ (σauthor = ‘Bruce Schneier’ BookAuthor))
• Sometimes this is not feasible:
• σ Borrower.name = BookAuthor.author Borrower × BookAuthor

37
Push Projections Inward

• Do projections as early as possible


• Reduces (“narrows”) the number of columns in the
relation(s) being joined

• Example:
•π name, title, dateDue Borrower ⋈ CheckedOut ⋈ Book

•π name, title, dateDue Borrower ⋈


(π borrowerID, title, dateDue CheckedOut ⋈ Book )
• Reduces the number of columns in the temporary
table from the intermediate join

38
Optimization Algorithm
Statistically based query optimization/Cost-based Optimizer: Uses sophisticated
algorithms based on statistics about the objects being accessed to determine the
best approach to execute a query. In this case, the optimizer process adds up the
processing cost, the I/O costs, and the resource costs (RAM and temporary space)
to determine the total cost of a given execution plan

A rule-based optimizer uses preset rules and points to determine the best
approach to execute a query. The rules assign a “fixed cost” to each SQL
operation; the costs are then added to yield the cost of the execution plan. For
example, a full table scan has a set cost of 10, while a table access by row ID
has a set cost of 3

39
Example
Consider the query

Select balance
From account
Where balance <2500;

This query can be translated into either of the following relational algebra
expressions:

• σ balance<2500 (∏ balance (account)


• ∏ balance (σ balance<2500 (account))

 The query which takes less CPU time, CPU cycles or disk access
will have less cost and will be executed.

40
SQL Query & Relation Algebr
Expression
SQL Query
SELECT ENAME
FROM EMPLOYEE, WORKSON, PROJECT
WHERE PNAME = 'database' AND PNUM = PNO AND ENO = ENUM
AND BDATE > '1965';

Relation Algebra Expression

π_ENAME (σ_PNAME='database' AND PNUM=PNO AND ENO=ENUM


AND BDATE>'1965' (EMPLOYEE ⨝ WORKSON ⨝ PROJECT))

41
Query Trees
• A tree data structure that corresponds to a relational algebra
expression.
• It represents the input relations of the query as leaf nodes of
the tree, and represents the relational algebra operations as
internal nodes.
• An execution of the query tree consists of executing an internal node
operation whenever its operands are available and then replacing
that internal node by the relation that results from executing the
operation.
• The order of execution of operations starts at the leaf nodes, which
represents the input database relations for the query, and ends at
the root node, which represents the final operation of the query. The
execution terminates when the root node operation is executed and
produces the result relation for the query.
42
Query Tree Example

43
Example 1
Select NAME From Student Where Major = ‘ICS’

Relation Algebra Expression

πNAME (σMajor = ‘ICS’ (Student)

44
Example 2
SELECT DeptName From Student, Department Where Code
= ‘Major’ AND year = 4
Relation Algebra Expression

π_DeptName (σ (Code =Major AND year=4 (Student ⨝


Department)))

45
Example 3 – Query Tree
Relation Algebra Expression: πp(R ⋈ R.P = S.P S)

46
Example 4 – Query Tree
πPnumber, Dnum, Lname, Address, Bdate(((σPlocation =
‘Stanford’(PROJECT)) ⋈ Dnum=Dnumber(DEPARTMENT)) ⋈
Mgr_ssn=Ssn(EMPLOYEE))

47
Example 4 – Query Tree (Cont
πPnumber, Dnum, Lname, Address, Bdate(((σPlocation =
‘Stanford’(PROJECT)) ⋈ Dnum=Dnumber(DEPARTMENT)) ⋈
Mgr_ssn=Ssn(EMPLOYEE))

48
Example 4 – Query Tree (Cont
πPnumber, Dnum, Lname, Address, Bdate(((σPlocation =
‘Stanford’(PROJECT)) ⋈ Dnum=Dnumber(DEPARTMENT)) ⋈
Mgr_ssn=Ssn(EMPLOYEE))

49
Example 4 – Query Tree (Cont
πPnumber, Dnum, Lname, Address, Bdate(((σPlocation =
‘Stanford’(PROJECT)) ⋈ Dnum=Dnumber(DEPARTMENT)) ⋈
Mgr_ssn=Ssn(EMPLOYEE))

50
Consider The Following Table
Instructor (ID, Name, Dept_name, Salary)
Teaches (ID, Course_ID, Sec_ID, Semester, Year)
Course (Course_ID, Title, Dept_name, Credits)

Query 1: Find the names of all instructors in the Music department,


along with the titles of the courses that they teach

How to Optimize it

Performing the selection early reduces the size of relation to be joined

51
Query Trees
∏(name, title)

σ(Dept_name = “Music”)



Instructor

Teaches ∏(Course_id, Title)

Course

52
Query Tree(Optimized)

∏(name, title)



σ(Dept_name = “Music”)

Instructor Teaches ∏(Course_id, Title)

Course

53
Example
Query 2: Find the names of all instructors in the CSE department who
have taught a course in 2009, along with the titles of the courses that
they taught

How to Optimize it

Performing the selection early reduces the size of relation to be joined

54
Query Tree of Example 2

σ(Dept_name = “CSE”)

σ (year = 2009)


Instructor Teaches

Databases: Query Proc. & Opt. 55


Query Tree of Example 2


σ (Dept_name = σ (year = 2009)
‘CSE’)

Instructor Teaches

Databases: Query Proc. & Opt. 56


Sample Query
• Example: “ What are the titles and years of movies
made by Fox that are at least 100 minutes long”

57
58
59
Query graph:

• A graph data structure that corresponds to a relational


calculus expression.
• It does not indicate an order on which operations to
perform first.
• There is only a single graph corresponding to each query.

60
Query Tree Example
• For every project located in ‘ISB’, list the project number, the
controlling department number and the department
manager’s last name, address, and birth date.
SELECT Pnumber, Dnum, Lname, Address,
Bdate
FROM Project, Department, Employee
WHERE Dnum=Dnumber
AND MgrSSN = SSN
AND Plocation = ‘ISB’

61
Query Tree: Example
∏P.Pnumber, P.Dnum, E.Lname, E.Address, E.Bdate

θD.MGRSSN=E.SSN

θP.Dnum=D.Dnumber E

σP.Location=‘ISB’
D

P
Note: The symbol θ represents JOIN

62
… --- Query Tree: Example
∏P.Pnumber, P.Dnum, E.Lname, E.Address, E.Bdate

σP.Dnum=D.Dnumber AND D.MGRSSN=E.SSN AND P.Location=‘ISB’

X E

D
P

63
--- Query Graph Example

• For every project located in ‘ISB’, list the project
number, the controlling department number, and
the department manager’s last name, address, and
birth date.
SELECT Pnumber, Dnum, Lname,
Address, Bdate
FROM Project, Department, Employee
WHERE Dnum = Dnumber
AND MgrSSN = SSN
AND Plocation = ‘ISB’
64
… --- Query Graph
Example
[P.Pnumber, P.Dum] [E.lname,E.aAddress, E.Bdate]

P.Dum=D.Numbr D.MgrSSN=E.SSN
P D E

P.Plocation = ‘ISB’

‘Stafford’

65
- Relational Algebra
Transformation
• The following list gives a basic selection of relational
algebra transformation:
• Cascade of selection: Conjunctive selection
operations can cascade into individual selection
operations
 p AND q AND r (R) = p (q (r (R)))
• Cascade of projection: In a sequence of projection
operations, only the last in sequence is required.
L(M(…(N(R) =  L(R)

66
- Relational Algebra
Transformation
• The following list gives a basic selection of relational
algebra transformation:
• Commutatively of selection: A sequence of selection
operations are commutative
q(p(R)) = p(q(R))
• Associativity of Natural Join and Cross Product:
Natural join (*) and Cross Product (X) are associative:
(R * S) * T = R * (S * T)
(R X S) X T = R X (S X T)

67
- Relational Algebra
Transformation
• The following list gives a basic selection of relational algebra
transformation:
• Cascade of selection: Conjunctive selection operations can cascade into
individual selection operations
 p AND q AND r (R) = p (q (r (R)))
• Cascade of projection: In a sequence of projection operations, only the last in
sequence is required.
L(M(…(N(R) =  L(R)
• Commutatively of selection: A sequence of selection operations are
commutative
q(p(R)) = p(q(R))
• Associativity of Natural Join and Cross Product: Natural join (*) and Cross
Product (X) are associative:
(R * S) * T = R * (S * T)
(R X S) X T = R X (S X T)

68
Heuristic Optimization-
Further Details
• Perform selection operations as early as possible
• Keep predicates on same relation together
• Combine Cartesian product with subsequent selection whose
predicate represents join condition into a join operation.
• Use associative of binary operations to rearrange leaf nodes with
most restrictive selection operations first.
• Perform projection as early as possible
• Keep projection attributes on same relations together.
• Compute common expressions once.
• If common expression appears more than once, and result not too large,
store result and reuse it when required.
• Useful when querying views, as same expression is used to construct
view each time.

69
Given an SQL Query, Let we Translate it
into its Relational Algebra Expression
R(A,B) S(B,C) T(C,D)
Π 𝐴,𝐷
SELECT R.A,T.D sA<10
FROM R,S,T
WHERE R.B = S.B
AND S.C = T.C
AND R.A < 10; T(C,D)

R(A,B) S(B,C)
Π 𝐴 , 𝐷 (𝜎 𝐴<10 ( 𝑇 ⋈ ( 𝑅 ⋈ 𝑆 ) ) )

Can we Optimize this Query Execution Plan ?

70
Optimizing RA Plan
R(A,B) S(B,C) T(C,D) Push down selection
on A so it occurs
SELECT R.A,T.D earlier
FROM R,S,T
WHERE R.B = S.B Π 𝐴,𝐷
AND S.C = T.C sA<10

AND R.A < 10;


T(C,D)

R(A,B) S(B,C)
Π 𝐴 , 𝐷 (𝜎 𝐴<10 ( 𝑇 ⋈ ( 𝑅 ⋈ 𝑆 ) ) )

71
Optimizing RA Plan
(cont…)
R(A,B) S(B,C) T(C,D)

SELECT R.A,T.D Push down


FROM R,S,T selection on
A so it occurs
WHERE R.B = S.B earlier Π 𝐴,𝐷
AND S.C = T.C
AND R.A < 10;
T(C,D)

sA<10
S(B,C)
Π 𝐴 , 𝐷 ( 𝑇 ⋈ ( 𝜎 𝐴< 10( 𝑅)⋈ 𝑆 ) )
R(A,B)

72
Optimizing RA Plan
(cont…)
R(A,B) S(B,C) T(C,D)

SELECT R.A,T.D Push down


FROM R,S,T projection so
it occurs
WHERE R.B = S.B earlier Π 𝐴,𝐷
AND S.C = T.C
AND R.A < 10;
T(C,D)

sA<10
S(B,C)
Π 𝐴 , 𝐷 ( 𝑇 ⋈ ( 𝜎 𝐴< 10( 𝑅)⋈ 𝑆 ) )
R(A,B)

73
Optimizing RA Plan
(cont…)
R(A,B) S(B,C) T(C,D)

SELECT R.A,T.D We eliminate


FROM R,S,T B earlier!
WHERE R.B = S.B Π 𝐴,𝐷
AND S.C = T.C
AND R.A < 10;
Π 𝐴 ,𝐶 T(C,D)

Π 𝐴 , 𝐷 ( 𝑇 ⋈ Π 𝐴, 𝑐 ( 𝜎 𝐴<10 (𝑅)⋈ 𝑆 ) ) sA<10


S(B,C)
R(A,B)

74
-- Query Optimization:
Example …
• Query: Find the last name of employees born after
1975 who work on a project named ‘Aquarius’

SELECT Lname
FROM Employee, Works_on, Project
WHERE Pname = ‘Aquarius’
AND ESSN = SSN
AND Pnumber = PNO
AND Bdate > ‘1975-12-31’

75
… -- Query Optimization: Example …
∏Lname

σPname=‘Aquirius’ AND P.Number=PNO AND ESSN=SSN AND Bdate=‘Dec-31-19

Initial Canonical
Query Tree X Project

Employee Works_On

76
… -- Query Optimization: Example …
∏Lname

Moving SELECT down σPnumber=PNO

Χ
σESSN=SSN σPname=‘Aquarius’

X Project

σBDate>‘1957-12-13’
Works_On

Employee
77
… -- Query Optimization: Example …
∏Lname

σESSN=SSN
Apply more restrictive SELECT

Χ
σPnumber=PNO σBDate>‘1957-12-13’

X Employee

σPname=‘Aquirius’
Works_On

Project

78
… -- Query Optimization: Example …

∏Lname
Replace CARTESIAN PRDUCT
And SELECT with JOIN θESSN=SSN

σBDate>‘1957-12-13’
θPnumber=Pno

σPname=‘Aquirius’
Employee
Works_On

Project

79
… -- Query Optimization: Example

∏Lname
Move PROJECTION down
θESSN=SSN

∏ESSN ∏SSN,Lname

θPnumber=Pno σBDate>‘1957-12-13’

∏Pnumber ∏ESSN,PNO
Employee
σPname=‘Aquirius’
Works_On

Project

80

You might also like