09 Query Eval
09 Query Eval
UVic C SC 370
✥ A page is 4k long
✥ The size of Reserves is 40 bytes long (100 tuples/page) and
spawns 1000 pages
✥ The size of Sailors is 50 bytes long (80 tuples/page) and spawns
500 pages.
✥ Also statistics:
✦ Cardinality: Number of tuples in R: N T uples(R)
✦ Size: Number of pages in R: N P ages(R)
✦ Index Cardinality: Number of distinct key values for index I:
N Keys(I)
✦ Index Size: Number of pages in index (for B-tree, number of
leaf pages): IN P ages(I)
✦ Index Height: The number of non-leaf levels in an index I:
IHeight(I)
✦ Index Range: Maximum and minimum values for the key of
an index I: ILow(I) and IM ax(I)
✥ Assume now that we have an index on hbid, sidi and the CNF
query is bid = 5 ∧ sid = 3
✥ If we know the number of different values for bid we can estimate
the reduction factor of the first conjunct
✥ But usually, the DBMS does not, so it approximates to 0.1
✥ So we can approximate this query’s selectivity as 0.01
✥ But the number of pages retrieved depends on whether the index
is clustered or not
✥ No index: scan
✥ Index, depends:
✦ it is clustered or unclustered?
✦ what is the reduction factor of the expression?
✥ Rule of thumb: for an unclustered index, if over 5% of tuples are
expected to match, then do scan
σbid=100∧rating>5
./sid=sid
Reserves Sailors
σbid=100∧rating>5 (On-the-fly)
A B
✥ Pipelining is a control strategy
✥ Results are produce one page at a time, used and then discarded