Skip to content

Commit

Permalink
feat: refactor code and tests to address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Nov 10, 2023
1 parent 4969e50 commit d319cd6
Show file tree
Hide file tree
Showing 3 changed files with 587 additions and 564 deletions.
13 changes: 5 additions & 8 deletions go/vt/vtgate/engine/fk_cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package engine
import (
"context"
"fmt"
"maps"

"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
Expand Down Expand Up @@ -113,7 +114,8 @@ func (fkc *FkCascade) TryExecute(ctx context.Context, vcursor VCursor, bindVars
return vcursor.ExecutePrimitive(ctx, fkc.Parent, bindVars, wantfields)
}

func (fkc *FkCascade) executeLiteralExprFkChild(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool, selectionRes *sqltypes.Result, child *FkChild, isStreaming bool) error {
func (fkc *FkCascade) executeLiteralExprFkChild(ctx context.Context, vcursor VCursor, in map[string]*querypb.BindVariable, wantfields bool, selectionRes *sqltypes.Result, child *FkChild, isStreaming bool) error {
bindVars := maps.Clone(in)
// We create a bindVariable that stores the tuple of columns involved in the fk constraint.
bv := &querypb.BindVariable{
Type: querypb.Type_TUPLE,
Expand All @@ -139,13 +141,13 @@ func (fkc *FkCascade) executeLiteralExprFkChild(ctx context.Context, vcursor VCu
if err != nil {
return err
}
delete(bindVars, child.BVName)
return nil
}

func (fkc *FkCascade) executeNonLiteralExprFkChild(ctx context.Context, vcursor VCursor, bindVars map[string]*querypb.BindVariable, wantfields bool, selectionRes *sqltypes.Result, child *FkChild) error {
func (fkc *FkCascade) executeNonLiteralExprFkChild(ctx context.Context, vcursor VCursor, in map[string]*querypb.BindVariable, wantfields bool, selectionRes *sqltypes.Result, child *FkChild) error {
// For each row in the SELECT we need to run the child primitive.
for _, row := range selectionRes.Rows {
bindVars := maps.Clone(in)
// First we check if any of the columns is being updated at all.
skipRow := true
for _, info := range child.NonLiteralInfo {
Expand Down Expand Up @@ -189,11 +191,6 @@ func (fkc *FkCascade) executeNonLiteralExprFkChild(ctx context.Context, vcursor
if err != nil {
return err
}
// Remove the bind variables that have been used and are no longer required.
delete(bindVars, child.BVName)
for _, info := range child.NonLiteralInfo {
delete(bindVars, info.UpdateExprBvName)
}
}
return nil
}
Expand Down
Loading

0 comments on commit d319cd6

Please sign in to comment.