---
title: "Revisiting the Algebraic Foundation of Relational Data (Prela), with \"Lua as a Query Language\""
authors:
  - "Yisu Remy Wang"
  - "Paul Talma"
year: 2026
venue: "arXiv preprint (cs.DB), 29 Jul 2026; follow-up blog post \"Lua as a Query Language\" (remy.wang, Nov 2026)"
arxiv: "2607.26356"
doi: null
source: "https://arxiv.org/abs/2607.26356"
version_reviewed: "v1 (arXiv); blog post as of 2026-11-29"
topics:
  - "tarski-relation-algebra"
  - "binary-relations-as-columns"
  - "embedded-query-language"
  - "relation-composition"
  - "cps-deforestation"
  - "loop-fusion"
  - "column-stores"
  - "relational-hops"
seed_rank: 2749
seed_batch: "craft-2026-11-29"
reviewed: "2026-11-29"
pool: "languages"
relevance_score: 8
lineage: contemporary-databases
cites:
  - title: "Revisiting the Algebraic Foundation of Relational Data"
    url: "https://arxiv.org/abs/2607.26356"
    year: 2026
    arxiv: "2607.26356"
    doi: null
  - title: "Lua as a Query Language"
    url: "https://remy.wang/blog/lua-ql.html"
    year: 2026
    arxiv: null
    doi: null
  - title: "Prela (source, MIT)"
    url: "https://github.com/remysucre/prela"
    year: 2026
    arxiv: null
    doi: null
  - title: "A Relational Model of Data for Large Shared Data Banks"
    url: "https://doi.org/10.1145/362384.362685"
    year: 1970
    arxiv: null
    doi: "10.1145/362384.362685"
  - title: "A Short Cut to Deforestation"
    url: "https://doi.org/10.1145/165180.165214"
    year: 1993
    arxiv: null
    doi: "10.1145/165180.165214"
  - title: "How Good Are Query Optimizers, Really?"
    url: "https://doi.org/10.14778/2850583.2850594"
    year: 2015
    arxiv: null
    doi: "10.14778/2850583.2850594"
  - title: "Applications of Alfred Tarski's Ideas in Database Theory"
    url: "https://doi.org/10.1007/3-540-44802-0_2"
    year: 2001
    arxiv: null
    doi: "10.1007/3-540-44802-0_2"
see:
  - "2580-mil-primitives-for-querying-a-fragmented-world"
  - "2739-on-searching-transposed-files"
  - "1075-stream-fusion-from-lists-to-streams-to-nothing-at-all"
---

# Revisiting the Algebraic Foundation of Relational Data (Prela), with "Lua as a Query Language"

## One-sentence takeaway

Prela treats every column as a binary relation (row → value, ID → row) and every query as an expression in Tarski's algebra of relations: `.select` is relational composition, `.and` is a product on the shared first column, `.with` is a semijoin and `.inv` flips a relation. Because each combinator also implements a `drive`/`probe` continuation protocol, a multi-column query inlines into the same single fused loop a column store would run. The Rust prototype runs all 113 Join Order Benchmark queries in 8.68 s against DuckDB's 38.82 s, single-threaded. A November follow-up builds the same AST from Lua so that ad hoc queries skip rustc.

## Why it matters here

This is the closest published design I have seen to ano's "relational hops" and selection-as-reference. A Prela variable is a column, `movie.s(company).s(country)` reads as "movie's company's country", and foreign-key hops automatically pass through an `id2row` relation the way field access auto-dereferences a pointer. The ID→row map degenerates to the identity when keys are dense, so a hop is an array index, which is what an ECS with dense entity indices already has. The `drive`/`probe` CPS protocol is a small, copyable recipe for compiling a chain of column hops into one tight loop without writing a vectorized engine or a query compiler. The Lua front end also shows the cheap route to an interactive surface: overload operators so that host-language expressions build an AST, use host `local`s as CTEs, and run closures column-wise so the host interpreter never runs per row. The mapping to ano, ECS components and standing rules is my extrapolation; the paper is about OLAP queries.

## Key ideas

- **Binary relations all the way down.** A k-column table becomes k+1 binary relations (ID→row plus row→value per column). The row-number side is implicit, so each relation is just a vector, which is the physical layout of a column store.
- **Small operator set (Table 1).** compose `r.select(t)` = π_{r.1,t.2}(r ⋈_{r.2=t.1} t); product `r.and(t)` joins on the first column and pairs the second; predicates `.eq/.lt/.rx`; `.filt(p)`; restrict `r.with(t)` = left semijoin; `.map(f)`; `.gather(t)` for nested lists (aggregation via `.map(min)`); `.inv()`; `group_by(t)` = `t.inv().with(r.inv())`. Joins are implicit in query structure, and every subexpression is itself a valid query.
- **CPS deforestation instead of an engine.** `lhs.select(rhs).drive(k) = lhs.drive(|x,y| rhs.probe(y, |z| k(x,z)))` and `col.drive(k)` is a `for` loop. With `#[inline]` on each combinator, rustc fuses `movie.select(title.and(keyword))` into `for i in 0..n: k(m[i], (t[i], w[i]))`.
- **Control over planning.** There is no optimizer, so the user picks join order, materialization points and data structures (dense vectors, hash maps, bit sets). JOB in ~1,000 lines of Prela against ~4,000 lines of SQL, and TPC-H in ~300 against ~600. TPC-H idiomatic queries take 1.13 s against DuckDB's 1.26 s, and hand-tuned ones 0.44 s (2.86×). All runs are single-threaded on an M2 MacBook Air.
- **Lua front end (Nov 2026).** Relational operators written in Lua return AST nodes for the Rust back end. `&` is overloaded for `.and`, field access for `.select`, Lua locals act as non-materialized views, and `reduce(function(price, disc) return (price*(1-disc)):sum() end)` runs with column-typed arguments. Lua cannot overload `<`/`==`, hence `:gt`/`:eq`.

## Caveats

This is a short v1 preprint (no venue listed). The JOB speedup is mostly data representation: contiguous primary keys make ID→row the identity, and the authors could not get DuckDB to use foreign-key indexes. It is not an operator-for-operator engine comparison. Prela is single-threaded, has no optimizer and no transactional story. Every query is compiled by rustc, which can cost more than running it, and that is why the Lua path exists. Plain TAR is less expressive than Codd's algebra; `.and` is the authors' pairing extension. The Lua front end is, in the author's words, a few hours of "vibing", "pretty sloppy", on a `lua-frontend` branch, and he flags sandboxing as open. I read the full paper and the full post. The ano/ECS bridge is mine.

## Links

- arXiv abstract: https://arxiv.org/abs/2607.26356
- PDF: https://arxiv.org/pdf/2607.26356
- Lua as a Query Language (blog): https://remy.wang/blog/lua-ql.html
- Prela introduction (blog): https://remy.wang/blog/prela.html
- Prela site and tutorial: https://prela-lang.org/
- Code: https://github.com/remysucre/prela (Lua front end: https://github.com/remysucre/prela/tree/lua-frontend/rust/dyn)
- HN discussion: https://news.ycombinator.com/item?id=50683565
