Don't warn about foreign keys causing table scan when creating table in same transaction #289
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.