Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: add support for ON UPDATE CASCADE for foreign key references
Enables the addition of the ON UPDATE CASCADE action for foreign keys references. Major changes in `rowwriter.go`: * Added a quick check to see if a cascader is required at all (this code is in `cascader.go`). And if not, the normal path is followed. * When a cascader is required, UpdateRow can only use a single batch per row. Unless we can read from batches without running them, this will be a requirement going forward. * Added the ability to skip foreign key checks for `InsertRow`. * Merge the `DeleteRow()` And `deleteRowWithoutCascade()` functions. Major changes in `cascader.go`: * Added the new `makeCascader` functions that check to see if a cascader is required at all. * Of course, added `updateRows()`, which performs all the updates. * Added the checking of foreign key constraints at the end of a `cascadeAll()` call. This of course Unlike with deletes, there is more to keep track of when looking for orphaned rows. In the wost case, rows can be updated multiple times. So row A -> B, then B -> C, then C -> D. But we don't want to test the middle states for foreign key violations, and we only want to test A -> D. So this accomplished by storing all transitions and looking forward through these updates to find if a row was updated again. There is potential to improve this using a map of some sort, but that can be done in a further update. The normal case is that there is only a single update and there is a quick path to only check that. There is also a need to compare the contents two rows. Using the example above, say after A -> B and then B -> C, there needs to be a way to determine that the first B is the equivalent of the second B. To accomplish this, a new function on `tree.Datums` `IsDistinctFrom()` was added that treats nulls as equivalent. Release note (SQL): ON UPDATE CASCADE foreign key constraints are fully supported
- Loading branch information