Should account_id have an index by default? #62
ianschmitz
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When generating a protected table using the CLI it generates a table including the following:
with sample RLS policies:
My understanding is this policy restricts a select statement on this table to only the rows where the
account_id
is in the set of accounts the user belongs to. This is effectively the same as doing:Meaning from a query planner perspective it would be much more performant to have an index on
account_id
so we can quickly filter the table down to the results that are in the account set, rather than having to do a table scan.I believe an index should be created by default on the
account_id
column. That column seems pretty logical, and perhapscreated_by
?An idea could be to have an index created for
account_id
by default, and have a commented out version of acreated_by
index that could be used if they are commonly filtering on "my rows" as opposed to the "accounts's rows". Thoughts?Beta Was this translation helpful? Give feedback.
All reactions