aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/vm/sqlvm/runtime/functions.go15
-rw-r--r--core/vm/sqlvm/runtime/instructions_op_test.go2
2 files changed, 11 insertions, 6 deletions
diff --git a/core/vm/sqlvm/runtime/functions.go b/core/vm/sqlvm/runtime/functions.go
index a885c92b8..d84517a76 100644
--- a/core/vm/sqlvm/runtime/functions.go
+++ b/core/vm/sqlvm/runtime/functions.go
@@ -456,7 +456,7 @@ func fnSubString(ctx *common.Context, ops []*Operand, length uint64) (result *Op
result = &Operand{
Meta: make([]ast.DataType, len(op.Meta)),
- Data: make([]Tuple, len(op.Data)),
+ Data: make([]Tuple, length),
}
dynBytesType := ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0)
@@ -466,9 +466,14 @@ func fnSubString(ctx *common.Context, ops []*Operand, length uint64) (result *Op
starts, ends := ops[1], ops[2]
- var start, end uint64
+ var start, end, t uint64
for i := uint64(0); i < length; i++ {
- result.Data[i] = make(Tuple, len(op.Data[i]))
+ t = i
+ if op.IsImmediate {
+ t = 0
+ }
+
+ result.Data[i] = make(Tuple, len(op.Data[t]))
if starts.IsImmediate {
start, err = ast.DecimalToUint64(starts.Data[0][0].Value)
@@ -490,8 +495,8 @@ func fnSubString(ctx *common.Context, ops []*Operand, length uint64) (result *Op
return
}
- for j := 0; j < len(op.Data[i]); j++ {
- result.Data[i][j] = &Raw{Bytes: op.Data[i][j].Bytes[start : start+end]}
+ for j := 0; j < len(op.Data[t]); j++ {
+ result.Data[i][j] = &Raw{Bytes: op.Data[t][j].Bytes[start : start+end]}
}
}
return
diff --git a/core/vm/sqlvm/runtime/instructions_op_test.go b/core/vm/sqlvm/runtime/instructions_op_test.go
index 0ff93a482..52b44e1f4 100644
--- a/core/vm/sqlvm/runtime/instructions_op_test.go
+++ b/core/vm/sqlvm/runtime/instructions_op_test.go
@@ -3999,7 +3999,7 @@ func (s *instructionSuite) TestOpFuncSubString() {
ast.ComposeDataType(ast.DataTypeMajorUint, 0),
},
[]Tuple{
- {&Raw{Value: decimal.NewFromFloat(2)}},
+ {&Raw{Value: decimal.NewFromFloat(1)}},
},
),
makeOperand(