SlideShare a Scribd company logo
1 of 16
Query Processing and
Optimization
Introduction
• In this chapter we shall discuss the techniques
used by a DBMS to process, optimize and execute
high-level queries.
• The techniques used to split complex queries into
multiple simple operations and methods of
implementing these low-level operations.
• The query optimization techniques are used to
chose an efficient execution plan that will
minimize the runtime as well as many other types
of resources such as number of disk I/O, CPU
time and so on.
Query Processing
• Query Processing is a procedure of transforming a high-level
query (such as SQL) into a correct and efficient execution plan
expressed in low-level language.
• When a database system receives a query for update or
retrieval of information, it goes through a series of
compilation steps, called execution plan.
• Query processing goes through various phases:
• first phase is called syntax checking phase, the system parses
the query and checks that it follows the syntax rules or not.
• It then matches the objects in the query syntax with the view
tables and columns listed in the system table.
• In second phase the SQL query is translated in to an algebraic
expression using various rules.
• So that the process of transforming a high-level SQL query into a
relational algebraic form is called Query Decomposition.
• The relational algebraic expression now passes to the query
optimizer.
• In third phase optimization is performed by substituting equivalent
expression depends on the factors such that the existence of
certain database structures, whether or not a given file is stored,
the presence of different indexes & so on.
• Query optimization module work in tandem with the join manager
module to improve the order in which joins are performed.
• At this stage the cost model and several other
estimation formulas are used to rewrite the query.
• The modified query is written to utilize system
resources so as to bring the optimal performance.
• The query optimizer then generates an action plan also
called a execution plan.
• This action plans are converted into a query codes that
are finally executed by a run time database processor.
• The run time database processor estimate the cost of
each action plan and chose the optimal one for the
execution.
Query Analyzer
• The syntax analyzer takes the query from the
users, parses it into tokens and analyses the
tokens and their order to make sure they
follow the rules of the language grammar.
• Is an error is found in the query submitted by
the user, it is rejected and an error code
together with an explanation of why the query
was rejected is return to the user.
Query Decomposition
• In query decomposition the query processing aims are to transfer
the high-level query into a relational algebra query and to check
whether that query is syntactically and semantically correct.
• Thus the query decomposition is start with a high-level query and
transform into query graph of low-level operations, which satisfy
the query.
• The SQL query is decomposed into query blocks (low-level
operations), which form the basic unit.
• Hence nested queries within a query are identified as separate
query blocks.
• The query decomposer goes through five stages of processing for
decomposition into low-level operation and translation into
algebraic expressions.
Query Analysis
• During the query analysis phase, the query is
syntactically analyzed using the programming
language compiler (parser).
• A syntactically legal query is then validated,
using the system catalog, to ensure that all
data objects (relations and attributes) referred
to by the query are defined in the database.
• The type specification of the query qualifiers
and result is also checked at this stage.
• Example:
SELECT emp_nm FROM EMPLOYEE WHERE
emp_desg>100
This query will be rejected because the comparison
“>100” is incompatible with the data type of
emp_desg which is a variable character string.
• At the end of query analysis phase, the high-level query
(SQL) is transformed into some internal representation
that is more suitable for processing.
• This internal representation is typically a kind of query
tree.
• A Query Tree is a tree data structure that
corresponds expression.
• A Query Tree is also called a relational algebra
tree.
– Leaf node of the tree, representing the base
input relations of the query.
– Internal nodes result of applying an operation in
the algebra.
– Root of the tree representing a result of the query.
• SELECT (P.proj_no, P.dept_no, E.name, E.add,
E.dob)
• FROM PROJECT P, DEPARTMENT D, EMPLOYEE
E
• WHERE P.dept_no = D.d_no AND D.mgr_id =
E.emp_id AND P.proj_loc = ‘Mumbai’ ;
• The three relations PROJECT, DEPARTMENT,
EMPLOYEE are represent as a leaf nodes P, D
and E, while the relational algebra operations
of the represented by internal tree nodes.
• Same SQL query can have man different
relational algebra expressions and hence
many different query trees.
• The query parser typically generates a
standard initial (canonical) query tree.
Query Normalization
• The primary phase of the normalization is to avoid
redundancy.
• The normalization phase converts the query into a
normalized form that can be more easily manipulated.
• In the normalization phase, a set of equivalency rules
are applied so that the projection and selection
operations included on the query are simplified to
avoid redundancy.
• The projection operation corresponds to the SELECT
clause of SQL query and the selection operation
correspond to the predicate found in WHERE clause.
• The equivalency transformation rules that are applied.
Semantic Analyzer
• The objective of this phase of query processing is to reduce the number of
predicates.
• The semantic analyzer rejects the normalized queries that are incorrectly
formulated.
• A query is incorrectly formulated if components do not contribute to the
generation of result.
• This happens in case of missing join specification.
• A query is contradictory if its predicate cannot satisfy by any tuple in the relation.
• The semantic analyzer examine the relational calculus query (SQL) to make sure it
contains only data objects that is table, columns, views, indexes that are defined in
the database catalog.
• It makes sure that each object in the query is referenced correctly according to its
data type.
• In case of missing join specifications the components do not contribute to the
generation of the results, and thus, a query may be incorrect formulated.

More Related Content

What's hot

Relational Algebra,Types of join
Relational Algebra,Types of joinRelational Algebra,Types of join
Relational Algebra,Types of joinraj upadhyay
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query OptimizationRavinder Kamboj
 
Query processing in Distributed Database System
Query processing in Distributed Database SystemQuery processing in Distributed Database System
Query processing in Distributed Database SystemMeghaj Mallick
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architecturesPooja Dixit
 
Distributed Database Management System
Distributed Database Management SystemDistributed Database Management System
Distributed Database Management SystemAAKANKSHA JAIN
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMSkoolkampus
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimizationWBUTTUTORIALS
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra pptGirdharRatne
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLEVraj Patel
 
Introduction to Distributed System
Introduction to Distributed SystemIntroduction to Distributed System
Introduction to Distributed SystemSunita Sahu
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJDharita Chokshi
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database conceptsTemesgenthanks
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database SystemSulemang
 

What's hot (20)

Relational Algebra,Types of join
Relational Algebra,Types of joinRelational Algebra,Types of join
Relational Algebra,Types of join
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query Optimization
 
Query processing in Distributed Database System
Query processing in Distributed Database SystemQuery processing in Distributed Database System
Query processing in Distributed Database System
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architectures
 
Distributed Database Management System
Distributed Database Management SystemDistributed Database Management System
Distributed Database Management System
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
 
Distributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query ProcessingDistributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query Processing
 
Database System Architectures
Database System ArchitecturesDatabase System Architectures
Database System Architectures
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
Introduction to Distributed System
Introduction to Distributed SystemIntroduction to Distributed System
Introduction to Distributed System
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Active database
Active databaseActive database
Active database
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Query trees
Query treesQuery trees
Query trees
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database System
 
Recovery techniques
Recovery techniquesRecovery techniques
Recovery techniques
 

Similar to Query processing

LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxAthosBeatus
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptxShafii8
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluationavniS
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
Query optimization
Query optimizationQuery optimization
Query optimizationPooja Dixit
 
UNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data baseUNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data baseshindhe1098cv
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performancefika sweety
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performancefika sweety
 

Similar to Query processing (20)

LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
Query processing
Query processingQuery processing
Query processing
 
Measures of query cost
Measures of query costMeasures of query cost
Measures of query cost
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
Statistics
StatisticsStatistics
Statistics
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
1 query processing
1 query processing1 query processing
1 query processing
 
1 query processing
1 query processing1 query processing
1 query processing
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Mc seminar
Mc seminarMc seminar
Mc seminar
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
UNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data baseUNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data base
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performance
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performance
 
module 1.pptx
module 1.pptxmodule 1.pptx
module 1.pptx
 
Oracle query optimizer
Oracle query optimizerOracle query optimizer
Oracle query optimizer
 
Development Guideline
Development GuidelineDevelopment Guideline
Development Guideline
 

More from Ravinder Kamboj

More from Ravinder Kamboj (12)

Data warehouse,data mining & Big Data
Data warehouse,data mining & Big DataData warehouse,data mining & Big Data
Data warehouse,data mining & Big Data
 
DDBMS
DDBMSDDBMS
DDBMS
 
Normalization of Data Base
Normalization of Data BaseNormalization of Data Base
Normalization of Data Base
 
Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
Lecture 1&2(rdbms-ii)
Lecture 1&2(rdbms-ii)Lecture 1&2(rdbms-ii)
Lecture 1&2(rdbms-ii)
 
Java script
Java scriptJava script
Java script
 
File Management
File ManagementFile Management
File Management
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
DHTML
DHTMLDHTML
DHTML
 
CSA lecture-1
CSA lecture-1CSA lecture-1
CSA lecture-1
 
Relational database management system (rdbms) i
Relational database management system (rdbms) iRelational database management system (rdbms) i
Relational database management system (rdbms) i
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Query processing

  • 2. Introduction • In this chapter we shall discuss the techniques used by a DBMS to process, optimize and execute high-level queries. • The techniques used to split complex queries into multiple simple operations and methods of implementing these low-level operations. • The query optimization techniques are used to chose an efficient execution plan that will minimize the runtime as well as many other types of resources such as number of disk I/O, CPU time and so on.
  • 3. Query Processing • Query Processing is a procedure of transforming a high-level query (such as SQL) into a correct and efficient execution plan expressed in low-level language. • When a database system receives a query for update or retrieval of information, it goes through a series of compilation steps, called execution plan. • Query processing goes through various phases: • first phase is called syntax checking phase, the system parses the query and checks that it follows the syntax rules or not. • It then matches the objects in the query syntax with the view tables and columns listed in the system table.
  • 4. • In second phase the SQL query is translated in to an algebraic expression using various rules. • So that the process of transforming a high-level SQL query into a relational algebraic form is called Query Decomposition. • The relational algebraic expression now passes to the query optimizer. • In third phase optimization is performed by substituting equivalent expression depends on the factors such that the existence of certain database structures, whether or not a given file is stored, the presence of different indexes & so on. • Query optimization module work in tandem with the join manager module to improve the order in which joins are performed.
  • 5. • At this stage the cost model and several other estimation formulas are used to rewrite the query. • The modified query is written to utilize system resources so as to bring the optimal performance. • The query optimizer then generates an action plan also called a execution plan. • This action plans are converted into a query codes that are finally executed by a run time database processor. • The run time database processor estimate the cost of each action plan and chose the optimal one for the execution.
  • 6. Query Analyzer • The syntax analyzer takes the query from the users, parses it into tokens and analyses the tokens and their order to make sure they follow the rules of the language grammar. • Is an error is found in the query submitted by the user, it is rejected and an error code together with an explanation of why the query was rejected is return to the user.
  • 7. Query Decomposition • In query decomposition the query processing aims are to transfer the high-level query into a relational algebra query and to check whether that query is syntactically and semantically correct. • Thus the query decomposition is start with a high-level query and transform into query graph of low-level operations, which satisfy the query. • The SQL query is decomposed into query blocks (low-level operations), which form the basic unit. • Hence nested queries within a query are identified as separate query blocks. • The query decomposer goes through five stages of processing for decomposition into low-level operation and translation into algebraic expressions.
  • 8.
  • 9. Query Analysis • During the query analysis phase, the query is syntactically analyzed using the programming language compiler (parser). • A syntactically legal query is then validated, using the system catalog, to ensure that all data objects (relations and attributes) referred to by the query are defined in the database. • The type specification of the query qualifiers and result is also checked at this stage.
  • 10. • Example: SELECT emp_nm FROM EMPLOYEE WHERE emp_desg>100 This query will be rejected because the comparison “>100” is incompatible with the data type of emp_desg which is a variable character string. • At the end of query analysis phase, the high-level query (SQL) is transformed into some internal representation that is more suitable for processing. • This internal representation is typically a kind of query tree.
  • 11. • A Query Tree is a tree data structure that corresponds expression. • A Query Tree is also called a relational algebra tree. – Leaf node of the tree, representing the base input relations of the query. – Internal nodes result of applying an operation in the algebra. – Root of the tree representing a result of the query.
  • 12. • SELECT (P.proj_no, P.dept_no, E.name, E.add, E.dob) • FROM PROJECT P, DEPARTMENT D, EMPLOYEE E • WHERE P.dept_no = D.d_no AND D.mgr_id = E.emp_id AND P.proj_loc = ‘Mumbai’ ;
  • 13.
  • 14. • The three relations PROJECT, DEPARTMENT, EMPLOYEE are represent as a leaf nodes P, D and E, while the relational algebra operations of the represented by internal tree nodes. • Same SQL query can have man different relational algebra expressions and hence many different query trees. • The query parser typically generates a standard initial (canonical) query tree.
  • 15. Query Normalization • The primary phase of the normalization is to avoid redundancy. • The normalization phase converts the query into a normalized form that can be more easily manipulated. • In the normalization phase, a set of equivalency rules are applied so that the projection and selection operations included on the query are simplified to avoid redundancy. • The projection operation corresponds to the SELECT clause of SQL query and the selection operation correspond to the predicate found in WHERE clause. • The equivalency transformation rules that are applied.
  • 16. Semantic Analyzer • The objective of this phase of query processing is to reduce the number of predicates. • The semantic analyzer rejects the normalized queries that are incorrectly formulated. • A query is incorrectly formulated if components do not contribute to the generation of result. • This happens in case of missing join specification. • A query is contradictory if its predicate cannot satisfy by any tuple in the relation. • The semantic analyzer examine the relational calculus query (SQL) to make sure it contains only data objects that is table, columns, views, indexes that are defined in the database catalog. • It makes sure that each object in the query is referenced correctly according to its data type. • In case of missing join specifications the components do not contribute to the generation of the results, and thus, a query may be incorrect formulated.