Skip to content

Commit

Permalink
Merge branch 'main' into fix-21337
Browse files Browse the repository at this point in the history
  • Loading branch information
ouyuanning authored Jan 26, 2025
2 parents 94acd83 + d5b8a9f commit 6c16244
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions pkg/sql/colexec/lockop/lock_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ func callNonBlocking(
return result, nil
}

// if input vec is not allnull and has null, return a copy vector without null value
func getVec(proc *process.Process, vec *vector.Vector) (*vector.Vector, error) {
if vec.HasNull() {
nulls := vec.GetNulls()
newVec := vector.NewVec(*vec.GetType())
for i := 0; i < vec.Length(); i++ {
if !nulls.Contains(uint64(i)) {
if err := vector.AppendBytes(newVec, nil, true, proc.Mp()); err != nil {
newVec.Free(proc.GetMPool())
return nil, err
}
if err := newVec.Copy(vec, int64(newVec.Length()-1), int64(i), proc.GetMPool()); err != nil {
newVec.Free(proc.GetMPool())
return nil, err
}
}
}
return newVec, nil
}
return vec, nil
}

func performLock(
bat *batch.Batch,
proc *process.Process,
Expand All @@ -174,15 +196,24 @@ func performLock(
zap.Int32("primary-index", target.primaryColumnIndexInBatch))
var filterCols []int32
// For partitioned tables, filter is not nil
if target.filter != nil {
filterCols = vector.MustFixedColWithTypeCheck[int32](bat.GetVector(target.filterColIndexInBatch))
// no function call AddLockTargetWithPartition to set target.filter, so next code is unused
/* if target.filter != nil {
srcVec := bat.GetVector(target.filterColIndexInBatch)
vec, err := getVec(proc, srcVec)
if err != nil {
return err
}
filterCols = vector.MustFixedColWithTypeCheck[int32](vec)
if srcVec != vec {
vec.Free(proc.GetMPool())
}
for _, value := range filterCols {
// has Illegal Partition index
if value == -1 {
return moerr.NewInvalidInput(proc.Ctx, "Table has no partition for value from column_list")
}
}
}
} */
locked, defChanged, refreshTS, err := doLock(
proc.Ctx,
lockOp.engine,
Expand Down Expand Up @@ -425,9 +456,19 @@ func doLock(
vec = bat.GetVector(idx)
}

var err error
if vec != nil && vec.AllNull() {
return false, false, timestamp.Timestamp{}, nil
}
if vec != nil {
inputVec := vec
if vec, err = getVec(proc, inputVec); err != nil {
return false, false, timestamp.Timestamp{}, err
}
if vec != inputVec {
defer vec.Free(proc.GetMPool())
}
}

if opts.maxCountPerLock == 0 {
opts.maxCountPerLock = int(lockService.GetConfig().MaxLockRowCount)
Expand Down

0 comments on commit 6c16244

Please sign in to comment.