Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

How to avoid large joins when determining which rows a user is authorized for?

$
0
0

Typical wep app situation: you have logged in users querying for resources exposed through an API. As a hypothetical example, company administrators quering for their employees’ time sheets:

company <- employees <- time_sheets
company <- admin

Say I wanted to get all the time sheets that I’m authorized for/I have access to as an admin of that company.

Without any optimizations, in the above I’d have to join admin with company with employees with time_sheets to determine all the time_sheets I can look at. You can see how for a wider schema the joins could add up very fast. I realize that in modern databases joins are ludicrously fast, but I’m guessing this is still a case you don’t want to completely ignore.

Is there a good solution to this? One could potentially have a separate admin to time_sheets many to many join table just to speed-up those queries, but then maintaining it might be tricky.

Any suggestions?


Viewing all articles
Browse latest Browse all 1138

Trending Articles