Cenk Kurtoğlu©26

Supabase performance · 5 minute read

Wrapped but still row-dependent: the RLS helper call that is re-evaluated per row

A common RLS performance pattern is to wrap a helper call in a scalar subquery so it is evaluated once: (select is_org_member(org_id)). That works only if the argument is row-independent. When the argument is a column of the very table the policy protects, the deparsed expression is a correlated SubPlan and the call happens for every candidate row.

What the catalog actually shows

PostgreSQL stores policies as expression trees in pg_policies.qual and pg_policies.with_check. Reading those columns does not execute the policy and does not read a single application row. On a PostgreSQL 17 fixture, the deparse of the bad form was:

( SELECT is_org_member(orders.org_id) AS is_org_member)

The argument orders.org_id is a column of the table the policy is attached to. Because the subquery references the outer row, the planner cannot hoist it out; it plans a correlated SubPlan. The cost is the same as calling the helper bare in the policy.

The row-independent form measured on the same fixture was:

(owner_id = ( SELECT auth.uid() AS uid))

Here the subquery has no reference to a column of the protected table and can be evaluated once. The same applies to membership checks: put the row set in an IN subquery whose inner predicate uses (select auth.uid()), rather than passing the outer row's column into a helper function.

Check M: a read-only heuristic

The free drift monitor now includes check M. It walks the deparsed policy expressions and flags a scalar subquery whose function call receives a column of that policy's own table, using pg_attribute for the column names. It reads only pg_policies, pg_class and pg_attribute; it needs no application-row access and no service_role.

M is a catalog signal, not a profiler result. It does not run EXPLAIN against your workload, does not measure execution time, and does not prove that a given plan was chosen on hosted Supabase. A flagged row is a policy worth reading; an unflagged policy is not automatically fast. The check was verified against a synthetic local PostgreSQL 17 fixture only — hosted defaults and the exact revision a project runs are outside what a public catalog query can tell you. Zero findings does not mean safe.

Where it fits in the nightly diff

This check was added after a reader pointed out that a naive bare-vs-wrapped grep misses the case where the helper is wrapped but still row-dependent. It is now part of the 13-check (A–M) read-only baseline: the nightly run reports only new fingerprints, and fails closed if credentials break instead of silently writing an empty baseline.

Get the free RLS Drift Monitor (13 checks, n8n + SQL) →

If you want a person to separate real exposure from catalog noise, that is a separate fixed-scope review: Supabase RLS Spot Check. Work starts only after payment is secured.

Related: the full 13-check catalog list · a real 10-row output from the synthetic fixture.

Free entry

If you would rather run these checks yourself

Honest limit: a catalog check is not proof of a leak, and an empty log is not proof the key was never used. Zero findings does not mean safe. If you want a human: $29 self-run kit · $95 spot check (five tables, one working day) · $195 full audit — work starts only after payment is secured.

Template bundle

Review all 20 frontend starters in one bundle

20 editable frontend starters with live demos are $79 — one payment, no subscription.

View the Bundle — $79↗