ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseโ€ข4y agoโ€ข
6 replies
psteinroe

Storage RLS Performance Index not used with RLS enabled

Hey everyone,

I am having major struggles with the query performance of the storage.objects table and cannot get my head around it. Any help is highly appreciated.

We are providing a multi-tenant solution where different entities can have files attached. To easily query them on different levels, we enforce the following directory structure:
organisation-id/entity-id/myfile.jpg
organisation-id/entity-id/myfile.jpg


In some cases, we also have one more level, e.g. for conversation with messages, we want to attach files to a message but also query all files of a conversation:
organisation-id/conversation-id/message-id/myfile.jpg
organisation-id/conversation-id/message-id/myfile.jpg
.

To query files for an entity, we use the following query (simplified):
select id
from storage.objects
where bucket_id = 'message_files'
and uuid_from_path_level_2(name) = '7daa4a53-1233-432d-bf11-a9dee8140027'::uuid;
select id
from storage.objects
where bucket_id = 'message_files'
and uuid_from_path_level_2(name) = '7daa4a53-1233-432d-bf11-a9dee8140027'::uuid;


For a better performance, we setup a bunch of indices, and when executed as service_role (bypassing rls), the indices are properly picked up (Visualised on explain.dalibo).
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Performance issues with RLS
SupabaseSSupabase / help-and-questions
6mo ago
Python: Insertion with RLS enabled
SupabaseSSupabase / help-and-questions
14mo ago
RLS Enabled logs
SupabaseSSupabase / help-and-questions
2mo ago
Storage RLS Template not working
SupabaseSSupabase / help-and-questions
13mo ago