14
Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

  • View
    218

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Query Execution

Chapter 15Section 15.1

Presented by Khadke, Suvarna

CS 257 (Section II) Id 213

1

Page 2: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

What is a 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

2

Page 3: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Major parts of Query processor

3

Query Execution:The algorithms that manipulate the data of the database.

Focus on the operations of extended relational algebra.

Page 4: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Outline of Query CompilationQuery compilation• Parsing : A parse tree for the query

is constructed• Query Rewrite : The parse tree is

converted to an initial query plan 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.

4

Page 5: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

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, that is, bring each tuple of some relation into main memory

5

Page 6: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

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.

6

Page 7: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Scanning TablesBasic approaches to locate the tuples of a relation RTable 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,

we can use this index to get all the tuples of Relation R

7

Page 8: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

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

8

Page 9: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

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.

9

Page 10: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Parameters for Measuring Costs

• Parameters that affect the performance of a queryBuffer space availability in the main memory

at the time of execution of the querySize of input and the size of the output

generatedThe size of memory block on the disk and the

size in the main memory also affects the performance

10

Page 11: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Parameters for Measuring Costs

• B: The number of blocks are needed to hold all tuples of relation R.

Also denoted as B(R)• T:The number of tuples in relationR. Also denoted as T(R)

V: The number of distinct values that appear in a column of a relation R

V(R, a)- is the number of distinct values of column for a in relation R

11

Page 12: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

I/O Cost for Scan Operators

• If relation R is clustered, then the number of disk I/O for the table-scan operator is = ~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 relation R which takes at least B disk I/O’s will require more I/O’s than the entire index

12

Page 13: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

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

tuplesIt initializes any data structures needed to

perform the operation

13

Page 14: Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id 213 1

Iterators for Implementation of Physical Operators

• 2. GetNext( ): Returns the next tuple in the resultIf there are no more tuples to return,

GetNext returns a special value NotFound• 3. Close( ) :

Ends the iteration after all tuplesIt calls Close on any arguments of the

operator

14