Menu

Why Your Supabase RLS Policies Are Slow (and 7 Fixes That Actually Work)
📰

Why Your Supabase RLS Policies Are Slow (and 7 Fixes That Actually Work)

DEV Community: database·Hugo Rus·6 days ago
#8zdnZmxu
#devtodatabase#devto#dev#policies#select
Long article (1244 words) — no AI summary yet.
Reading 0:00
15s threshold

RLS policies run as part of every query, so a policy that's fine on 1,000 rows can crawl on 1,000,000. The usual culprits: auth.uid() evaluated once per row, missing indexes on the columns policies filter by, queries without explicit filters, policies that apply to roles they don't need to, joins inside policies and several overlapping permissive policies. Measure with EXPLAIN ANALYZE as a real user, then apply the fixes below. Most are one-line changes.

RLS is the right way to secure Supabase. But because policies are invisible in your queries, their cost is invisible too, until a list screen that took 50 ms in development takes seconds in production.

How do RLS policies affect query performance?

Postgres adds your policy's using expression to every query on the table, like an extra WHERE clause.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.