Every time you run a SQL query, the database does something remarkable before it touches a single row: it plans the query. It decides which table to scan first, which indexes to use, and in what order to join the tables. These choices can make a query run in milliseconds or hours — and they all depend on a single, surprisingly fragile question: how many rows will this step produce?
That count is called the cardinality of an intermediate result. Estimating it accurately is the job of the cardinality estimator, a component that every relational database has had since the 1970s. The first serious version appeared in IBM's System R (Selinger et al., 1979), and the core ideas — histograms and independence assumptions — have barely changed since.
The problem is that accurate cardinality estimation is open and hard. Not open in the sense that researchers haven't tried — thousands of papers have been written — but open in the sense that no system reliably gets it right. Errors compound exponentially through joins, turning a mistake into a catastrophe by the fifth table. This is the quiet crisis at the heart of every database engine.
Comments
Loading comments...