-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Online foreign key support #141
Conversation
e3c2f91
to
8611c63
Compare
@@ -1970,23 +1986,77 @@ func (a *attachPartitionSQLVertexGenerator) GetDeleteDependencies(_ schema.Table | |||
return nil, nil | |||
} | |||
|
|||
func buildForeignKeyConstraintDiff(fsg *foreignKeyConstraintSQLVertexGenerator, addedTablesByName map[string]schema.Table, old, new schema.ForeignKeyConstraint) (foreignKeyConstraintDiff, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This aligns more with the new paradigm of sql vertex generators: the diff function should call into the sql vertex generator (if possible) to reduce duplicated logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Couple comments non-blocking
// buildChildrenByPartitionedIndexNameMap builds a map of indexes by their parent index name. This map will include | ||
// all descendents, not just direct descendents. For example, if foobar idx has 5 children and each of those children | ||
// has 5 children, the slice for foobar index wil contain 30 indexes (the 5 direct children and the 25 "grandchildren") | ||
func buildChildrenByPartitionedIndexNameMap(indexes []schema.Index) map[string][]schema.Index { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: Could this function be a fair amount simpler with a findRoot(node, nodesByParent) helper? You avoid having to reason about popping/pushing onto currentNodes too.
- Build childrenByDirectParent map
- For each index, call
findRoot(index, childrenByDirectParent)
- Add child to root entry in output map
Optionally you could memoize findRoot if you care about performance
@@ -1970,23 +1986,77 @@ func (a *attachPartitionSQLVertexGenerator) GetDeleteDependencies(_ schema.Table | |||
return nil, nil | |||
} | |||
|
|||
func buildForeignKeyConstraintDiff(fsg *foreignKeyConstraintSQLVertexGenerator, addedTablesByName map[string]schema.Table, old, new schema.ForeignKeyConstraint) (foreignKeyConstraintDiff, bool, error) { | |||
if _, isOnNewTable := addedTablesByName[new.OwningTable.GetName()]; isOnNewTable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does addedTablesByName include the case where the owning/referencing tables are themselves recreated? Or is it only net new tables?
Description
Online foreign key support via
VALIDATE
.Unfortunately, it is not possible to add
NOT VALID
constraints to partitioned tables, so this strategy can only work when adding foreign keys to normal tables. It does work on partitions, so if a user really wanted to add foreign key constraints safely on a partitioned table, they could just add n foreign key constraints, one per partition, rather than just 1.Motivation
Fixes #97
Testing
Tested via acceptance tests