I want to save permissions for both individual users, and user groups. In my mysql database, I have a permissions table where I store a permission name, and a permission id. I have a user table, where I store a username, password etc. which also contains an id, and I have a groups table which stores a group name and group id.
What would now be the most efficient option? To make 2 tables, one containing user permissions and one containing group permissions, so something like this:
int group id | int permission id
int user id | int permission id
or would it be better to have one table like this;
int id | int permission id | enum('user','group')
I doubt there would be much of a performance difference between your two approaches; but, as with all performance and optimization questions, feelings and guesses don’t matter, only profiled results matter. Which one will be more efficient depends on your data, your database, your access patterns, and what “efficient” means (space? time? developer effort? final monetary cost?) in your context.
That said, using two tables is a better structure as it allows you to have foreign keys from your group-permission table back to your group table and your user-permission table back to your user table. Even if it was faster in one table I’d still go with two: data integrity is more important than wasting a couple µs of processor time, I don’t see much point in quickly accessing unreliable or broken data.