-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHI-1855: Refactor HRM SQL to use a composable function for selecting a full contact #444
base: master
Are you sure you want to change the base?
Conversation
) media ON true | ||
$$ | ||
LANGUAGE SQL | ||
STABLE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking the functions 'STABLE' should mean that the Postgres query planner should be able to optimise it's query plan for the whole query, taking the logic inside the function and the logic of the calling statement and treating it as one big query, meaning it shouldn't be any less performant than not using a function
Feeling like I get the idea here, but I have a few questions, maybe you can answer in a short meeting if you don't mind, but I will write them here so I don't forget.
|
@GPaoloni - the point of this is to demonstrate a different way of encapsulating & reusing SQL that can be used in combination with client side techniques we currently use or ones we could potentially use with Knex. So for example, instead of attaching the same extra WHERE clause to lots of different queries on the client to enforce SQL level permissions, we can create a function that implements the same logic and use that in the queries instead. To answer your specific questions:
Happy to talk more on a call tho! |
So any further thoughts? Merge or no merge? @robert-bo-davis @murilovmachado |
What are the primary benefits you see in moving this abstraction into postgres functions? Does that benefit outweigh the cognitive load of the developer having to think about "does this happen in our data access layer or is is based on some SQL that is hidden away in a stored function somewhere?" My gut reaction is that this muddles data retrieval sql generation responsibilities in a way that will end up being more difficult to understand and maintain in the future as complexity grows than generating the SQL (or using a query builder) in the data access layer would be, but I don't have any well researched arguments to back that up. |
The 2 main benefits I see are
I'm not proposing we move loads of business logic into functions, just the highly reused filters & joins, i.e. those case when the times we DON'T want to apply this logic are the exception (permissions being a good example). I used the 'full contact join' for the example because we always do those joins when we select a contact in the current data access logic
|
Description
A POC PR as part of investigating permissions changes that might be required for case merging - so just for consideration & discussion rather than something that I absolutely want to merge
This PR refactors our contact selection logic to use a PostgreSQL function to encapsulate the repeated selection relationship logic in a reusable way.
This does 3 things:
Checklist
Related Issues
CHI-1855
Verification steps
Automated tests