SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler offline
Query Processing and Query Optimization
DATED: 11-03-2016
1
Introduction
Data base
User Query
2
DBMS
Result
Query
processor
Query
Optimizer
Other
Subprograms
 Modern database management systems (DBMS) are complex programs that:
 get user queries,
 translate them in internal representation necessary for data accesss, and
 produce meaningful result efficiently (that is the results which take less
execution time and consume less resources)
Query Processing
3
Introduction (Cont.)
SELECT *
FROM TABLE-1, TABLE-2
WHERE TABLE-1 . ID = TABLE-2 . ID
σTABLE-1 . ID = TABLE-2 . ID (TABLE-1 X TABLE-2)
Relational
algebra
generator
Query parser
(Syntax and
semantic
analyzer)
 Query processor gets a user
query in structured query
language (SQL), checks
query for syntax and semantic
errors, and generates its
equivalent expression in
relational algebra necessary for
data access.
Query Processor
Estimate
alternate
plan Estimate
alternate
plan
Data base
Query
Alternate query plan 1 Alternate query plan 2 Alternate query plan n. . .
Choose best plan among them
4
Q . P
 The process of generating various execution plans for user query and finding
a best plan that takes less execution time and consumes less resources.
Query Optimizer
Introduction (Cont.)
Query Optimization
Query processor
5
 Generation of various execution plans and finding a better plan is
done by query optimization techniques (algorithms) implemented
in the query optimizer.
 OPTIMIZATION TECHNIQUES
 Simple execution plan
 Eliminating Cartesian product with joins
 Performing selection before join (Push selection)
 Performing projection before join (Push projections)
.
.
.
Introduction (Cont.)
Query Optimization
6
 name
 Students.id = Enrolled.id / Enrolled.grade=‘B’
Students Enrolled
Introduction (Cont.)
Query Optimization
 SIMPLE QUERY EXECUTION PLAN: Query processor generates an equivalent
relational algebraic expression and forward it to the query optimizer. Usually, that
expression involves Cartesian product.
Example: Return names of students who earned grade ‘B’
x
id name age
E1 Ahmed 15
E2 Farhan 14
id reg_nr grade
E2 AB29 B
E4 AB30 D
Students
Enrolled
 name ( Enrolled. grade = ‘B’ / Students.id = Enrolled.id ) Student x Enrolled
7
 name
 Students.id = Enrolled.id / Enrolled.grade=‘B’
Students Enrolled
Introduction (Cont.)
 ELIMINATION OF CARTESIAN WITH JOIN: Cartesian product may be
replaced with joins.
Example:  name ( Enrolled. grade = ‘B’ / Students.id = Enrolled.id ) Student x Enrolled
x
Query Optimization
 name
 Enrolled.grade=‘B’
Students Enrolled
Students.id = Enrolled.id⋈
8
 name
Students.id= Enrolled.id /
Enrolled.grade=‘B’
Students Enrolled
Introduction (Cont.)
 PERFORMING SELECTION BEFORE JOIN (PUSH SELECTION):
By pushing selection operator down makes them executes as early as possible
x
Query Optimization
 name
 Enrolled.grade=‘B’
Students Enrolled
Students.id = Enrolled.id
Students.id = Enrolled.id
 name
Enrolled.grade=‘B’Students
Enrolled
Example:  name ( Enrolled. grade = ‘B’ / Students.id = Enrolled.id ) Student x Enrolled
⋈
⋈
Query: Return names of students who earned grade ‘B’
9
Students Enrolled
id Name
11 Ali
22 Ahmed
33 Saima
id C.no Grade
11 CS20 A
22 CS21 B
33 CS22 B
 Name (Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled)
SELECT Name
FROM Students , Enrolled
WHERE Students.id= Enrolled.id
AND Enrolled . Grade=‘B’
Results
Query: Return names of students who earned grade ‘B’
SELECT Name
FROM Students , Enrolled
WHERE Students.id= Enrolled.id
AND Enrolled . Grade=‘B’
10
Students Enrolled
id Name
11 Ali
22 Ahmed
33 Saima
id C.no Grade
11 CS20 A
22 CS21 B
33 CS22 B
 Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id
Results (Cont.)
Query: Return names of students who earned grade ‘B’
11
Students Enrolled
id Name
11 Ali
22 Ahmed
33 Saima
id C.no Grade
11 CS20 A
22 CS21 B
33 CS22 B
SELECT Name
FROM Students , Enrolled
WHERE Students.id= Enrolled.id
AND Enrolled . Grade=‘B’
 Name (Students (Enrolled . Grade = ‘B’ (Enrolled))⋈ Students . id = Enrolled . id
Results (Cont.)
12
Students.id=Enrolled.id
/ Enrolled.Grade=‘B’
Students
 Name
X
Enrolled
 Name
 Enrolled.Ggrade=‘B’
Students Enrolled
Students.id=Enrolled.id
Students.id=Enrolled.id
 Name
 Enrolled.Grade=‘B’Students
Enrolled
⋈
⋈
Results (Cont.)
13
Students.id=Enrolled.id
^ Enrolled.Grade=‘B’
Students
 Name
X
Enrolled
 Name
 Enrolled.Ggrade=‘B’
Students Enrolled
Students.id=Enrolled.id
Students.id=Enrolled.id
 Name
 Enrolled.Grade=‘B’Students
Enrolled
⋈
⋈
Execution time:
0.2804756 ms
Execution time :
0.0707199 ms
Execution time :
0.060316 ms
Comparing and contrasting proposed optimization strategies based
on execution time.
Results (Cont.)
14
id Name
11 Ali
22 Ahmed
33 Saima
Students
Enrolled
id C.no Grade
11 CS20 A
22 CS21 B
33 CS22 B
Name (Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled)
id Name id C.no Grade
11 Ali 11 CS20 A
11 Ali 22 CS21 B
11 Ali 33 CS22 B
22 Ahmed 11 CS20 A
22 Ahmed 22 CS21 B
22 Ahmed 33 CS22 B
33 Saima 11 CS20 A
33 Saima 22 CS21 B
33 Saima 33 CS22 B
( Students X Enrolled)
Execution plan #1
Results (Cont.)
15
id Name id C.no Grade
11 Ali 11 CS20 A
11 Ali 22 CS21 B
11 Ali 33 CS22 B
22 Ahmed 11 CS20 A
22 Ahmed 22 CS21 B
22 Ahmed 33 CS22 B
33 Saima 11 CS20 A
33 Saima 22 CS21 B
33 Saima 33 CS22 B
Sid Name Id C.no Grade
22 Ahmed 22 CS21 B
33 Saima 33 CS22 B
 Students . id = Enrolled . id / Enrolled . Grade = ‘B’
Name
Ahmed
Saima
Name
Execution plan #1 (Cont.)
( Students X Enrolled)
Name ( Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled)
This query cannot be the best way to reach our answer. We
have cross product, which means that we create a table
whose number of rows is |Students|* | Enrolled |.
Results (Cont.)
16
Students
Enrolled
id Name
11 Ali
22 Ahmed
33 Saima
id C.no Grade
11 CS20 A
22 CS21 B
33 CS22 B
Execution plan #2
 Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id
id Name id C.no Grade
11 Ali 11 CS20 A
22 Ahmed 22 CS21 B
33 Saima 33 CS22 B
( Students (Enrolled))⋈ Students . id = Enrolled . id
Results (Cont.)
17
Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id
Name
Ahmed
Saima
Name
Execution plan #2(Cont.)
id Name id C.no Grade
11 Ali 11 CS20 A
22 Ahmed 22 CS21 B
33 Saima 33 CS22 B
( Students (Enrolled))⋈ Students . id = Enrolled . id
id Name id C.no Grade
22 Ahmed 22 CS21 B
33 Saima 33 CS22 B
Takes less execution time as compared to 1st
plan because cross product is replaced by join
and the number of rows are decreased .
 Enrolled . Grade = ‘B’
Results (Cont.)
18
Enrolled
id C.no Grade
11 CS20 A
22 CS21 B
33 CS22 B
 Name (Students (Enrolled . Grade = ‘B’ (Enrolled))⋈ Students . id = Enrolled . id
 Enrolled . Grade = ‘B’
id C.no Grade
22 CS21 B
33 CS22 B
Execution plan #3
id Name
22 Ahmed
33 Saima
id C.no Grade
22 CS21 B
33 CS22 B
Students ⋈Students . id = Enrolled .id ( Enrolled)
Name
Ahmed
Saima
Name
Students
id Name
11 Ali
22 Ahmed
33 Saima
The earlier we process selections, less tuples we need to manipulate
higher up in the tree.
Results (Cont.)
 Developed a tool that translates user queries (entered in SQL) into mathematical representation
(relational algebra) necessary for data access.
 It has been proved that the developed tool is better at:
 producing syntax and semantic errors,
 generating query execution plans: (i) Simple, (ii) elimination of Cartesian product with join, and
(iii) push selection
 allowing connectivity with databases of interest and produces query results
 Query optimizer of the tool produces execution times of all three execution plans considered
 Based on the obtained results, it is concluded that push-selection is better than the join and join is better
than Cartesian product in terms of execution times.
 Tool may be used (in both academic and research institutes) for:
 better understanding of how queries are actually processed and optimized.
 the development of modern DBMS packages which will be more efficient in terms of execution time.
19
Conclusion
The measurement of the consumption of resources
Analysis of the tradeoff between execution time and
consumption of resources
Other optimization techniques can be implemented
20
Future Works
21
CRT Tool
ctrt.byethost7.com/crt
crt.quest.edu.pk
22
1. Chaudhuri S. Mendelzon A. and Paredaens J. (2008) An overview of query
optimization in relational systems. In proceedings of the 17th ACM SIGACT-
SIGMOD-SIGART Symposium on Principles of Database Systems, isbn: 0-89791-
996-3.
2. Bernstein P. A., and Newcomer E. (2009) Principles of Transaction Processing.
isbn: 9780080948416.
3. Elmasri R., and NavathS. B. (2011) Fundamentals of database systems, isbn:
978-81-317-1625-0, Addison-Wesley Longman Publishing Co., Inc. 2011.
4. D. Kossmann (2000). The State of the Art in Distributed Query
Processing. ACM Computing Surveys, 32(4): 422-469.
5. Wesley W. Chu, Fellow, and Paul Hurley (1982) Optimal Query Processing for
Distributed Database Systems. IEEE Transaction on Computers, vol. C-31, no.
9, September 1982.
References
23
6. W. Kim (1982) On optimizing an SQL-like nested query. ACM Transaction on
Database Systems, vol. 7, pages. 443-469, Sept. 1982.
7. Klug Anthony (2010) Equivalence of relational algebra and relational calculus
query languages having aggregate functions. Journal of ACM, Vol. 29, Number
3, isbn: 0004-5411, pages: 699-717.
8. Nica Anisoara, Charlesworth Ian, and Panju Maysum (2012) Analyzing Query
Optimization Process: Portraits of Join Enumeration Algorithms. In
proceedings of the 29th IEEE International Conference on Data Engineering
(ICDE), pages. 1301-1304.
9. Ozsu, M. Tamer, Valduriez Patrick (2010) Principles of Distributed Database
Systems. isbn: 978-1-4419-8833-1.
10. Majid Khan and M. N. A. Khan (2013) Exploring Query Optimization
Techniques in Relational Databases. In proceedings of the International Journal
of Database Theory and Application. Vol. 6, No. 3, June, 2013.
References
24
12. Alaa Aljanaby, Emad Abuelrub and Mohammed Odeh (2005) A Survey of
Distributed Query Optimization. In proceedings of the the International Arab
Journal of Information Technology, Vol. 2, No. 1, January 2005.
13. B.M. Monjurul Alom, Frans Henskens and Michael Hannaford (2009) Query
Processing and Optimization in Distributed Database Systems. International
Journal of Computer Science and Network Security (IJCSNS), vol.9 No.9,
September 2009.
14. M.A. Pund, S. R. Jadhao, P. D. Thakare (2011) A Role of Query Optimization
in Relational Database. International Journal of Scientific & Engineering
Research, Volume 2, Issue 1, ISSN 2229-5518.
15. Ratnesh Litoriya, Anshu Ranjan (2010) Implementation of Relational Algebra
Interpreter using another query language. International Conference on Data
Storage and Data Engineering. Pages 24-28, ISBN: 978-0-7695-3958-4
References
25
16. Kunal Jamsutkar, Viki Patil, Dr. B.B. Meshram (2013) Query Processing
Strategies in Distributed Database. Journal of Engineering, Computers &
Applied Sciences (JEC&AS), Volume 2, No.7, July 2013, ISSN No: 2319‐5606.
17. Kirby McMaster, Samuel Sambasivam, Steven Hadfield (2012) Relational
Algebra and SQL: Better Together. Proceedings of the Information Systems
Educators Conference. Vol. 29, no.1906, ISSN: 2167-1435.
18. Sunita M. Mahajan, Vaishali P. Jadhav (2012) An Analysis of Execution Plans in
Query Optimization. International Conference on Communication, Information &
Computing Technology (ICCICT). October 19-20, Mumbai, India.
19. W. Kim (1982) On optimizing an SQL-like nested query. ACM Transaction on
Database Systems., vol. 7, pages 443-469, Sept. 1982.
20. Deepak Sukheja,Umesh Kumar Singh (2011) A Novel Approach of Query
Optimization for Distributed Database Systems. IJCSI International Journal of
Computer Science Issues, Vol. 8, Issue 4, No 1, July 2011.
References
26
21. Seema Parminder Kaur (2013) Query Optimization Algorithm based on
Relational Algebra Equivalence Transformation. International Journal of
Engineering and Management Sciences (I.J.E.M.S.), vol.4 (3) 2013: 326-331, ISSN
2229-600X .
22. E. Zafarani, M. Reza, H. Asil and A. Asil (2012) Presenting a New Method for
Optimizing Join Queries Processing in Heterogeneous Distributed Databases.
In proceeding of the Knowledge Discovery and Data Mining (WKDD ’10), pages
379 – 382, ISBN 978-1-4244-5397-9.
23. Jyoti Mor, Indu Kashyap, R.K.Rathy (2012) Implementing Semantic Query
Optimization in Relational Databases. International Journal of Computer
Applications, isbn: 0975 – 8887, vol 52, No.9, August 2012.
24. Stefano Ceri, Georg Gottlob (1985) Translating SQL Into Relational Algebra:
Optimization, Semantics, and Equivalence of SQL Queries, Software
Engineering, In proceeding of the IEEE Transactions, vol. SE-11, issue 4, pages.
324 – 345, April 1985.
25. J. Plodzien (2000) Optimization of Object query Language, Ph.D. Thesis,
Institute Of Computer Science, Polish Academy Of Science,2000.
References
27
26. Preeti Tiwari, Swati V. Chande (2013) Optimization of Distributed Database
Queries Using Hybrids of Ant Colony Optimization Algorithm. International
Journal of Advanced Research in Computer Science and Software Engineering,
Volume 3, Issue 6, June 2013 ISSN: 2277 128X.
27. Navita Kumari “SQL Server Query Optimization Techniques - Tips for Writing
Efficient and Faster Queries” International Journal of Scientific and Research
Publications, Volume 2, Issue 6, June 2012 ISSN 2250-3153.
28. XU Silao, HONG Mei “Translating SQL Into Relational Algebra Tree Using
Object-Oriented Thinking to Obtain Expression Of Relational Algebra” I.J.
Engineering and Manufacturing, 2012,3, 53-62 Published Online June 2012 in
MECS.
29. Santhi Lasya, Sreekar Tanuku (2011) A Study of Library Databases by
Translating Those SQL Queries Into Relational Algebra and Generating
Query Trees. International Journal of Computer Science Issues (IJCSI), Vol.
8, Issue 5, No 1, September 2011.
References
Thanks
28
Questions/Suggestions
Query Processing (SQL)
29
 Structured Query Language (SQL) is declarative query language
developed for user convenience that tells the database management
system (DBMS) what the user wants.
 Structure of SQL query is based on three clauses
SELECT column1, column2, . . . , columnn
FROM Table1, Table2, . . . , Tablen
WHERE condition
Introduction (Cont.)
30
Employees
 Example: Return names of employees who are programmers
SELECT Ename
FROM Employees
WHERE Employee . Title = ‘Programmer’
EID EName Title
E1 Ahmed Programmer
E2 Farhan Elect. Engineer
E3 Kashif Programmer
E4 Neelam Mech. Engineer
E5 Ehsan Syst. Analyst
Query Processing (SQL)
Introduction (Cont.)
31
 As opposed to SQL, relational algebra is procedural
programming language that not only tells the DBMS
what the user wants but also tells how to compute the
answer.
 Relational algebra consists of operators that operate on
relations (Tables)
 Relations (Tables) correspond to sets of tuples/records
 Input of an operator:
 one or two relations
 Output of an operator:
 a result relation
 The output of one operator can serve as input to another
operator
Query Processing (Relational Algebra)
Introduction (Cont.)
σ, U, π,
×, ⋈,
∩, . . .
Table1 Table2
Result-Table
32
Employees
 Example: Return names of employees who are programmers
π EName σEmployees . Title = ‘Programmer’(Employees)
EID EName Title
E1 Ahmed Programmer
E2 Farhan Elect. Engineer
E3 Kashif Programmer
E4 Neelam Mech. Engineer
E5 Ehsan Syst. Analyst
Query Processing (Relational Algebra)
Introduction (Cont.)
33
 In order to translate a SQL query into relational algebra, query
processor translates;
 SELECT clause to Projection (π),
 FROM clause to table name(s) or their Cartesian, and
 WHERE clause to Selection (σ)
 Example 1: Return names of employees who are programmers
SELECT EName
FROM Employees
WHERE Employee . Title = ‘Programmer’
Query Processing (SQL to Relational Algebra)
Introduction (Cont.)
π EName σEmployees . Title = ‘Programmer’ (Employees)
34
 In order to translate a SQL query into relational algebra, query
processor translates;
 SELECT clause to Projection (π),
 FROM clause to table name(s) or their Cartesian, and
 WHERE clause to Selection (σ)
 Example 2: Return names of employees who are working on project P1
π EName σEmployees . EID = Assignment.ENo / Assignment . PNo = ‘P1’ (Employees X Assignment)
SELECT EName
FROM Employees, Assignment
WHERE Employee.EID = Assignment.ENo and Assignment.PNo = ‘P1’
Query Processing (SQL to Relational Algebra)
Introduction (Cont.)
35
 Name (Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled)
 Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id
 Name (Students (Enrolled . Grade = ‘B’ (Enrolled))⋈ Students . id = Enrolled . id
Results(Cont.)
36
37Tool

Mais conteúdo relacionado

Mais procurados

13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMSkoolkampus
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query OptimizationBrian Gallagher
 
Query Optimization
Query OptimizationQuery Optimization
Query Optimizationrohitsalunke
 
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...Beat Signer
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxAnusha sivakumar
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...Raj vardhan
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational AlgebraAmin Omi
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimizationWBUTTUTORIALS
 
Integrity constraints in dbms
Integrity constraints in dbmsIntegrity constraints in dbms
Integrity constraints in dbmsVignesh Saravanan
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbmsNaresh Kumar
 
Unit 5 composite datatypes
Unit 5  composite datatypesUnit 5  composite datatypes
Unit 5 composite datatypesDrkhanchanaR
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptxAnusha sivakumar
 

Mais procurados (20)

13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
Query processing
Query processingQuery processing
Query processing
 
Query Optimization
Query OptimizationQuery Optimization
Query Optimization
 
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
Query Processing and Optimisation - Lecture 10 - Introduction to Databases (1...
 
basic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptxbasic structure of SQL FINAL.pptx
basic structure of SQL FINAL.pptx
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
NESTED SUBQUERY.pptx
NESTED SUBQUERY.pptxNESTED SUBQUERY.pptx
NESTED SUBQUERY.pptx
 
Integrity constraints in dbms
Integrity constraints in dbmsIntegrity constraints in dbms
Integrity constraints in dbms
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Unit 5 composite datatypes
Unit 5  composite datatypesUnit 5  composite datatypes
Unit 5 composite datatypes
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
Relational model
Relational modelRelational model
Relational model
 
Query trees
Query treesQuery trees
Query trees
 
Relational Calculus
Relational CalculusRelational Calculus
Relational Calculus
 

Semelhante a Query optimization in SQL

Introduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculusIntroduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculusAjit Nayak
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineeringJulian Hyde
 
BISH CS Modle Exit Exam.doc
BISH CS Modle Exit Exam.docBISH CS Modle Exit Exam.doc
BISH CS Modle Exit Exam.docAnimutGeremew3
 
Lokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon informationLokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon informationbholu803201
 
Java Foundations: Objects and Classes
Java Foundations: Objects and ClassesJava Foundations: Objects and Classes
Java Foundations: Objects and ClassesSvetlin Nakov
 
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOADCS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOADSheik Mohideen
 
aprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdf
aprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdfaprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdf
aprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdfMahdeepBisht
 
A project report on libray mgt system
A project report on libray mgt system A project report on libray mgt system
A project report on libray mgt system ashvan710883
 
Library Management Python, MySQL
Library Management Python, MySQLLibrary Management Python, MySQL
Library Management Python, MySQLDarshit Vaghasiya
 
CSI2132: Database I – Assignment 3:
CSI2132: Database I – Assignment 3:CSI2132: Database I – Assignment 3:
CSI2132: Database I – Assignment 3:DeanMurphys
 
2005 fall cs523_lecture_4
2005 fall cs523_lecture_42005 fall cs523_lecture_4
2005 fall cs523_lecture_4abhineetverma
 
Create Student Project Database with insert, select, update, and del.pdf
Create Student Project Database with insert, select, update, and del.pdfCreate Student Project Database with insert, select, update, and del.pdf
Create Student Project Database with insert, select, update, and del.pdfarkleatheray
 
Database queries
Database queriesDatabase queries
Database querieslaiba29012
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...Isham Rashik
 
Online_Examination
Online_ExaminationOnline_Examination
Online_ExaminationRupam Dey
 

Semelhante a Query optimization in SQL (20)

Relational Algebra1.pptx
Relational Algebra1.pptxRelational Algebra1.pptx
Relational Algebra1.pptx
 
Introduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculusIntroduction to database-Formal Query language and Relational calculus
Introduction to database-Formal Query language and Relational calculus
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
 
BISH CS Modle Exit Exam.doc
BISH CS Modle Exit Exam.docBISH CS Modle Exit Exam.doc
BISH CS Modle Exit Exam.doc
 
Lokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon informationLokesh 's Ip project Pokemon information
Lokesh 's Ip project Pokemon information
 
Java Foundations: Objects and Classes
Java Foundations: Objects and ClassesJava Foundations: Objects and Classes
Java Foundations: Objects and Classes
 
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOADCS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
 
aprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdf
aprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdfaprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdf
aprojectreportonlibraymgtsystem2-141114055422-conversion-gate02 (1).pdf
 
A project report on libray mgt system
A project report on libray mgt system A project report on libray mgt system
A project report on libray mgt system
 
Project report format
Project report formatProject report format
Project report format
 
Library Management Python, MySQL
Library Management Python, MySQLLibrary Management Python, MySQL
Library Management Python, MySQL
 
R Algebra.ppt
R Algebra.pptR Algebra.ppt
R Algebra.ppt
 
PPT
PPTPPT
PPT
 
CSI2132: Database I – Assignment 3:
CSI2132: Database I – Assignment 3:CSI2132: Database I – Assignment 3:
CSI2132: Database I – Assignment 3:
 
2005 fall cs523_lecture_4
2005 fall cs523_lecture_42005 fall cs523_lecture_4
2005 fall cs523_lecture_4
 
Rdbms (2)
Rdbms (2)Rdbms (2)
Rdbms (2)
 
Create Student Project Database with insert, select, update, and del.pdf
Create Student Project Database with insert, select, update, and del.pdfCreate Student Project Database with insert, select, update, and del.pdf
Create Student Project Database with insert, select, update, and del.pdf
 
Database queries
Database queriesDatabase queries
Database queries
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...
 
Online_Examination
Online_ExaminationOnline_Examination
Online_Examination
 

Mais de Abdul Rehman

Introduction Relational Marketing
Introduction Relational Marketing Introduction Relational Marketing
Introduction Relational Marketing Abdul Rehman
 
Software Engineering
Software Engineering Software Engineering
Software Engineering Abdul Rehman
 
Introduction To Autumata Theory
 Introduction To Autumata Theory Introduction To Autumata Theory
Introduction To Autumata TheoryAbdul Rehman
 
computer System UNit Every thing
computer System UNit Every thingcomputer System UNit Every thing
computer System UNit Every thingAbdul Rehman
 
Education system in Pakistan
Education system in PakistanEducation system in Pakistan
Education system in PakistanAbdul Rehman
 
How to write a letter
How to write a letterHow to write a letter
How to write a letterAbdul Rehman
 
Writing good paragraphs ppt
Writing good paragraphs pptWriting good paragraphs ppt
Writing good paragraphs pptAbdul Rehman
 
programming c language.
programming c language. programming c language.
programming c language. Abdul Rehman
 

Mais de Abdul Rehman (8)

Introduction Relational Marketing
Introduction Relational Marketing Introduction Relational Marketing
Introduction Relational Marketing
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Introduction To Autumata Theory
 Introduction To Autumata Theory Introduction To Autumata Theory
Introduction To Autumata Theory
 
computer System UNit Every thing
computer System UNit Every thingcomputer System UNit Every thing
computer System UNit Every thing
 
Education system in Pakistan
Education system in PakistanEducation system in Pakistan
Education system in Pakistan
 
How to write a letter
How to write a letterHow to write a letter
How to write a letter
 
Writing good paragraphs ppt
Writing good paragraphs pptWriting good paragraphs ppt
Writing good paragraphs ppt
 
programming c language.
programming c language. programming c language.
programming c language.
 

Último

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Último (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Query optimization in SQL

  • 1. Query Processing and Query Optimization DATED: 11-03-2016 1
  • 2. Introduction Data base User Query 2 DBMS Result Query processor Query Optimizer Other Subprograms  Modern database management systems (DBMS) are complex programs that:  get user queries,  translate them in internal representation necessary for data accesss, and  produce meaningful result efficiently (that is the results which take less execution time and consume less resources)
  • 3. Query Processing 3 Introduction (Cont.) SELECT * FROM TABLE-1, TABLE-2 WHERE TABLE-1 . ID = TABLE-2 . ID σTABLE-1 . ID = TABLE-2 . ID (TABLE-1 X TABLE-2) Relational algebra generator Query parser (Syntax and semantic analyzer)  Query processor gets a user query in structured query language (SQL), checks query for syntax and semantic errors, and generates its equivalent expression in relational algebra necessary for data access. Query Processor
  • 4. Estimate alternate plan Estimate alternate plan Data base Query Alternate query plan 1 Alternate query plan 2 Alternate query plan n. . . Choose best plan among them 4 Q . P  The process of generating various execution plans for user query and finding a best plan that takes less execution time and consumes less resources. Query Optimizer Introduction (Cont.) Query Optimization Query processor
  • 5. 5  Generation of various execution plans and finding a better plan is done by query optimization techniques (algorithms) implemented in the query optimizer.  OPTIMIZATION TECHNIQUES  Simple execution plan  Eliminating Cartesian product with joins  Performing selection before join (Push selection)  Performing projection before join (Push projections) . . . Introduction (Cont.) Query Optimization
  • 6. 6  name  Students.id = Enrolled.id / Enrolled.grade=‘B’ Students Enrolled Introduction (Cont.) Query Optimization  SIMPLE QUERY EXECUTION PLAN: Query processor generates an equivalent relational algebraic expression and forward it to the query optimizer. Usually, that expression involves Cartesian product. Example: Return names of students who earned grade ‘B’ x id name age E1 Ahmed 15 E2 Farhan 14 id reg_nr grade E2 AB29 B E4 AB30 D Students Enrolled  name ( Enrolled. grade = ‘B’ / Students.id = Enrolled.id ) Student x Enrolled
  • 7. 7  name  Students.id = Enrolled.id / Enrolled.grade=‘B’ Students Enrolled Introduction (Cont.)  ELIMINATION OF CARTESIAN WITH JOIN: Cartesian product may be replaced with joins. Example:  name ( Enrolled. grade = ‘B’ / Students.id = Enrolled.id ) Student x Enrolled x Query Optimization  name  Enrolled.grade=‘B’ Students Enrolled Students.id = Enrolled.id⋈
  • 8. 8  name Students.id= Enrolled.id / Enrolled.grade=‘B’ Students Enrolled Introduction (Cont.)  PERFORMING SELECTION BEFORE JOIN (PUSH SELECTION): By pushing selection operator down makes them executes as early as possible x Query Optimization  name  Enrolled.grade=‘B’ Students Enrolled Students.id = Enrolled.id Students.id = Enrolled.id  name Enrolled.grade=‘B’Students Enrolled Example:  name ( Enrolled. grade = ‘B’ / Students.id = Enrolled.id ) Student x Enrolled ⋈ ⋈
  • 9. Query: Return names of students who earned grade ‘B’ 9 Students Enrolled id Name 11 Ali 22 Ahmed 33 Saima id C.no Grade 11 CS20 A 22 CS21 B 33 CS22 B  Name (Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled) SELECT Name FROM Students , Enrolled WHERE Students.id= Enrolled.id AND Enrolled . Grade=‘B’ Results
  • 10. Query: Return names of students who earned grade ‘B’ SELECT Name FROM Students , Enrolled WHERE Students.id= Enrolled.id AND Enrolled . Grade=‘B’ 10 Students Enrolled id Name 11 Ali 22 Ahmed 33 Saima id C.no Grade 11 CS20 A 22 CS21 B 33 CS22 B  Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id Results (Cont.)
  • 11. Query: Return names of students who earned grade ‘B’ 11 Students Enrolled id Name 11 Ali 22 Ahmed 33 Saima id C.no Grade 11 CS20 A 22 CS21 B 33 CS22 B SELECT Name FROM Students , Enrolled WHERE Students.id= Enrolled.id AND Enrolled . Grade=‘B’  Name (Students (Enrolled . Grade = ‘B’ (Enrolled))⋈ Students . id = Enrolled . id Results (Cont.)
  • 12. 12 Students.id=Enrolled.id / Enrolled.Grade=‘B’ Students  Name X Enrolled  Name  Enrolled.Ggrade=‘B’ Students Enrolled Students.id=Enrolled.id Students.id=Enrolled.id  Name  Enrolled.Grade=‘B’Students Enrolled ⋈ ⋈ Results (Cont.)
  • 13. 13 Students.id=Enrolled.id ^ Enrolled.Grade=‘B’ Students  Name X Enrolled  Name  Enrolled.Ggrade=‘B’ Students Enrolled Students.id=Enrolled.id Students.id=Enrolled.id  Name  Enrolled.Grade=‘B’Students Enrolled ⋈ ⋈ Execution time: 0.2804756 ms Execution time : 0.0707199 ms Execution time : 0.060316 ms Comparing and contrasting proposed optimization strategies based on execution time. Results (Cont.)
  • 14. 14 id Name 11 Ali 22 Ahmed 33 Saima Students Enrolled id C.no Grade 11 CS20 A 22 CS21 B 33 CS22 B Name (Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled) id Name id C.no Grade 11 Ali 11 CS20 A 11 Ali 22 CS21 B 11 Ali 33 CS22 B 22 Ahmed 11 CS20 A 22 Ahmed 22 CS21 B 22 Ahmed 33 CS22 B 33 Saima 11 CS20 A 33 Saima 22 CS21 B 33 Saima 33 CS22 B ( Students X Enrolled) Execution plan #1 Results (Cont.)
  • 15. 15 id Name id C.no Grade 11 Ali 11 CS20 A 11 Ali 22 CS21 B 11 Ali 33 CS22 B 22 Ahmed 11 CS20 A 22 Ahmed 22 CS21 B 22 Ahmed 33 CS22 B 33 Saima 11 CS20 A 33 Saima 22 CS21 B 33 Saima 33 CS22 B Sid Name Id C.no Grade 22 Ahmed 22 CS21 B 33 Saima 33 CS22 B  Students . id = Enrolled . id / Enrolled . Grade = ‘B’ Name Ahmed Saima Name Execution plan #1 (Cont.) ( Students X Enrolled) Name ( Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled) This query cannot be the best way to reach our answer. We have cross product, which means that we create a table whose number of rows is |Students|* | Enrolled |. Results (Cont.)
  • 16. 16 Students Enrolled id Name 11 Ali 22 Ahmed 33 Saima id C.no Grade 11 CS20 A 22 CS21 B 33 CS22 B Execution plan #2  Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id id Name id C.no Grade 11 Ali 11 CS20 A 22 Ahmed 22 CS21 B 33 Saima 33 CS22 B ( Students (Enrolled))⋈ Students . id = Enrolled . id Results (Cont.)
  • 17. 17 Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id Name Ahmed Saima Name Execution plan #2(Cont.) id Name id C.no Grade 11 Ali 11 CS20 A 22 Ahmed 22 CS21 B 33 Saima 33 CS22 B ( Students (Enrolled))⋈ Students . id = Enrolled . id id Name id C.no Grade 22 Ahmed 22 CS21 B 33 Saima 33 CS22 B Takes less execution time as compared to 1st plan because cross product is replaced by join and the number of rows are decreased .  Enrolled . Grade = ‘B’ Results (Cont.)
  • 18. 18 Enrolled id C.no Grade 11 CS20 A 22 CS21 B 33 CS22 B  Name (Students (Enrolled . Grade = ‘B’ (Enrolled))⋈ Students . id = Enrolled . id  Enrolled . Grade = ‘B’ id C.no Grade 22 CS21 B 33 CS22 B Execution plan #3 id Name 22 Ahmed 33 Saima id C.no Grade 22 CS21 B 33 CS22 B Students ⋈Students . id = Enrolled .id ( Enrolled) Name Ahmed Saima Name Students id Name 11 Ali 22 Ahmed 33 Saima The earlier we process selections, less tuples we need to manipulate higher up in the tree. Results (Cont.)
  • 19.  Developed a tool that translates user queries (entered in SQL) into mathematical representation (relational algebra) necessary for data access.  It has been proved that the developed tool is better at:  producing syntax and semantic errors,  generating query execution plans: (i) Simple, (ii) elimination of Cartesian product with join, and (iii) push selection  allowing connectivity with databases of interest and produces query results  Query optimizer of the tool produces execution times of all three execution plans considered  Based on the obtained results, it is concluded that push-selection is better than the join and join is better than Cartesian product in terms of execution times.  Tool may be used (in both academic and research institutes) for:  better understanding of how queries are actually processed and optimized.  the development of modern DBMS packages which will be more efficient in terms of execution time. 19 Conclusion
  • 20. The measurement of the consumption of resources Analysis of the tradeoff between execution time and consumption of resources Other optimization techniques can be implemented 20 Future Works
  • 22. 22 1. Chaudhuri S. Mendelzon A. and Paredaens J. (2008) An overview of query optimization in relational systems. In proceedings of the 17th ACM SIGACT- SIGMOD-SIGART Symposium on Principles of Database Systems, isbn: 0-89791- 996-3. 2. Bernstein P. A., and Newcomer E. (2009) Principles of Transaction Processing. isbn: 9780080948416. 3. Elmasri R., and NavathS. B. (2011) Fundamentals of database systems, isbn: 978-81-317-1625-0, Addison-Wesley Longman Publishing Co., Inc. 2011. 4. D. Kossmann (2000). The State of the Art in Distributed Query Processing. ACM Computing Surveys, 32(4): 422-469. 5. Wesley W. Chu, Fellow, and Paul Hurley (1982) Optimal Query Processing for Distributed Database Systems. IEEE Transaction on Computers, vol. C-31, no. 9, September 1982. References
  • 23. 23 6. W. Kim (1982) On optimizing an SQL-like nested query. ACM Transaction on Database Systems, vol. 7, pages. 443-469, Sept. 1982. 7. Klug Anthony (2010) Equivalence of relational algebra and relational calculus query languages having aggregate functions. Journal of ACM, Vol. 29, Number 3, isbn: 0004-5411, pages: 699-717. 8. Nica Anisoara, Charlesworth Ian, and Panju Maysum (2012) Analyzing Query Optimization Process: Portraits of Join Enumeration Algorithms. In proceedings of the 29th IEEE International Conference on Data Engineering (ICDE), pages. 1301-1304. 9. Ozsu, M. Tamer, Valduriez Patrick (2010) Principles of Distributed Database Systems. isbn: 978-1-4419-8833-1. 10. Majid Khan and M. N. A. Khan (2013) Exploring Query Optimization Techniques in Relational Databases. In proceedings of the International Journal of Database Theory and Application. Vol. 6, No. 3, June, 2013. References
  • 24. 24 12. Alaa Aljanaby, Emad Abuelrub and Mohammed Odeh (2005) A Survey of Distributed Query Optimization. In proceedings of the the International Arab Journal of Information Technology, Vol. 2, No. 1, January 2005. 13. B.M. Monjurul Alom, Frans Henskens and Michael Hannaford (2009) Query Processing and Optimization in Distributed Database Systems. International Journal of Computer Science and Network Security (IJCSNS), vol.9 No.9, September 2009. 14. M.A. Pund, S. R. Jadhao, P. D. Thakare (2011) A Role of Query Optimization in Relational Database. International Journal of Scientific & Engineering Research, Volume 2, Issue 1, ISSN 2229-5518. 15. Ratnesh Litoriya, Anshu Ranjan (2010) Implementation of Relational Algebra Interpreter using another query language. International Conference on Data Storage and Data Engineering. Pages 24-28, ISBN: 978-0-7695-3958-4 References
  • 25. 25 16. Kunal Jamsutkar, Viki Patil, Dr. B.B. Meshram (2013) Query Processing Strategies in Distributed Database. Journal of Engineering, Computers & Applied Sciences (JEC&AS), Volume 2, No.7, July 2013, ISSN No: 2319‐5606. 17. Kirby McMaster, Samuel Sambasivam, Steven Hadfield (2012) Relational Algebra and SQL: Better Together. Proceedings of the Information Systems Educators Conference. Vol. 29, no.1906, ISSN: 2167-1435. 18. Sunita M. Mahajan, Vaishali P. Jadhav (2012) An Analysis of Execution Plans in Query Optimization. International Conference on Communication, Information & Computing Technology (ICCICT). October 19-20, Mumbai, India. 19. W. Kim (1982) On optimizing an SQL-like nested query. ACM Transaction on Database Systems., vol. 7, pages 443-469, Sept. 1982. 20. Deepak Sukheja,Umesh Kumar Singh (2011) A Novel Approach of Query Optimization for Distributed Database Systems. IJCSI International Journal of Computer Science Issues, Vol. 8, Issue 4, No 1, July 2011. References
  • 26. 26 21. Seema Parminder Kaur (2013) Query Optimization Algorithm based on Relational Algebra Equivalence Transformation. International Journal of Engineering and Management Sciences (I.J.E.M.S.), vol.4 (3) 2013: 326-331, ISSN 2229-600X . 22. E. Zafarani, M. Reza, H. Asil and A. Asil (2012) Presenting a New Method for Optimizing Join Queries Processing in Heterogeneous Distributed Databases. In proceeding of the Knowledge Discovery and Data Mining (WKDD ’10), pages 379 – 382, ISBN 978-1-4244-5397-9. 23. Jyoti Mor, Indu Kashyap, R.K.Rathy (2012) Implementing Semantic Query Optimization in Relational Databases. International Journal of Computer Applications, isbn: 0975 – 8887, vol 52, No.9, August 2012. 24. Stefano Ceri, Georg Gottlob (1985) Translating SQL Into Relational Algebra: Optimization, Semantics, and Equivalence of SQL Queries, Software Engineering, In proceeding of the IEEE Transactions, vol. SE-11, issue 4, pages. 324 – 345, April 1985. 25. J. Plodzien (2000) Optimization of Object query Language, Ph.D. Thesis, Institute Of Computer Science, Polish Academy Of Science,2000. References
  • 27. 27 26. Preeti Tiwari, Swati V. Chande (2013) Optimization of Distributed Database Queries Using Hybrids of Ant Colony Optimization Algorithm. International Journal of Advanced Research in Computer Science and Software Engineering, Volume 3, Issue 6, June 2013 ISSN: 2277 128X. 27. Navita Kumari “SQL Server Query Optimization Techniques - Tips for Writing Efficient and Faster Queries” International Journal of Scientific and Research Publications, Volume 2, Issue 6, June 2012 ISSN 2250-3153. 28. XU Silao, HONG Mei “Translating SQL Into Relational Algebra Tree Using Object-Oriented Thinking to Obtain Expression Of Relational Algebra” I.J. Engineering and Manufacturing, 2012,3, 53-62 Published Online June 2012 in MECS. 29. Santhi Lasya, Sreekar Tanuku (2011) A Study of Library Databases by Translating Those SQL Queries Into Relational Algebra and Generating Query Trees. International Journal of Computer Science Issues (IJCSI), Vol. 8, Issue 5, No 1, September 2011. References
  • 29. Query Processing (SQL) 29  Structured Query Language (SQL) is declarative query language developed for user convenience that tells the database management system (DBMS) what the user wants.  Structure of SQL query is based on three clauses SELECT column1, column2, . . . , columnn FROM Table1, Table2, . . . , Tablen WHERE condition Introduction (Cont.)
  • 30. 30 Employees  Example: Return names of employees who are programmers SELECT Ename FROM Employees WHERE Employee . Title = ‘Programmer’ EID EName Title E1 Ahmed Programmer E2 Farhan Elect. Engineer E3 Kashif Programmer E4 Neelam Mech. Engineer E5 Ehsan Syst. Analyst Query Processing (SQL) Introduction (Cont.)
  • 31. 31  As opposed to SQL, relational algebra is procedural programming language that not only tells the DBMS what the user wants but also tells how to compute the answer.  Relational algebra consists of operators that operate on relations (Tables)  Relations (Tables) correspond to sets of tuples/records  Input of an operator:  one or two relations  Output of an operator:  a result relation  The output of one operator can serve as input to another operator Query Processing (Relational Algebra) Introduction (Cont.) σ, U, π, ×, ⋈, ∩, . . . Table1 Table2 Result-Table
  • 32. 32 Employees  Example: Return names of employees who are programmers π EName σEmployees . Title = ‘Programmer’(Employees) EID EName Title E1 Ahmed Programmer E2 Farhan Elect. Engineer E3 Kashif Programmer E4 Neelam Mech. Engineer E5 Ehsan Syst. Analyst Query Processing (Relational Algebra) Introduction (Cont.)
  • 33. 33  In order to translate a SQL query into relational algebra, query processor translates;  SELECT clause to Projection (π),  FROM clause to table name(s) or their Cartesian, and  WHERE clause to Selection (σ)  Example 1: Return names of employees who are programmers SELECT EName FROM Employees WHERE Employee . Title = ‘Programmer’ Query Processing (SQL to Relational Algebra) Introduction (Cont.) π EName σEmployees . Title = ‘Programmer’ (Employees)
  • 34. 34  In order to translate a SQL query into relational algebra, query processor translates;  SELECT clause to Projection (π),  FROM clause to table name(s) or their Cartesian, and  WHERE clause to Selection (σ)  Example 2: Return names of employees who are working on project P1 π EName σEmployees . EID = Assignment.ENo / Assignment . PNo = ‘P1’ (Employees X Assignment) SELECT EName FROM Employees, Assignment WHERE Employee.EID = Assignment.ENo and Assignment.PNo = ‘P1’ Query Processing (SQL to Relational Algebra) Introduction (Cont.)
  • 35. 35  Name (Students . id = Enrolled . id / Enrolled . Grade = ‘B’ ( Students X Enrolled)  Name ( Enrolled . Grade = ‘B’ ( Students (Enrolled))⋈ Students . id = Enrolled . id  Name (Students (Enrolled . Grade = ‘B’ (Enrolled))⋈ Students . id = Enrolled . id Results(Cont.)
  • 36. 36