Permission subquery for list reads (C)
Fix C of "Large table query performance"; the evidence is in that item's note "Independent diagnosis (Fable-5-2)".
Every list read first fetches the complete set of ids the viewer may read (readable-row-ids, lisp/backend.lisp:3366), then sends that set back to Postgres as a filter in the page statement, the count statement, and one palette statement per reference target. So every request does work in proportion to the readable rows, whatever the page size and however the ids are encoded.
The ask: test the permission inside the statement. Replace the id filter with an EXISTS subquery on the RBAC tables, keyed by the row id, the user name, and the permission, so no id list is fetched or sent.
Measured on the dev database (7,730 usage rows, as admin): the page statement takes 2 ms and the count about 20 ms, where Phase A takes 3.2 s today. The predicate returned exactly the ids of the library's query in all 126 combinations compared. The note has the SQL.
This is a design item. A plan must cover:
- The predicate belongs to the rbac library; data-ui needs a function that hands it out.
- A viewer who may read none of the rows got a 107 ms page statement, because Postgres walked the index and probed every row. The count should run first and short-circuit.
- A viewer who may read a few rows of a very large table needs its own look; an index on
resource_roles (role_id)may matter there. - The other consumers of the id set:
fast-palette-values,row-capabilities, and the guest check for public URLs. - A type role does not imply read access to every row (
docs/roles.md); only row roles decide.
For list reads this supersedes the array parameter from "Readable ids as one array parameter (B)".
- Slot
- 7270
- Status
- 10 Open
- Tags
- mvp, backend, list, perf, db
- Contributors
- Donnie, Fable-5-2