-
Notifications
You must be signed in to change notification settings - Fork 330
Add ability to skip validation on postgres FK creation #244
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
Merged
josevalim
merged 4 commits into
elixir-ecto:master
from
TylerWitt:add-validation-skipping-to-postgres
Jul 6, 2020
Merged
Add ability to skip validation on postgres FK creation #244
josevalim
merged 4 commits into
elixir-ecto:master
from
TylerWitt:add-validation-skipping-to-postgres
Jul 6, 2020
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validation on FK constraints in postgres can cause large tables to stay locked for a relatively long time because it has to check all rows for valid data, while also preventing new entries. Postgres implemented a way to not validate the constraint immediately so the FK can be immediately inserted, improving concurrency, with the intention that a `VALIDATE CONSTRAINT` query will be following. The validation query uses a less expensive lock, because it only needs to check rows that existed before the constraint. This allows safer migrations, and also allows for users to clean up known violations while still enforcing the constraint for new entries. This commit implements the ability to skip validation, but it does not implement the validation query.
josevalim
reviewed
Jul 5, 2020
Co-authored-by: José Valim <[email protected]>
josevalim
reviewed
Jul 6, 2020
josevalim
reviewed
Jul 6, 2020
josevalim
reviewed
Jul 6, 2020
Member
josevalim
left a comment
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.
Two minor comments added for consistency. You will have to update the error messages after committing them though. :)
Contributor
Author
|
Done! Did you want me to squash it down too? |
Member
|
💚 💙 💜 💛 ❤️ |
zachdaniel
pushed a commit
to zachdaniel/ecto_sql
that referenced
this pull request
Sep 19, 2020
Validation on FK constraints in postgres can cause large tables to stay locked for a relatively long time because it has to check all rows for valid data, while also preventing new entries. Postgres implemented a way to not validate the constraint immediately so the FK can be immediately inserted, improving concurrency, with the intention that a `VALIDATE CONSTRAINT` query will be following. The validation query uses a less expensive lock, because it only needs to check rows that existed before the constraint. This allows safer migrations, and also allows for users to clean up known violations while still enforcing the constraint for new entries. This commit implements the ability to skip validation, but it does not implement the validation query.
jbernardo95
added a commit
to jbernardo95/ecto_sql
that referenced
this pull request
Sep 23, 2020
Validation of constraints in PostgreSQL can cause large tables to stay locked for a long time (preventing writes, because it has to check all rows in order to consider the constraint as valid. PostgreSQL has a way to get around this by first creating constraints as not valid. And then running a query to validate the constraint. The validation query does not lock the table, i.e. it can be run while allowing writes in parallel. This commit implements the ability to skip validation of constraints. It does not implement the validation query. This was inspired by elixir-ecto#244. https://www.postgresql.org/docs/current/sql-altertable.html
josevalim
pushed a commit
that referenced
this pull request
Sep 24, 2020
…te (#271) Validation of constraints in PostgreSQL can cause large tables to stay locked for a long time (preventing writes, because it has to check all rows in order to consider the constraint as valid. PostgreSQL has a way to get around this by first creating constraints as not valid. And then running a query to validate the constraint. The validation query does not lock the table, i.e. it can be run while allowing writes in parallel. This commit implements the ability to skip validation of constraints. It does not implement the validation query. This was inspired by #244. https://www.postgresql.org/docs/current/sql-altertable.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Validation on FK constraints in postgres can cause large tables to stay locked for a relatively long time because it has to check all rows for valid data, while also preventing new entries.
Postgres implemented a way to not validate the constraint immediately so the FK can be immediately inserted, improving concurrency, with the intention that a
VALIDATE CONSTRAINTquery will be following.The validation query uses a less expensive lock, because it only needs to check rows that existed before the constraint. This allows safer migrations, and also allows for users to clean up known violations while still enforcing the constraint for new entries.
This commit implements the ability to skip validation, but it does not implement the validation query.
See https://www.postgresql.org/docs/12/sql-altertable.html for more details