Slow Supabase queries often trace back to complex RLS policies
Developers building apps on Supabase often find that pages load slowly once real user data accumulates, even when testing felt fast. The article argues that the frontend is rarely to blame and that Row Level Security policies are the usual cause, since Postgres can run costly lookups for every scanned row. A diagnostic is suggested: running the same query with the service_role key, which bypasses RLS, and comparing speeds. Recommended fixes include storing role or team data in JWT claims via auth hooks, moving complex permission logic into SECURITY DEFINER functions, and adding indexes on columns the policies filter by. Together these changes aim to let Postgres's query planner optimize access checks instead of repeatedly scanning tables.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in