A hand-written statement is declared once, typed both ways and prepared once
Table of Contents
1. Summary
Hand-written SQL is a statement declared once, in the repository that owns it, with typed parameters and a typed row. Its first use on a connection prepares it, and later uses execute the prepared plan. Results come back in the binary format and decode into the row type. No hand-written statement builds SQL text from values, and no caller walks a grid of optional strings.
2. Detail
2.1. The shape
struct held_row final { boost::uuids::uuid result_id; std::chrono::system_clock::time_point lease_until; }; const statement<held_row, boost::uuids::uuid> held_by{ "compute.held_by", "select result_id, lease_until from ores_compute_work_ledger_tbl " "where host_id = $1"};
A statement names itself, so the session can prepare it once per connection and report its numbers by name (Every queue and every session reports its own numbers). The row type is a flat struct, the same shape Data-Oriented Design in ORE Studio asks of data that moves in bulk.
2.2. Many keys, one statement
A read of many keys passes them as one array parameter (where id = any($1)),
so a batch is one statement and one round trip, not one statement for each key.
2.3. Through the pooler
Statements are prepared through the protocol, so a pooler in transaction mode can keep them prepared on its server connections (The environments share the database through a transaction pooler).
3. See also
- The data path — the structure note that orders this cluster.
- A repository works inside an open transaction and never holds credentials — the transaction a statement runs in.