The SQL editor runs as postgres with no timeout. API requests run as anon (3s) or authenticated (8s). A count: 'exact' through RLS on 600k rows counts every row and checks the policy on each, that doesn't finish in 8s on small compute.
Options:
- Use
count: 'estimated'for big numbers. It uses the planner's estimate above a threshold and an exact count for small tables. Showing "about 600k leads" is fine. - Make sure the policy column is indexed and uses
(select auth.uid()). - If you really need exact counts, keep a counter (trigger or a nightly job) in a small table.
You can raise the timeout (alter role authenticated set statement_timeout = '15s';), but that just lets a slow query be slow for longer.