-
Notifications
You must be signed in to change notification settings - Fork 402
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
Add support for locking clauses in SQL #7979
base: master
Are you sure you want to change the base?
Conversation
Wait, this is not a sound approach. If we compile this: SELECT name FROM "User" WHERE id = $1::uuid FOR UPDATE ... to this ... WITH
user_inh_view AS (
SELECT ... FOR UPDATE
)
SELECT name FROM user_inh_view WHERE id = $1::uuid ... PostgreSQL will lock all rows of the base table, not just the one selected by the where clause. |
Hm. Should we just document then that locking clauses only work sensibly for non-inherited types without access policies? |
That would work. But we'd have to modify code for compiling inheritance CTEs, because currently we do it unconditionally - even if object has no access policies, we call into the pg_compiler and generate inheritance views, which then turn out to be very verbose no-ops. Also when access policies are disabled, we generate inheritance CTEs unconditionally, even if it is just a select from single table. |
The decision here (that me and Elvis made yesterday) is to first support I'll start work on this. |
Ok, I've implemented our restrictions. This can be reviewed. This PR should also improve resolver & query performance, because it skips creating inheritance CTEs or access policy CTEs when they are not needed. I still have to add tests that check if locks are actually obtained as they should be. |
414eed5
to
8e2900e
Compare
This adds parsing/codegen bits. The resolver needs to learn to push the
locking_clause
down to constituent elements of the inheritance union.