1What are the main stages of query processing?
parse convert optimize execute
2What does the optimizer do?
chooses the best query plan based on cost
3What is a logical query plan?
relational algebra representation of a query
4What is a physical query plan?
actual execution strategy with algorithms
5What determines the best query plan?
estimated cost and statistics
6What is the goal of query optimization?
minimize intermediate result size
7What is a key optimization rule?
push selections down
8What is another optimization rule?
push projections down
9Why push selections early?
reduces number of tuples processed
10Why push projections early?
reduces number of attributes processed
11What are transformation rules?
rules that preserve query equivalence
12What are the three main evaluation techniques?
indexing iteration partitioning
13What is indexing used for?
fast retrieval using conditions
14What is iteration?
scanning tuples sequentially
15What is partitioning?
divide data into smaller parts using hashing or sorting
16What is a one-pass algorithm?
process data in one scan
17What is a two-pass algorithm?
requires two scans of data
18What is a multi-pass algorithm?
requires multiple scans for large data
19What limits one-pass algorithms?
data must fit in memory
20When can one-pass join be used?
when smaller relation fits in memory
21Memory requirement for one-pass join?
M ≥ B(S) + 1
22I/O cost of one-pass join?
B(R) + B(S)
23Condition for duplicate elimination one-pass?
result must fit in memory
24I/O cost of duplicate elimination one-pass?
B(R)
25Condition for group by one-pass?
number of groups fits in memory
26What is a blocking operator?
must process all input before output
27What is a non-blocking operator?
can output tuples immediately
28Examples of blocking operators?
group by sorting
29Examples of non-blocking operators?
selection projection join
30What happens in pass 1 of external sort?
read M blocks sort write runs
31What happens in pass 2?
merge sorted runs
32Constraint for two-pass sort?
B(R) ≤ M²
33I/O cost of two-pass sort?
3B(R)
34Steps of sort-merge join?
sort both relations then merge join
35I/O cost of sort-merge join?
3(B(R)+B(S))
36What is the main idea of hash-based algorithms?
partition then process each partition
37What happens in pass 1?
partition data using hash function
38What happens in pass 2?
process each bucket independently
39Condition for two-pass hashing?
each bucket fits in memory
40Constraint formula?
B(R) < M²
42What is required for hash join?
same hash function on join key
43What happens after partitioning?
join matching buckets
44I/O cost of hash join?
3(B(R)+B(S))
45Constraint for hash join?
smaller relation fits in memory per partition
46What is B(R)?
number of blocks in relation
47What is T(R)?
number of tuples
48What is V(R,A)?
number of distinct values of attribute A
49Equality selection size?
T(R)/V(R,A)
50Range selection size?
T(R)/3 if unknown distribution
51Inequality selection size?
T(R)
52AND condition estimation?
multiply fractions
53OR condition estimation?
sum or probabilistic formula
54Formula for join size?
T(R) × T(S) / max(V(R,Y), V(S,Y))
55What assumption is used?
uniform distribution