cslib-frontier guide

6. SQL Query Semantics🔗

A query rewrite is correct when the rewritten query returns the same rows as the original on every database. Stating that requires a semantics: what a query returns, when it fails, and what NULL does. The library's SQL semantics evaluates queries in Lean, so a concrete query is checked by computation and a law about all databases is a theorem. It adapts and redesigns Evelyn Mitchell's sql_equiv.

This chapter builds a two-table database, evaluates queries over it, and applies the theorem that an equijoin returns as many rows as the join size of its keys. The manual page describes the full semantic contract.

import CslibFrontier.Languages.SQL.JoinSize
import CslibFrontier.Languages.SQL.QueryEquiv

open Cslib.SQL Cslib.SQL.Query
  1. 6.1. Schemas and Instances
  2. 6.2. Evaluation
  3. 6.3. Equijoins and Join Sizes
  4. 6.4. Equivalence