I am looking for a schema to give to "fruits" permission by:
- User
- Group
- User and Group simultaneously. I mean "OR" "AND"
The idea is to get the best performace to do that relationship.
I am looking for a schema to give to "fruits" permission by:
The idea is to get the best performace to do that relationship.
The idea is to get the best performace to do that relationship.
Is that the idea? Or is the idea to do it correctly? There are infinitely many fast solutions to incorrect results.
The problem you pose, by the way, is pervasive in security: how to characterize groups for authorization. The groups are hard to define and harder to administer.
If the id
for users and groups are taken from the same domain -- that is, no user id is also a a group id -- then you can use the union of user and groups. If groups can also be group members (not you've as shown), you have a recursive definition, which SQL supports. You can then query a recursive view for permission membership. Now all you need is a simple table to reflect them:
create table permissions (
int member_id not null -- user or group,
char permission not null
check permission in ('R', 'W', 'X') -- or whatever
);
If users and groups are in distinct domains, the query is the same, but the view and the permission table both need an additional column to reflect whether it's a user or group.