Query optimization
Problems
- Access path selection
Choose for each relation of a query between a full scan and the indexes that match its predicates, by their estimated cost, and keep the cheapest path for each interesting order.
core - Join ordering problem
Choose the order and the tree shape in which to join n relations so that the estimated cost is least. NP-hard in general; polynomial for tree queries with ASI costs.
core - Query optimization problem
Given a declarative query, find an equivalent execution plan with the least estimated cost. Optimizers combine rewrite rules with a cost-based search over join orders and methods.
core - Cardinality estimation
Estimate the number of tuples that a query or subplan returns, from statistics, samples or sketches, without running it. Errors grow fast with the number of joins.
advanced - Multiple-query optimization
Optimize a batch of queries together, so that a subexpression common to several queries is computed once and shared. The problem is NP-hard; practical methods are heuristics.
advanced - Parametric query optimization
Given a query whose cost depends on parameters unknown at compile time, find a set of plans and a rule that picks, for each parameter value, a plan that is optimal for it.
advanced - View selection problem
Choose which views to materialize so that a query workload runs fastest within a budget. In the data cube lattice, greedy gets at least 1 - 1/e of the best benefit.
1 languagesadvanced
Algorithms
- Greedy operator ordering
A join ordering heuristic that repeatedly joins the two current subplans whose join has the smallest estimated result.
1 languagescore - System R join enumeration
Find the cheapest left-deep join plan by dynamic programming over subsets of relations, keeping one plan per interesting order. The optimizer of System R (1979).
1 languagescore - Cascades optimization framework
A rule-driven top-down optimizer that explores groups of equivalent expressions in a memo with tasks, promises and branch-and-bound pruning.
1 languagesadvanced - DPccp
Dynamic programming for join ordering that enumerates exactly the connected subgraph and complement pairs of the query graph.
1 languagesadvanced - Guaranteed-error estimator
Estimate the number of distinct values in a column from r random rows of n. Its bias is at most a factor 1 + sqrt(n/r), the order of the lower bound for every estimator that reads r rows.
1 languagesadvanced - HRU greedy view selection
Choose views of a data cube lattice one at a time by largest benefit. The greedy benefit is at least (e - 1)/e, about 63 percent, of the optimal benefit, for a fixed number k of views.
1 languagesadvanced - IKKBZ algorithm
Find the optimal left-deep join order without cross products for an acyclic query graph and an ASI cost, in polynomial time.
1 languagesadvanced - Volcano optimizer generator
Generate an optimizer from algebraic rules and physical properties that searches plans top down by dynamic programming with memoization.
1 languagesadvanced - DPhyp
An extension of DPccp to query hypergraphs, which handles complex join predicates and the reordering of outer joins.
1 languagesresearch - Eddies
An eddy sends each tuple through the filters and joins of a query in an order it chooses per tuple, from what it sees at run time. With timestamped SteMs, every order gives the same result.
1 languagesresearch - Wander join
Estimate SUM or COUNT over a join by random walks through the indexes. Each walk is divided by its probability, so it is an unbiased estimate, and a failed walk counts as 0.
1 languagesresearch
Data structures
- Histogram (database statistics)
A few buckets that summarize the value distribution of a column. The optimizer reads them to estimate the selectivity of equality and range predicates.
1 languagescore
Techniques
- Predicate pushdown
Rewrite a query plan so that each selection runs as early as the algebraic laws allow: below joins, projections and outer joins on the preserved side.
1 languagesintro - Subquery unnesting
Rewrite a correlated nested subquery as a join or an outer join with grouping, so that it is evaluated once instead of once per row.
1 languagescore - Eager aggregation
Move a grouping below a join when the conditions of Yan and Larson hold, so the join works on fewer rows.
1 languagesadvanced - Mid-query re-optimization
Count the rows at checkpoints while a plan runs, and optimize the rest of the query again when a count is far from its estimate, reusing the results already computed.
advanced - Learned cardinality estimation
Train a model, on executed queries or on the data itself, to predict the result sizes of queries in place of histograms and independence. Its accuracy is measured, not proved.
research - Learned query optimization
Choose join orders, whole plans or optimizer hints with a model trained on the measured latency of executed plans. The gains are measured on benchmarks; there is no guarantee.
research - Pessimistic cardinality estimation
Use a guaranteed upper bound on the size of a join, computed from sizes and maximum degrees of the relations, in place of an estimate. The bound never underestimates, but it can be loose.
research
Concepts
- Query plan
A tree of operators that computes a query. A logical plan uses algebra operators; a physical plan names the algorithm and access path for each one.
1 languagesintro - Selectivity
The fraction of tuples that satisfy a predicate. Optimizers estimate it from statistics, and assume independence and uniformity when they lack better data.
intro - Attribute value independence assumption
The assumption that predicates on different columns are independent, so the selectivity of a conjunction is the product of their selectivities. With correlated columns it underestimates.
core - Interesting orders
Sort orders of intermediate results that a later join, grouping or ORDER BY can use, which a plan enumerator keeps alongside cost.
core - Left-deep and bushy join trees
The shapes of join plans: a left-deep tree has a base relation as each inner input, a bushy tree may join two intermediate results.
core - Query cost model
A formula that gives each physical query plan a number, mostly page I/O plus a weighted CPU term, so that the optimizer can compare plans without running them.
core
Theorems
- Equivalence rules of relational algebra
Laws such as join commutativity, associativity and the pushing of selections and projections, which let an optimizer rewrite a plan. Some hold for sets only, others for sets and bags.
core - Exponential propagation of estimation errors
If each frequency that a join size estimate uses is off by at most a factor 1 + e, the estimate for a join of n relations is off by at most (1 + e)^n, and this bound is reached.
advanced - NP-hardness of join ordering
Finding an optimal join order is NP-hard in general, while for tree queries under an ASI cost function it is polynomial.
advanced