Skip to content

Commit

Permalink
cherry pick pingcap#30290 to release-5.3
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
tiancaiamao authored and ti-srebot committed Dec 3, 2021
1 parent 83b273a commit 5904d97
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ type executorBuilder struct {
// isStaleness means whether this statement use stale read.
isStaleness bool
readReplicaScope string
<<<<<<< HEAD
=======
inUpdateStmt bool
inDeleteStmt bool
inInsertStmt bool
>>>>>>> 4fbbd5a77... executor: make projection executor unparallel for insert/update/delete (#30290)
}

// CTEStorages stores resTbl and iterInTbl for CTEExec.
Expand Down Expand Up @@ -793,6 +799,7 @@ func (b *executorBuilder) buildSetConfig(v *plannercore.SetConfig) Executor {
}

func (b *executorBuilder) buildInsert(v *plannercore.Insert) Executor {
b.inInsertStmt = true
if v.SelectPlan != nil {
// Try to update the forUpdateTS for insert/replace into select statements.
// Set the selectPlan parameter to nil to make it always update the forUpdateTS.
Expand Down Expand Up @@ -1416,6 +1423,12 @@ func (b *executorBuilder) buildProjection(v *plannercore.PhysicalProjection) Exe
if int64(v.StatsCount()) < int64(b.ctx.GetSessionVars().MaxChunkSize) {
e.numWorkers = 0
}

// Use un-parallel projection for query that write on memdb to avoid data race.
// See also https://github.com/pingcap/tidb/issues/26832
if b.inUpdateStmt || b.inDeleteStmt || b.inInsertStmt || b.hasLock {
e.numWorkers = 0
}
return e
}

Expand Down Expand Up @@ -1924,6 +1937,7 @@ func (b *executorBuilder) buildSplitRegion(v *plannercore.SplitRegion) Executor
}

func (b *executorBuilder) buildUpdate(v *plannercore.Update) Executor {
b.inUpdateStmt = true
tblID2table := make(map[int64]table.Table, len(v.TblColPosInfos))
multiUpdateOnSameTable := make(map[int64]bool)
for _, info := range v.TblColPosInfos {
Expand Down Expand Up @@ -1996,6 +2010,7 @@ func getAssignFlag(ctx sessionctx.Context, v *plannercore.Update, schemaLen int)
}

func (b *executorBuilder) buildDelete(v *plannercore.Delete) Executor {
b.inDeleteStmt = true
tblID2table := make(map[int64]table.Table, len(v.TblColPosInfos))
for _, info := range v.TblColPosInfos {
tblID2table[info.TblID], _ = b.is.TableByID(info.TblID)
Expand Down

0 comments on commit 5904d97

Please sign in to comment.