Protocol specification
Remit SQL
A strict, deterministic dialect profile over sqlparser-rs (PostgreSQL
dialect), lowered to a DataFusion LogicalPlan. The reference checker
(remit-sql) is shared by the Holder and the SDKs (remit-verify-wasm).
Allowed
- A single
SELECTstatement (RMT-E0202otherwise), withWHERE,GROUP BY,HAVING,ORDER BY,LIMIT/OFFSET/FETCH,DISTINCT. INNER/JOINandLEFT [OUTER] JOIN; comma joins.- Non-recursive CTEs, derived tables and subqueries. Use
INandEXISTSsubqueries in filters. To return a boolean for whether any rows match, useSELECT COUNT(*) > 0 AS found FROM … WHERE …. - Relations named
source.tablefrom the principal's visible catalog. - Allowlisted deterministic functions: arithmetic, string, date/time
(
date_trunc,date_part,extract,date_bin,to_timestamp, …), conditional (coalesce,nullif,CASE), casts; aggregates (count,sum,avg,min,max,stddev*,var*,median,bool_and/or,corr,covar*,regr_*,string_agg,array_agg); window functions (row_number,rank,lag,lead, …). The full list isremit_sql::{SCALAR,AGGREGATE,WINDOW}_FUNCTIONS. - Named params
$name(declared in the template,RMT-E0110). - Holder search functions over catalog
indexes:fts('index', $q, k)(BM25, light stemming) andknn('index', $vector_json, k)(cosine). They return only(id, score); join back to the resource to read columns, so its policy view still applies. They need thesearchoperation (a Cedar action) on the indexed resource; indexes cover exposed, unmasked columns only. The first argument must be a string literal naming an index (RMT-E0211).
Excluded
| Construct | Code |
|---|---|
| DDL, DML, utility statements, multiple statements | RMT-E0202 |
WITH RECURSIVE | RMT-E0203 |
UNION/INTERSECT/EXCEPT | RMT-E0204 (declare a second read instead) |
now(), current_*, random(), uuid(), UDFs, qualified functions | RMT-E0205 |
RIGHT/FULL/CROSS/SEMI/ANTI joins, APPLY | RMT-E0206 |
SELECT INTO, locking, TOP, QUALIFY, LATERAL, sampling, time travel, dialect clauses | RMT-E0207 |
Positional params $1 | RMT-E0208 |
| Over-long statements (> 16 KiB) | RMT-E0210 |
Time always comes from params. Diagnostics carry a 1-based (line, column) span
when known and a hint.
Policy is enforced in the plan
Senders' SQL is planned against policy views, never raw tables:
- Hidden columns (
expose = false) and invisible resources do not exist; errors are indistinguishable from nonexistent names. - Masks (
hashkeyed by a Holder salt,null,redact,trunc:<unit>), casts, DP clamps, row filters and owner filters are part of the view and are inlined into the plan before optimization. - Aggregates over a
k-protected resource are rewritten to keep only groups withCOUNT(DISTINCT privacy_unit) ≥ k(orCOUNT(*) ≥ kwithout a privacy unit). Projecting the privacy unit away before aggregating is rejected (RMT-E0306). - Aggregate-only resources reject any plan in which a scan of them is not under
an aggregate (
RMT-E0304). max_rowsis enforced withLIMIT max_rows + 1and an error on overflow; scans are metered per remit (rows and bytes) and memory is capped by a per-remit DataFusion memory pool.
Column lineage (facts.resources[*].columns) is computed on the optimized plan
over schema-only views, so filter, join and group keys count as accessed columns,
and is independent of param values.