Skip to content

Commit

Permalink
Fix panic: out of range in EvalExpression.go (matrixorigin#16885)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyan1 authored Jun 14, 2024
1 parent 7622383 commit 7ced499
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/sql/colexec/evalExpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ func (expr *FunctionExpressionExecutor) EvalIff(proc *process.Process, batches [
if err != nil {
return err
}
if len(expr.selectList1) < batches[0].RowCount() {
expr.selectList1 = make([]bool, batches[0].RowCount())
expr.selectList2 = make([]bool, batches[0].RowCount())
rowCount := batches[0].RowCount()
if len(expr.selectList1) < rowCount {
expr.selectList1 = make([]bool, rowCount)
expr.selectList2 = make([]bool, rowCount)
}

for i := range expr.selectList1 {
for i := 0; i < rowCount; i++ {
b, null := vector.GenerateFunctionFixedTypeParameter[bool](expr.parameterResults[0]).GetValue(uint64(i))
if selectList != nil {
expr.selectList1[i] = selectList[i]
Expand All @@ -519,9 +519,10 @@ func (expr *FunctionExpressionExecutor) EvalIff(proc *process.Process, batches [
}

func (expr *FunctionExpressionExecutor) EvalCase(proc *process.Process, batches []*batch.Batch, selectList []bool) (err error) {
if len(expr.selectList1) < batches[0].RowCount() {
expr.selectList1 = make([]bool, batches[0].RowCount())
expr.selectList2 = make([]bool, batches[0].RowCount())
rowCount := batches[0].RowCount()
if len(expr.selectList1) < rowCount {
expr.selectList1 = make([]bool, rowCount)
expr.selectList2 = make([]bool, rowCount)
}
if selectList != nil {
copy(expr.selectList1, selectList)
Expand All @@ -536,7 +537,7 @@ func (expr *FunctionExpressionExecutor) EvalCase(proc *process.Process, batches
return err
}
if i != len(expr.parameterExecutor)-1 {
for j := range expr.selectList1 {
for j := 0; j < rowCount; j++ {
b, null := vector.GenerateFunctionFixedTypeParameter[bool](expr.parameterResults[i]).GetValue(uint64(j))
if !null && b {
expr.selectList1[j] = false
Expand Down

0 comments on commit 7ced499

Please sign in to comment.