Repository navigation
Conversation
The parent step ran about three catalog reads per partition while it held the tree's locks, and a deadlock there failed as execution-failed. It now reads the whole tree in a fixed number of statements, and a 40P01 gets the retryable partitioned-foreign-key-deadlocked code.
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.
The last step of adding a foreign key to a partitioned table online now holds its locks for a fixed number of statements however many partitions there are, and a deadlock there gets its own retryable code.
Why
pg-sprite adds a foreign key to a partitioned table one partition at a time, then finishes with a short step on the parent that locks the referenced table and every partition while it checks each partition's key. That check ran about three catalog queries per partition, so the lock was held longer the bigger the table (about 231 ms at 400 partitions), and if the step deadlocked with another session it was reported as a generic failure, though simply running it again would have worked.
What
readKeyColumnsOf, foreign keys through a newreadForeignKeysOf, and the adopted keys through a newreadAdoptedLeafFKs. The proof rules (ST-7) are unchanged; a partition the batch returns nothing for fails closed.40P01from any statement in the parent step returnsErrPartitionedForeignKeyDeadlocked, codepartitioned-foreign-key-deadlocked,Permanent()false, with the server's error kept in the chain. The rerun adopts every partition.ACCESS SHAREon the referenced table, then inserting into the tree) returns the typed code, leaves the parent without the key and each partition's key unadopted, and a rerun adopts all of them. The deadlock test passed 10 runs under-race.Before / after
The same parent step on a 400-partition
eventstable referencingaccounts, once in the normal case and once meeting another session's transaction that readaccountsand then writes toevents.