Docsity

Database Design - Query Processing - Prof. Mihai Pop, Study Guides, Projects, Research of Principles of Database Management

Partial preview of the text

Download Database Design - Query Processing - Prof. Mihai Pop and more Study Guides, Projects, Research Principles of Database Management in PDF only on Docsity!

CMSC 424 – Database design

Lecture 16

Query processing

Mihai Pop

Admin issues

• Questions about midterm?

• Questions about project?

Oracle: explain plan

delete plan_table; explain plan for select name from country where population > 10000000 ; Explained select substr(lpad(' ', level – 1) || operation || ' (' || options || ')', 1, 30) “Operation”, object_name “Object” from plan_table start with id = 0 connect by prior id = parent_id; _Operation Object


SELECT STATEMENT () TABLE ACCESS (FULL) COUNTRY_

How to think about query processing

• n(r), b(r), f(r), V(A, r), SC(A, r) – values that can be computed

without knowing what query you might run

• Think about how many results your query might retrieve

• Think about how they are organized on disk:

– sorted (A is a clustering index)

– unsorted (A is a secondary index)

• Think about how the index is organized – how many index

blocks you need to hit to find the correct answer?

• Usually think of either average or worst-case scenarios.

• When retrieving range – think about what fraction that

range represents from the total range of values in database.

Selection with Indexed Scan R.A=c

• A3: Primary index on key:

– cost = (height + 1) + 1

height+1 is needed to get to the leaves

(unsuccessful stops at the leaves)

• A4: Primary (clustering) index on non-key:

– cost = (height + 1) + 1 +  SC(A,r)/f(r) 

all tuples with the same value are clustered

• A5: Secondary (non-clustering) index

– cost = (height + 1) + 1 + SC(A,r)

tuples with the same value are scattered

– It can be very expensive

1 4 5 6 9 11 table R 1 4 5 6 9 11 3 table R 1 occurrence file  (^) size of the result: n(σ(R.A=c))=SC(A,r)=n(r) / V(A,r)

Selection with Indexed Scan R.A>=c

A6: Primary index on key: ● (^) search for A=c; then pick tuples with A >= c ● (^) cost = (height + 1) + b(r)/2 w/o a bound constant c ● (^) = -”- + n(r) (max(A,r)-c)/(max(A,r)-min(A,r))/f(r) ● (^) Primary (clustering) index on non-key: ● (^) cost = as above (all tuples with the same value are clustered) A7: Secondary (non-clustering) index ● (^) cost = (height + 1) + B-treeLeaves/2 + n(r)/2 or ● (^) = -”- + -”- + ● (^) + {1 + SC(A,r)}((max(A,r)-c) tuples with the same value are scattered can be more expensive than file scan 1 4 5 6 9 11 3 table R 1 occurrence file 1 4 5 6 9 11 table R 1 4 5 6 9 11 3 table R 1 occurrence file ● (^) size of the result: n(σ(R.A>c))= [max(A,r)-c] * n(r) / [max(A,r) - min(A,r)]