Skip to content

perf(rls): wrap auth.uid() in (select ...) for per-statement evaluation - #13

Open
dmitrymaranik wants to merge 1 commit into
firecrawl:mainfrom
dmitrymaranik:perf/wrap-rls-initplan
Open

perf(rls): wrap auth.uid() in (select ...) for per-statement evaluation#13
dmitrymaranik wants to merge 1 commit into
firecrawl:mainfrom
dmitrymaranik:perf/wrap-rls-initplan

Conversation

@dmitrymaranik

Copy link
Copy Markdown

Closes #12.

The RLS policies call auth.uid() directly in USING/WITH CHECK, which Postgres re-evaluates once per row. This wraps each call in (select auth.uid()) so the planner evaluates it once per statement (an InitPlan) and caches it -- the Supabase-documented RLS perf pattern.

  • Predicate-equivalent -- (select auth.uid()) returns the same value, so row visibility is unchanged.
  • Verified with pgrls: the PERF001 findings clear to 0 after the change, with nothing else altered.
  • Added as a new migration (20260628000000_wrap_rls_perf_initplan.sql); the SQL is pgrls fix --rule PERF001 output.

Happy to adjust the migration filename/placement to your conventions.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

@dmitrymaranik is attempting to deploy a commit to the Firecrawl Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RLS perf: wrap auth.uid() in (select ...) for per-statement evaluation

1 participant