Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <crazycs520@gmail.com>
  • Loading branch information
crazycs520 committed Sep 28, 2022
1 parent 02c1090 commit dac9943
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
13 changes: 7 additions & 6 deletions planner/core/foreign_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func (p *Insert) buildOnDuplicateUpdateColumns() map[string]struct{} {
return m
}

func (updt *Update) buildOnUpdateFKChecks(ctx sessionctx.Context, is infoschema.InfoSchema, tblID2table map[int64]table.Table) (map[int64][]*FKCheck, error) {
func (updt *Update) buildOnUpdateFKChecks(ctx sessionctx.Context, is infoschema.InfoSchema, tblID2table map[int64]table.Table) error {
if !ctx.GetSessionVars().ForeignKeyChecks {
return nil, nil
return nil
}
tblID2UpdateColumns := updt.buildTbl2UpdateColumns()
fkChecks := make(map[int64][]*FKCheck)
Expand All @@ -88,28 +88,29 @@ func (updt *Update) buildOnUpdateFKChecks(ctx sessionctx.Context, is infoschema.
dbInfo, exist := is.SchemaByTable(tblInfo)
if !exist {
// Normally, it should never happen. Just check here to avoid panic here.
return nil, infoschema.ErrDatabaseNotExists
return infoschema.ErrDatabaseNotExists
}
updateCols := tblID2UpdateColumns[tid]
if len(updateCols) == 0 {
continue
}
referredFKChecks, err := buildOnUpdateReferredFKChecks(is, dbInfo.Name.L, tblInfo, updateCols)
if err != nil {
return nil, err
return err
}
if len(referredFKChecks) > 0 {
fkChecks[tid] = append(fkChecks[tid], referredFKChecks...)
}
childFKChecks, err := buildOnUpdateChildFKChecks(is, dbInfo.Name.L, tblInfo, updateCols)
if err != nil {
return nil, err
return err
}
if len(childFKChecks) > 0 {
fkChecks[tid] = append(fkChecks[tid], childFKChecks...)
}
}
return fkChecks, nil
updt.FKChecks = fkChecks
return nil
}

func buildOnUpdateReferredFKChecks(is infoschema.InfoSchema, dbName string, tblInfo *model.TableInfo, updateCols map[string]struct{}) ([]*FKCheck, error) {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5381,7 +5381,7 @@ func (b *PlanBuilder) buildUpdate(ctx context.Context, update *ast.UpdateStmt) (
}
updt.PartitionedTable = b.partitionedTable
updt.tblID2Table = tblID2table
updt.FKChecks, err = updt.buildOnUpdateFKChecks(b.ctx, b.is, tblID2table)
err = updt.buildOnUpdateFKChecks(b.ctx, b.is, tblID2table)
return updt, err
}

Expand Down
3 changes: 1 addition & 2 deletions planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1546,11 +1546,10 @@ func buildPointUpdatePlan(ctx sessionctx.Context, pointPlan PhysicalPlan, dbName
updatePlan.PartitionedTable = append(updatePlan.PartitionedTable, pt)
}
}
fkChecks, err := updatePlan.buildOnUpdateFKChecks(ctx, is, updatePlan.tblID2Table)
err := updatePlan.buildOnUpdateFKChecks(ctx, is, updatePlan.tblID2Table)
if err != nil {
return nil
}
updatePlan.FKChecks = fkChecks
return updatePlan
}

Expand Down

0 comments on commit dac9943

Please sign in to comment.