- Query Optimization
Given n input tables A,B,C,… that a SQL query combines by binary joins, query optimization is the problem of finding, among all possible query plans, one with minimal total cost. A plan is a parenthesised expression such as… §
A binary tree with n leaves has n−1 inner nodes; the number of tree shapes is the Catalan number Cn−1, with Cm=m+11(m2m) (C1,…,C5=1,2,5,14,42). With the tables assigned to the leaves there… §
- Relational Algebra
A sequence of operations can be written as a list of assignments, as one nested expression, or as a tree (leaves = input tables, inner nodes = operations, root = result); see Query Plan. §
- Relational Model
The operations on tables (Relational Algebra: projection, selection, Cartesian Product, Join, Grouping) take tables and return a table, so they can be composed into query plans. SQL references columns by name cj; the formal operations r… §
- SQL Query Structure
“Cross-product, then filter, then pick columns” defines what the query returns, not how an RDBMS computes it. Computing the full Cartesian product of several tables is far too expensive; the RDBMS chooses a cheaper equivalent Query Plan (s… §
- VL04 – Query Planning Basics
A single SQL query has many sequences of operations that compute its result. Regarding the result they are all equivalent (up to a permutation of the columns), but their processing time can differ greatly (Slide 19). Choosing a good sequen… §
The scratchpad links the Query Plan note under “Query planning”. Its content goes beyond this lecture and is covered in Lecture 6 (see Query Optimization): §
- VL05 – Joins and more SQL
Cartesian product vs. join (Slide 9). The query above can be evaluated by two query plans in the operations of Relational Algebra: §
These estimates extend the per-operation cost model of query plans from Lecture 4. §
- VL06 – Indexing, Query Optimization, ACID
Recap (Slide 13). A query plan is a sequence of operations that computes the result table from the input tables. Its cost is estimated per operation from the size estimates of its inputs (Lectures 4 and 5, ES4 and ES5). Goal now: find the… §
Query Plan — plans as parenthesised expressions / binary trees with the total-cost function §
- SQL and Query Planning
Query Plan — a sequence/expression/tree of operations with its estimated total cost §
Cost models by lecture. All of them are sums over the operations of a Query Plan, with sizes propagated from the leaves: §