Database Management Systems (Dbms Ii) : Query Processing & Optimization
Database Management Systems (Dbms Ii) : Query Processing & Optimization
DATABASE MANAGEMENT
SYSTEMS (DBMS II)
CHAPTER 02
QUERY PROCESSING
& OPTIMIZATION
DATABASE MANAGEMENT SYSTEMS (DBMS II)
✓2.1. Query Processing Steps in DBMS.
✓2.2. Query Decomposition in DBMS.
✓2.3. Optimization Process in DBMS.
✓2.4. Approaches to Query Optimization.
✓2.5.Transformation Rules.
✓2.6.Implementing Relational Operators.
✓2.7.Pipelining.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What is Data Processing in DBMS?
Definition:
►data processing may refer to a known steps in the
information processing cycle in which data is acquired,
entered, validated, processed, stored, and output, in
response to QUERIES.
The processing is the step that organizes the information in
order to form the desired output.
►Queries of a database can be fast or slow. Depends on a lot
of things. The size of the table, the amount of data you are
requesting from the query, etc.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
Introduction to QPO
►By writing a query, there are many plans that a database management
system
(DBMS) can follow to process it and produce its answer. So All plans are
equivalent in terms of their final output but they vary in their cost & the
amount of time that they need to run.
What is the plan that needs the least amount of time?
Such query optimization is absolutely necessary in a DBMS.
►What is a Query processor?
Definition 1:A query processor is part of a DBMS ( it’s the DBMS
compiler) responsible for translating declarative statements written
in a given query language into a sequence of physical operations to
be executed by the lower levels of the system to generate outputs.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What is a Query processor?
Definition 2:
All database systems must be able to respond to requests for
information from the user process queries So Obtaining the
desired information from a database system in a predictable and
reliable fashion is called Query Processing.
►What is a Query Optimization?
Definition : Getting the desired information from a
database system (out put) back in a timely manner that
deals with the custom required techniques is called
Query Optimization. This paper will introduce the reader to
the basic concepts alternatives can be enormous.
►You can Optimize your query by using various commands and
operators such as and, or ,like ,order by …etc.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What is Query Processing and Optimization (QPO)?
Definition 1:
► Basic idea of QPO :
In SQL, queries are expressed in high level declarative format
so QPO do translates a SQL query to an execution plan over
physical data model by using an operations & Optimized
operations or commands on file-structures, indices, etc.
► Ideal execution plan by Query should take as little time
as possible.
Definition 2 of QPO ( very important):
►Query processing is a set of activities involving in getting the
result of a query expressed in a high-level language. These
activities includes parsing the queries and translate them into
expressions that can be implemented at the physical level of the
file system & then if it’s possible Optimizing and evaluating
the query.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
❖ The cost of processing of query is dominated by the speed of
disk access.
For a given query, there are several possible strategies for
processing , especially when query is complex. So The
difference between a good strategies and a bad one is based on
the order of magnitude. Therefore, it is worthwhile for the
system to spend some time on selecting a good strategies for
processing query.
►Selecting the proper rules to apply, when to apply them and how
they are applied is the function of the query optimization engine.
► Costs are used to estimate the runtime cost of evaluating the query, in
terms of the number of I/O operations required, the CPU requirements,
and other factors determined from the data dictionary.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
3. Evaluation:
►What do we mean by Query EVALUATION in DBMS?
► The final step in processing a query is the evaluation phase which
can be made by either:
➢ Example query:
➢Example query:
select employees.name, orders.product from
employees
inner join orders on
(employees.employee_id=orders.employee_id)
DATABASE MANAGEMENT SYSTEMS (DBMS II)
3. TREE structure :
➢ This query contains Records that may executed or not
based on the conditions that the branches of query uses.
➢ Limitations:
➢ The user should carefully monitor the conditions used to be
able to retrieve the required information.
➢ Example query:
select * from persons
where(firstname='tove' or firstname='stephen')
and
lastname='svendson'
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What are the Transformation rules used in query
optimization?
1. Query normalization:
This achieving the following goals:
A. Isolate the different types of operators at different levels
in the expression.
B. Eventually eliminate operators when necessary.
C. Perform the selection operators.
2. Representive rules:
A. Follow the SQL command syntax.
B. Separate between data & the database schema.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What are the Transformation rules used in query
optimization?
3. Simplification rules :
This means that the simplification of query is critical so we have to
make our query simple in format.
A. don't use relation algebra we it’s not necessary.
B. Don’t use join when it’ not necessary.
C. Other simplifications.
3. Semantic optimization:
This means use as much as conditions, blocks of data
necessary to obtain the outputs.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
►What is parallel database?
►Parallel database systems:
Is used improve performance through parallelizing
various operations like loading data, query
execution data may be distributed, but purely for
performance reasons.
►What is distributed database?
►Distributed database systems:
Data is physically stored across various sites, each
of which runs DBMS and can function
independently. Data distribution determined by
local ownership and availability, in addition to
performance.
DATABASE MANAGEMENT SYSTEMS (DBMS II)
DATABASE MANAGEMENT SYSTEMS (DBMS II)
END of CHAPTER 02
QUERY PROCESSING
&
OPTIMIZATION
THANK YOU FOR YOUR TIME