Idea 1: Run each plan
If we can't get the exact cost of a plan, what can we do?
Idea 2: Run each plan on a small sample of the data.
Idea 3: Analytically estimate the cost of a plan.
Figure out the cost of each individual operator.
Only count the number of IOs added by each operator.
Operation | RA | IOs Added (#pages) | Memory (#tuples) |
---|---|---|---|
Table Scan | $R$ | $\frac{|R|}{\mathcal P}$ | $O(1)$ |
Projection | $\pi(R)$ | $0$ | $O(1)$ |
Selection | $\sigma(R)$ | $0$ | $O(1)$ |
Union | $R \cup S$ | $0$ | $O(1)$ |
Sort | $\tau(R)$ | $0$ | $O(|R|)$ |
$2 \cdot \lfloor log_{\mathcal B}(|R|) \rfloor$ | $O(\mathcal B)$ | ||
Index Scan | $\sigma_c(R)$ | $\log_{\mathcal I}(|R|) + \frac{|\sigma_c(R)|}{\mathcal P}$ | $O(1)$ |
$1$ | $O(1)$ |
Operation | RA | IOs Added (#pages) | Memory (#tuples) |
---|---|---|---|
Nested Loop Join | $R \times S$ | $0$ | $O(|S|)$ |
$\frac{|S|}{\mathcal P}$ | $O(1)$ | ||
1-Pass Hash Join | $R \bowtie S$ | $0$ | $O(|S|)$ |
2-Pass Hash Join | $R \bowtie S$ | $2|R| + 2|S|$ | $O(1)$ |
Sort-Merge Join | $R \bowtie S$ | $0$ + Sort | $O(1)$ + Sort |
Index Nested Loop | $R \bowtie_c S$ | $|R| \cdot (\log_{\mathcal I}(|S|) + \frac{|\sigma_c(S)|}{\mathcal P})$ | $O(1)$ |
$|R| \cdot 1$ | $O(1)$ | ||
Aggregate | $\gamma_A(R)$ | $0$ | $adom(A)$ |
$0$ + Sort | $O(1)$ + Sort |
Next Class: How to estimate $|R|$