Skip to content

Commit

Permalink
remove fk_verify operator, refactors the fk test
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Aug 7, 2023
1 parent e927865 commit 71c09a9
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 478 deletions.
5 changes: 2 additions & 3 deletions go/vt/vtgate/planbuilder/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ func insertUnshardedShortcut(stmt *sqlparser.Insert, ks *vindexes.Keyspace, tabl
}

type insert struct {
eInsert *engine.Insert
source logicalPlan
fkVerify logicalPlan
eInsert *engine.Insert
source logicalPlan
}

var _ logicalPlan = (*insert)(nil)
Expand Down
9 changes: 0 additions & 9 deletions go/vt/vtgate/planbuilder/operator_transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ func transformToLogicalPlan(ctx *plancontext.PlanningContext, op ops.Operator, i
return transformAggregator(ctx, op)
case *operators.Distinct:
return transformDistinct(ctx, op)
case *operators.FKVerify:
return nil, vterrors.VT12002()
}

return nil, vterrors.VT13001(fmt.Sprintf("unknown type encountered: %T (transformToLogicalPlan)", op))
Expand Down Expand Up @@ -429,13 +427,6 @@ func transformInsertPlan(ctx *plancontext.PlanningContext, op *operators.Route,
}
}

if ins.FKVerify != nil {
i.fkVerify, err = transformToLogicalPlan(ctx, ins.FKVerify, true)
if err != nil {
return
}
}

return
}

Expand Down
5 changes: 1 addition & 4 deletions go/vt/vtgate/planbuilder/operators/ast2op.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ func createOperatorFromInsert(ctx *plancontext.PlanningContext, ins *sqlparser.I
if ksMode == vschemapb.Keyspace_FK_MANAGED {
parentFKs := vindexTable.CrossShardParentFKs()
if len(parentFKs) > 0 {
insOp.FKVerify, err = NewFkVerify(ctx, parentFKs, ins.Columns)
if err != nil {
return nil, err
}
return nil, vterrors.VT12002()
}
}

Expand Down
140 changes: 0 additions & 140 deletions go/vt/vtgate/planbuilder/operators/fk_verify.go

This file was deleted.

5 changes: 0 additions & 5 deletions go/vt/vtgate/planbuilder/operators/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ type Insert struct {
// Insert using select query will have select plan as input operator for the insert operation.
Input ops.Operator

// FKVerify is required to check the validity of foreign key constraints that aren't shard scoped.
// It is nil if no verification is required.
FKVerify ops.Operator

noColumns
noPredicates
}
Expand Down Expand Up @@ -115,7 +111,6 @@ func (i *Insert) Clone(inputs []ops.Operator) ops.Operator {
ColVindexes: i.ColVindexes,
VindexValues: i.VindexValues,
VindexValueOffset: i.VindexValueOffset,
FKVerify: i.FKVerify,
}
}

Expand Down
3 changes: 2 additions & 1 deletion go/vt/vtgate/vindexes/foreign_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (t *Table) CrossShardParentFKs() (crossShardFKs []ParentFKInfo) {
if len(t.ParentForeignKeys) == 0 {
return
}
primaryVindex := t.ColumnVindexes[0]
for _, fk := range t.ParentForeignKeys {
// If the keyspaces are different, then the fk definition
// is going to go across shards.
Expand All @@ -125,8 +124,10 @@ func (t *Table) CrossShardParentFKs() (crossShardFKs []ParentFKInfo) {
if !t.Keyspace.Sharded {
continue
}

// If the primary vindexes don't match between the parent and child table,
// we cannot infer that the fk constraint in shard scoped.
primaryVindex := t.ColumnVindexes[0]
if fk.Table.ColumnVindexes[0].Vindex != primaryVindex.Vindex {
crossShardFKs = append(crossShardFKs, fk)
continue
Expand Down
Loading

0 comments on commit 71c09a9

Please sign in to comment.