Relational Algebra Formalisms & SQL Query Transformation Math
SQL declarative statements correspond to relational algebra operators executed across database relations:
select * from usersSELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT.SQL Major Clauses & Execution Order Reference
| Order | Clause | Algebraic Purpose | Optimization Tip |
|---|---|---|---|
| 1 | FROM / JOIN | Identifies source tables & cross products | Join on indexed foreign keys |
| 2 | WHERE | Row filtering (Selection σ) | Filter early to minimize joined dataset |
| 3 | GROUP BY | Aggregates rows into buckets | Group by unique clustered indices |
| 4 | HAVING | Filters aggregated group records | Avoid non-aggregated conditions in HAVING |
| 5 | SELECT | Computes column projection (π) | Avoid SELECT * in production endpoints |