-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
45520: opt: FK checks for Upsert r=RaduBerinde a=RaduBerinde These commit add support for opt-driven FK checks for UPSERT and INSERT ON CONFLICT DO UPDATE. This is a simplified and cleaned up reimplementation of #45095. There aren't a lot of logictests around FKs and upsert. I plan to try to build a randomized testing facility for FK checks, where we generate randomized mutations and cross-check FK violations or lack there of against a separate instance of the database without FK relationships. #### Revert "opt: add first half of upsert FK checks" This reverts commit 96447c8. We are reconsidering the direction of the upsert FK checks: instead of filtering inserted vs updated rows, we can use the return columns to get the "new" values. This change also made some things harder to understand: we used to build the FK check input using just the columns corresponding to the FK instead of all columns. Release note: None #### opt: refactor optbuilder FK check code The optbuilder FK check code has become unnecessarily complicated: - there are two ways of creating a WithScan (`makeFKInputScan` and `projectOrdinals`) which are similar but take different kinds of information as input. - there are various slices of column ordinals or column IDs that are threaded through long parts of code, making it hard to follow. This change cleans this up by creating a fkCheckHelper which contains the metadata related to FK table ordinals and is capable of creating a WithScan with either the "new" or the "fetched" values. The new code should generate the same effective plans; the differences are: - we now always create the WithScan before the other table Scan so some column IDs in the plan changed; - we no longer have an unnecessary projection for Update (it was used to renumber the columns coming out of WithScan). Release note: None #### opt: add outbound FK checks for upsert This is a re-implementation of Justin's change 3d1dd0f, except that we now perform the insertion check for all new rows instead of just the inserted rows. We do this by utilizing the same column that would be used for a RETURNING clause, which in some cases is of the form `CASE WHEN canary IS NULL col1 ELSE col2`. Release note: None #### opt: add inbound FK checks for upsert This change adds inbound FK checks for upsert and switches execution over to the new style FK checks for upsert. Similar to UPDATE, the inbound FK checks run on the set difference between "old" values for the FK columns and "new" values. Release note (performance improvement): improved execution plans of foreign key checks for UPSERT and INSERT ON CONFLICT in some cases (in particular multi-region). Co-authored-by: Radu Berinde <[email protected]>
- Loading branch information
Showing
14 changed files
with
3,512 additions
and
1,552 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.