Skip to content

Commit 0146174

Browse files
committed
addressed some review comments
1 parent d319c72 commit 0146174

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

sql/analyzer/apply_foreign_keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ func applyForeignKeysToNodes(ctx *sql.Context, a *Analyzer, n sql.Node, cache *f
122122
if plan.IsEmptyTable(n.Child) {
123123
return n, transform.SameTree, nil
124124
}
125-
// TODO: UPDATE JOIN can update multiple tables. Because updatableJoinTable does not implement
126-
// sql.ForeignKeyTable, we do not currenly support FK checks for UPDATE JOIN statements.
127125
updateDest, err := plan.GetUpdatable(n.Child)
128126
if err != nil {
129127
return nil, transform.SameTree, err
@@ -459,6 +457,8 @@ func getForeignKeyRefActions(ctx *sql.Context, a *Analyzer, tbl sql.ForeignKeyTa
459457
return fkEditor, nil
460458
}
461459

460+
// getForeignKeyHandlerFromUpdateDestination creates a ForeignKeyHandler from a given UpdatableTable. It's used in
461+
// applying foreign keys to Update nodes
462462
func getForeignKeyHandlerFromUpdateDestination(updateDest sql.UpdatableTable, ctx *sql.Context, a *Analyzer,
463463
cache *foreignKeyCache, fkChain foreignKeyChain, originalNode sql.Node) (*plan.ForeignKeyHandler, error) {
464464
fkTbl, ok := updateDest.(sql.ForeignKeyTable)

sql/analyzer/assign_update_join.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func modifyUpdateExprsForJoin(ctx *sql.Context, a *Analyzer, n sql.Node, scope *
3434
return n, transform.SameTree, nil
3535
}
3636

37+
n.IsJoin = true
3738
updateTargets, err := getUpdateTargetsByTable(us, jn)
3839
if err != nil {
3940
return nil, transform.SameTree, err

sql/plan/update_join.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
)
2222

2323
type UpdateJoin struct {
24-
UpdateTargets map[string]sql.Node
24+
updateTargets map[string]sql.Node
2525
UnaryNode
2626
}
2727

2828
// NewUpdateJoin returns a new *UpdateJoin node.
2929
func NewUpdateJoin(updateTargets map[string]sql.Node, child sql.Node) *UpdateJoin {
3030
return &UpdateJoin{
31-
UpdateTargets: updateTargets,
31+
updateTargets: updateTargets,
3232
UnaryNode: UnaryNode{Child: child},
3333
}
3434
}
@@ -55,7 +55,7 @@ func (u *UpdateJoin) DebugString() string {
5555
// GetUpdatable returns an updateJoinTable which implements sql.UpdatableTable.
5656
func (u *UpdateJoin) GetUpdatable() sql.UpdatableTable {
5757
return &UpdatableJoinTable{
58-
UpdateTargets: u.UpdateTargets,
58+
UpdateTargets: u.updateTargets,
5959
joinNode: u.Child.(*UpdateSource).Child,
6060
}
6161
}
@@ -66,7 +66,7 @@ func (u *UpdateJoin) WithChildren(children ...sql.Node) (sql.Node, error) {
6666
return nil, sql.ErrInvalidChildrenNumber.New(u, len(children), 1)
6767
}
6868

69-
return NewUpdateJoin(u.UpdateTargets, children[0]), nil
69+
return NewUpdateJoin(u.updateTargets, children[0]), nil
7070
}
7171

7272
func (u *UpdateJoin) IsReadOnly() bool {
@@ -79,7 +79,7 @@ func (u *UpdateJoin) CollationCoercibility(ctx *sql.Context) (collation sql.Coll
7979
}
8080

8181
func (u *UpdateJoin) GetUpdaters(ctx *sql.Context) (map[string]sql.RowUpdater, error) {
82-
return getUpdaters(u.UpdateTargets, ctx)
82+
return getUpdaters(u.updateTargets, ctx)
8383
}
8484

8585
func getUpdaters(updateTargets map[string]sql.Node, ctx *sql.Context) (map[string]sql.RowUpdater, error) {

0 commit comments

Comments
 (0)