Download presentation
Presentation is loading. Please wait.
Published byΤρυφωσα Ευταξίας Modified over 6 years ago
1
Query Execution Presented by Khadke, Suvarna CS 257
Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213
2
Agenda Query Processor and major parts of Query processor
Physical-Query-Plan Operators Scanning Tables Basic approaches to locate the tuples of a relation R Sorting While Scanning Tables Computation Model for Physical Operator I/O Cost for Scan Operators Iterators
3
Query Processor Group of components of a DBMS that converts a user queries and data-modification commands into a sequence of database operations It also executes those operations Must supply detail regarding how the query is to be executed
4
Major parts of Query processor
Query execution: The algorithms that manipulate the data of the database. Focus on the operations of extended relational algebra.
5
Outline of Query Compilation
Parsing : A parse tree for the query is constructed Query Rewrite : The parse tree is converted to an initial query plan (algebraic representation of the query). And transformed into logical query plan (less time) Physical Plan Generation : Logical Q Plan is converted into physical query plan by selecting algorithms and order of execution of these operator.
6
Physical-Query-Plan Operators
Physical operators are implementations of the operator of relational algebra. They can also be use in non relational algebra operators like “scan” which scans tables.
7
Scanning Tables One of the basic thing we can do in a Physical query plan is to read the entire contents of a relation R. Variation of this operator involves simple predicate Read only those tuples of the relation R that satisfy the predicate.
8
Basic approaches to locate the tuples of a relation R
Table Scan Relation R is stored in secondary memory with its tuples arranged in blocks It is possible to get the blocks one by one Index-scan If there is an index on any attribute of Relation R Can use this index to get all the tuples of R For Example: sparse index on R
9
Sorting While Scanning Tables
Number of reasons to sort a relation Query could include an ORDER BY clause, requiring that a relation be sorted. Algorithms to implement relational algebra operations requires one or both arguments to be sorted relations. Physical-query-plan operator sort-scan takes a relation R, attributes on which the sort is to be made, and produces R in that sorted order Another reason : B-tree index on a, multiway merge-sort
10
Computation Model for Physical Operator
Physical-Plan Operator should be selected wisely which is essential for good Query Processor . For “cost” of each operator is estimated by number of disk I/O’s for an operation. The total cost of operation depends on the size of the answer and includes the final write back cost to the total cost of the query.
11
Parameters for Measuring Costs
B: The number of blocks are needed to hold all tuples of R. Also known as B(R) T:The number of tuples in R. Also known as T(R) V: The number of distinct values that appear in a column of a relation V(R, a)- is the number of distinct values of column for a in R
12
I/O Cost for Scan Operators
If relation R is clustered, then the number of disk I/O for the table-scan operator is approximately B disk I/O’s If relation R is not clustered, then the number of required disk I/O generally is much higher A index on a relation R occupies many fewer than B(R) blocks That means a scan of the entire R which takes at least B disk I/O’s will require more I/O’s than the entire index
13
Iterators for Implementation of Physical Operators
Many physical operators can be implemented as an Iterator. Three methods forming the iterator for an operation are: 1. Open( ) : This method starts the process of getting tuples It initializes any data structures needed to perform the operation
14
Iterators for Implementation of Physical Operators
2. GetNext( ): Returns the next tuple in the result Adjusts data structures as necessary to allow subsequent tuples to be obtained If there are no more tuples to return, GetNext returns a special value NotFound 3. Close( ) : Ends the iteration after all tuples It calls Close on any arguments of the operator
15
Reference ULLMAN, J. D., WISDOM J. & HECTOR G., DATABASE SYSTEMS THE COMPLETE BOOK, 2nd Edition, 2008.
16
Thank You
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.