What Is Query Processing?
What Is Query Processing?
Friday, January 8,
ADBMS 2021
Algebra
Basic Algorithms for Executing Query The aim of query processing is to find information in one or
ADBMS
Operations more databases and deliver it to the user quickly and
Using Heuristic in Query Optimization efficiently.
Using Selectivity and Cost Estimates in Query • Query Processing can be divided into four main phases:
Optimization • Decomposition:
Semantic Query Optimization • Optimization
• Code generation, and
1 2
• Execution
ADBMS
1
1/8/2021
Query processing …
Query processing…
• Query processing: Execute transactions in behalf of this query
and print the result. Steps in query processing:
ADBMS
ADBMS
Simplification :- to detect redundant qualifications,
5 6
Relational Algebra
Cont.…
• Example: Select Customer name From Customer, Invoice
• Domain: set of relations Where region = ‘Kansas City and Amount > 1000
Friday, January 8, 2021
ADBMS
7 8
2
1/8/2021
Query processing…
• Query Optimization :- are one of the main means by which Cont.…
• Approaches to Query Optimization
modern database systems achieve their performance
ADBMS
ADBMS
• Thus the heuristic approach of optimization will make
request from among the manifold alternative strategies. i.e. use of:
there are many ways (access paths) for accessing desired • Properties of individual operators
• Association between operators
file/record.
• Query Tree: a graphical representation of the operators,
• The optimizer tries to select the most efficient (cheapest) relations, attributes and predicates and processing sequence
during query processing.
access path for accessing the data 9 10
Cont. Cont.
Query tree is composed of three main parts: • The properties of each operations and the association between
Friday, January 8, 2021
ADBMS
3
1/8/2021
Cont. Cont.
ADBMS
13 14
Cont. Cont.
• Query tree:
Process for heuristics optimization – A tree data structure that corresponds to a relational algebra
Friday, January 8, 2021
ADBMS
3. A query execution plan is generated to execute groups of • An execution of the query tree consists of executing an internal
operations based on the access paths available on the files node operation whenever its operands are available and then
replacing that internal node by the relation that results from
involved in the query. executing the operation.
The main heuristic is to apply first the operations that reduce the • Query graph:
size of intermediate results. – A graph data structure that corresponds to a relational
calculus expression.
• E.g. Apply SELECT and PROJECT operations before applying
15 – It does not indicate an order on which operations to perform 16
the JOIN or other binary operations.
first.
– There is only a single graph corresponding to each query.
4
1/8/2021
Cont. Cont.
Example:
SELECT ENAME,RESP
ADBMS
ADBMS
AND PNAME = "CAD/CAM"
AND DUR ≥ 36
AND TITLE = "Programmer"
17 18
ADBMS
19 20
5
1/8/2021
Cont. Cont.
ADBMS
ADBMS
Constrict query tree ?
21 22
3. The select and join operations that are most restrictive should be
executed before other similar operations. (This is done by
reordering the leaf nodes of the tree among themselves and
23 adjusting the rest of the tree appropriately.) 24
6
1/8/2021
Using Selectivity and Cost Estimates in Query Optimization Cost Estimation Approach to Query Optimization
• The main idea is to minimize the cost of processing a query.
• Cost-based query optimization:
The cost function is comprised of:
ADBMS
ADBMS
• Number of execution strategies to be considered for the purpose of estimating cost.
• Cost Components for Query Execution • The main target of query optimization is to minimize the size
1. Access cost to secondary storage of the intermediate relation. The size will have effect in the
2. Storage cost cost of:
3. Computation cost • Disk Access
4. Memory usage cost • Data Transportation
5. Communication cost • Storage space in the Primary Memory
25 26
• Writing on Disk
ADBMS
7
1/8/2021
Cont.
ADBMS
ADBMS
– S2 Binary search:
• If the selection condition involves an equality comparison on a key
attribute on which the file is ordered, binary search (which is more
efficient than linear search) can be used
– S3 Using a primary index to retrieve a single record:
• If the selection condition involves an equality comparison on a key
attribute with a primary index use the primary index to retrieve the 29 30
record.
Friday, January 8, 2021
ADBMS
31 32
8
ADBMS Friday, January 8, 2021
33