Don't warn about foreign keys causing table scan when creating table in same transaction#289
Draft
andrewsmith wants to merge 3 commits intosbdchd:masterfrom
Conversation
These are used heavily elsewhere and are a little better at verifying the rule output than the hand-written assertions were.
These cover a few cases that should not cause this rule to warn because the table is being created in the same transaction as the foreign key constraint.
This addresses sbdchd#220, which claims that although an exclusive lock will be obtained on the referenced table, there are no rows in the referencing table so the table scan under the exclusive lock should be short or non-existent.
👷 Deploy request for squawkhq pending review.Visit the deploys page to approve it
|
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
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.
I started to put this together to address an extension of #220: the case where the table is created and a foreign key constraint is added in the same transaction. We use a tool that generates SQL from a language-specific mapper and it separates these into two steps:
In this case, there should be no table scan or it should be near instantaneous. I put together this change to adapt this rule to recognize this, but there are some shortcomings.
If someone were to have INSERT or COPY statements between the table creation and the foreign key addition, then the table scan becomes a real risk again. It also seems fairly intractable to determine this, as INSERT/COPY statements could be hidden in a stored procedure or function that is executed between the CREATE TABLE and ALTER TABLE commands.
Anyhow, I wanted to put this up for consideration and see if you had any thoughts on that problem. I imagine the INSERT/COPY between creation and foreign key addition would be pretty unlikely, but would cause Squawk to produce a false-negative, which is unsettling.