Projection ($\pi$)
Key Attribute:
Non-key Attribute:
Selection ($\sigma$)
单点/区间查询
- Linear Search (No index, unsorted data)
- Binary Search (No index, sorted data)
- Works for point query (e.g., $\sigma_\text{age=21}$)
- Works for range query (e.g., $\sigma_\text{age>21}$)
- Using index (e.g., B+ tree)
- Flexible: Can create B+ tree index on key/non-key, sorted/unsorted attributes
使用优先级:
- Index (if indexed)
- (else) Binary Search (if sorted)
- (else) Linear Search
复合查询(多条件)
考虑:$\sigma_\text{age < 25 AND gender = F}\ (\text{students})$
如果只有 age 有 index:
- 先按 age 的 index 搜一遍
- 再对新表筛选 gender = F