Skip to content

Commit

Permalink
check fks on all update target tables
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Mar 6, 2024
1 parent 048d303 commit 1e3d3ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions go/vt/vtgate/planbuilder/operators/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ func (u *Update) ShortDescription() string {

func createOperatorFromUpdate(ctx *plancontext.PlanningContext, updStmt *sqlparser.Update) (op Operator) {
errIfUpdateNotSupported(ctx, updStmt)
parentFks := ctx.SemTable.GetParentForeignKeysList()
childFks := ctx.SemTable.GetChildForeignKeysList()
var parentFks []vindexes.ParentFKInfo
for _, ts := range ctx.SemTable.GetSortedTargets() {
parentFks = append(parentFks, ctx.SemTable.GetParentForeignKeysForTableSet(ts)...)
}
var childFks []vindexes.ChildFKInfo
for _, ts := range ctx.SemTable.GetSortedTargets() {
childFks = append(childFks, ctx.SemTable.GetChildForeignKeysForTableSet(ts)...)
}

// We check if dml with input plan is required. DML with input planning is generally
// slower, because it does a selection and then creates a update statement wherein we have to
Expand Down
10 changes: 10 additions & 0 deletions go/vt/vtgate/semantics/semantic_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ func (st *SemTable) GetChildForeignKeysForTable(tableName sqlparser.TableName) [
return st.childForeignKeysInvolved[st.Targets[tableName.Name]]
}

// GetChildForeignKeysForTableSet gets the child foreign keys as a list for the specified TableSet.
func (st *SemTable) GetChildForeignKeysForTableSet(ts TableSet) []vindexes.ChildFKInfo {
return st.childForeignKeysInvolved[ts]
}

// GetChildForeignKeysList gets the child foreign keys as a list.
func (st *SemTable) GetChildForeignKeysList() []vindexes.ChildFKInfo {
var childFkInfos []vindexes.ChildFKInfo
Expand All @@ -203,6 +208,11 @@ func (st *SemTable) GetChildForeignKeysList() []vindexes.ChildFKInfo {
return childFkInfos
}

// GetParentForeignKeysForTableSet gets the parent foreign keys as a list for the specified TableSet.
func (st *SemTable) GetParentForeignKeysForTableSet(ts TableSet) []vindexes.ParentFKInfo {
return st.parentForeignKeysInvolved[ts]
}

// GetParentForeignKeysList gets the parent foreign keys as a list.
func (st *SemTable) GetParentForeignKeysList() []vindexes.ParentFKInfo {
var parentFkInfos []vindexes.ParentFKInfo
Expand Down

0 comments on commit 1e3d3ee

Please sign in to comment.