diff --git a/planner/core/foreign_key.go b/planner/core/foreign_key.go index b628687869762..651bd5b897e4a 100644 --- a/planner/core/foreign_key.go +++ b/planner/core/foreign_key.go @@ -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) @@ -88,7 +88,7 @@ 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 { @@ -96,20 +96,21 @@ func (updt *Update) buildOnUpdateFKChecks(ctx sessionctx.Context, is infoschema. } 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) { diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 84bd3c2322f50..4b864a00deb8c 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -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 } diff --git a/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index a5506fa1e660f..e33c16d3923a1 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -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 }