Is there an easy way to debug performance of RLS p...
# help
k
Is there an easy way to debug performance of RLS policies? My team has somehow managed to make a lookup of a table with 5 rows take >3s.
s
Recently @User tweeted out his experience around this https://twitter.com/KennethCassel/status/1451574010605707268
k
Hey @keknal! the gist is: - set
postgres
user to a superuser - connect to db as
postgres
user - run a transaction like
Copy code
sql
begin; 
set local role authenticated;
set local request.jwt.claim.sub = ''; 

EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS)
insert into lesson_contents_v2(lesson_id, properties) values (2197,
  '{
  "content": "<p>testing insert speed with rls</p>"
}'
);
commit;
these lines
Copy code
sql
set local role authenticated;
set local request.jwt.claim.sub = '';
will set you as the user who's uuid you pass in on line 2
explain
is a postgres tool for analyzing performance of queries
i'll write a more in-depth tutorial about it!
k
hey, managed to figure it out on my own a couple minutes before you replied 🙂
thanks anyways!
k
ah cool! glad you got it figured out. i wrote up a small tutorial for anyone else wondering https://www.slip.so/tutorials/row-level-security-performance-in-supabase