Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change LIMIT,OFFSET's data type from int64 to uint64 #16698

Merged
merged 7 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/sql/colexec/limit/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (arg *Argument) Prepare(proc *process.Process) error {
if err != nil {
return err
}
arg.limit = uint64(vector.MustFixedCol[int64](vec)[0])
arg.limit = uint64(vector.MustFixedCol[uint64](vec)[0])

return nil
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/sql/colexec/limit/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/require"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
Expand All @@ -26,7 +28,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -54,7 +55,7 @@ func init() {
},
arg: &Argument{
Seen: 0,
LimitExpr: plan2.MakePlan2Int64ConstExprWithType(8),
LimitExpr: plan2.MakePlan2Uint64ConstExprWithType(8),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 0,
Expand All @@ -71,7 +72,7 @@ func init() {
},
arg: &Argument{
Seen: 0,
LimitExpr: plan2.MakePlan2Int64ConstExprWithType(10),
LimitExpr: plan2.MakePlan2Uint64ConstExprWithType(10),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 0,
Expand All @@ -88,7 +89,7 @@ func init() {
},
arg: &Argument{
Seen: 0,
LimitExpr: plan2.MakePlan2Int64ConstExprWithType(12),
LimitExpr: plan2.MakePlan2Uint64ConstExprWithType(12),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 0,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/mergelimit/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (arg *Argument) Prepare(proc *process.Process) error {
if err != nil {
return err
}
arg.ctr.limit = uint64(vector.MustFixedCol[int64](vec)[0])
arg.ctr.limit = uint64(vector.MustFixedCol[uint64](vec)[0])
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/colexec/mergelimit/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
plan "github.com/matrixorigin/matrixone/pkg/sql/plan"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -155,7 +156,7 @@ func newTestCase(limit uint64) limitTestCase {
types.T_int8.ToType(),
},
arg: &Argument{
Limit: plan.MakePlan2Int64ConstExprWithType(int64(limit)),
Limit: plan.MakePlan2Uint64ConstExprWithType(limit),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 0,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/mergeoffset/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (arg *Argument) Prepare(proc *process.Process) error {
if err != nil {
return err
}
arg.ctr.offset = uint64(vector.MustFixedCol[int64](vec)[0])
arg.ctr.offset = uint64(vector.MustFixedCol[uint64](vec)[0])

ap.ctr.seen = 0
return nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/colexec/mergeoffset/offset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
plan "github.com/matrixorigin/matrixone/pkg/sql/plan"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -156,7 +157,7 @@ func newTestCase(offset uint64) offsetTestCase {
types.T_int8.ToType(),
},
arg: &Argument{
Offset: plan.MakePlan2Int64ConstExprWithType(int64(offset)),
Offset: plan.MakePlan2Uint64ConstExprWithType(offset),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 0,
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/colexec/mergetop/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (arg *Argument) Prepare(proc *process.Process) (err error) {
if err != nil {
return err
}
arg.ctr.limit = vector.MustFixedCol[int64](vec)[0]
arg.ctr.limit = vector.MustFixedCol[uint64](vec)[0]
ap.ctr.InitReceiver(proc, true)
if arg.ctr.limit > 1024 {
ap.ctr.sels = make([]int64, 0, 1024)
Expand Down Expand Up @@ -175,12 +175,12 @@ func (ctr *container) build(ap *Argument, proc *process.Process, anal process.An
}
}

func (ctr *container) processBatch(limit int64, bat *batch.Batch, proc *process.Process) error {
func (ctr *container) processBatch(limit uint64, bat *batch.Batch, proc *process.Process) error {
var start int64

length := int64(bat.RowCount())
if n := int64(len(ctr.sels)); n < limit {
start = limit - n
if n := uint64(len(ctr.sels)); n < limit {
start = int64(limit - n)
if start > length {
start = length
}
Expand All @@ -190,7 +190,7 @@ func (ctr *container) processBatch(limit int64, bat *batch.Batch, proc *process.
return err
}
}
ctr.sels = append(ctr.sels, n)
ctr.sels = append(ctr.sels, int64(n))
n++
}
ctr.bat.AddRowCount(bat.RowCount())
Expand Down Expand Up @@ -219,8 +219,8 @@ func (ctr *container) processBatch(limit int64, bat *batch.Batch, proc *process.
return nil
}

func (ctr *container) eval(limit int64, proc *process.Process, anal process.Analyze, isLast bool, result *vm.CallResult) error {
if int64(len(ctr.sels)) < limit {
func (ctr *container) eval(limit uint64, proc *process.Process, anal process.Analyze, isLast bool, result *vm.CallResult) error {
if uint64(len(ctr.sels)) < limit {
ctr.sort()
}
for i, cmp := range ctr.cmps {
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/colexec/mergetop/top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
Expand All @@ -27,7 +29,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -162,7 +163,7 @@ func newTestCase(ds []bool, ts []types.Type, limit int64, fs []*plan.OrderBySpec
proc: proc,
arg: &Argument{
Fs: fs,
Limit: plan2.MakePlan2Int64ConstExprWithType(limit),
Limit: plan2.MakePlan2Uint64ConstExprWithType(uint64(limit)),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 0,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/mergetop/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type container struct {
poses []int32 // sorted list of attributes
cmps []compare.Compare // compare structure used to do sort work

limit int64
limit uint64
limitExecutor colexec.ExpressionExecutor

bat *batch.Batch // bat stores the final result of merge-top
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/offset/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (arg *Argument) Prepare(proc *process.Process) error {
if err != nil {
return err
}
arg.offset = uint64(vector.MustFixedCol[int64](vec)[0])
arg.offset = uint64(vector.MustFixedCol[uint64](vec)[0])

return nil
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/sql/colexec/offset/offset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/require"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
Expand All @@ -26,7 +28,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -54,7 +55,7 @@ func init() {
},
arg: &Argument{
Seen: 0,
OffsetExpr: plan2.MakePlan2Int64ConstExprWithType(8),
OffsetExpr: plan2.MakePlan2Uint64ConstExprWithType(8),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 1,
Expand All @@ -71,7 +72,7 @@ func init() {
},
arg: &Argument{
Seen: 0,
OffsetExpr: plan2.MakePlan2Int64ConstExprWithType(10),
OffsetExpr: plan2.MakePlan2Uint64ConstExprWithType(10),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 1,
Expand All @@ -88,7 +89,7 @@ func init() {
},
arg: &Argument{
Seen: 0,
OffsetExpr: plan2.MakePlan2Int64ConstExprWithType(12),
OffsetExpr: plan2.MakePlan2Uint64ConstExprWithType(12),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 1,
Expand Down
16 changes: 8 additions & 8 deletions pkg/sql/colexec/top/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (arg *Argument) Prepare(proc *process.Process) (err error) {
if err != nil {
return err
}
arg.ctr.limit = vector.MustFixedCol[int64](vec)[0]
arg.ctr.limit = vector.MustFixedCol[uint64](vec)[0]
if arg.ctr.limit > 1024 {
ap.ctr.sels = make([]int64, 0, 1024)
} else {
Expand Down Expand Up @@ -201,12 +201,12 @@ func (ctr *container) build(ap *Argument, bat *batch.Batch, proc *process.Proces
return err
}

func (ctr *container) processBatch(limit int64, bat *batch.Batch, proc *process.Process) error {
func (ctr *container) processBatch(limit uint64, bat *batch.Batch, proc *process.Process) error {
var start int64

length := int64(bat.RowCount())
if n := int64(len(ctr.sels)); n < limit {
start = limit - n
if n := uint64(len(ctr.sels)); n < limit {
start = int64(limit - n)
if start > length {
start = length
}
Expand All @@ -216,7 +216,7 @@ func (ctr *container) processBatch(limit int64, bat *batch.Batch, proc *process.
return err
}
}
ctr.sels = append(ctr.sels, n)
ctr.sels = append(ctr.sels, int64(n))
n++
}
ctr.bat.AddRowCount(int(start))
Expand Down Expand Up @@ -246,8 +246,8 @@ func (ctr *container) processBatch(limit int64, bat *batch.Batch, proc *process.
return nil
}

func (ctr *container) eval(limit int64, proc *process.Process, result *vm.CallResult) error {
if int64(len(ctr.sels)) < limit {
func (ctr *container) eval(limit uint64, proc *process.Process, result *vm.CallResult) error {
if uint64(len(ctr.sels)) < limit {
ctr.sort()
}
for i, cmp := range ctr.cmps {
Expand Down Expand Up @@ -302,7 +302,7 @@ func (arg *Argument) updateTopValueZM() bool {
func (arg *Argument) getTopValue() ([]byte, bool) {
ctr := arg.ctr
// not enough items in the heap.
if int64(len(ctr.sels)) < arg.ctr.limit {
if uint64(len(ctr.sels)) < arg.ctr.limit {
return nil, false
}
x := int(ctr.sels[0])
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/colexec/top/top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/require"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
Expand All @@ -27,7 +29,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -119,7 +120,7 @@ func newTestCase(m *mpool.MPool, ts []types.Type, limit int64, fs []*plan.OrderB
proc: testutil.NewProcessWithMPool(m),
arg: &Argument{
Fs: fs,
Limit: plan2.MakePlan2Int64ConstExprWithType(limit),
Limit: plan2.MakePlan2Uint64ConstExprWithType(uint64(limit)),
OperatorBase: vm.OperatorBase{
OperatorInfo: vm.OperatorInfo{
Idx: 0,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/colexec/top/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type container struct {
poses []int32 // sorted list of attributes
cmps []compare.Compare

limit int64
limit uint64
limitExecutor colexec.ExpressionExecutor

executorsForOrderColumn []colexec.ExpressionExecutor
Expand Down
10 changes: 7 additions & 3 deletions pkg/sql/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2793,11 +2793,15 @@ func (c *Compile) compileSort(n *plan.Node, ss []*Scope) []*Scope {
}
defer vec2.Free(c.proc.Mp())

limit, offset := vector.MustFixedCol[int64](vec1)[0], vector.MustFixedCol[int64](vec2)[0]
limit, offset := vector.MustFixedCol[uint64](vec1)[0], vector.MustFixedCol[uint64](vec2)[0]
topN := limit + offset
if topN <= 8192*2 {
overflow := false
if topN < limit || topN < offset {
overflow = true
}
if !overflow && topN <= 8192*2 {
// if n is small, convert `order by col limit m offset n` to `top m+n offset n`
return c.compileOffset(n, c.compileTop(n, plan2.MakePlan2Int64ConstExprWithType(topN), ss))
return c.compileOffset(n, c.compileTop(n, plan2.MakePlan2Uint64ConstExprWithType(topN), ss))
}
}
return c.compileLimit(n, c.compileOffset(n, c.compileOrder(n, ss)))
Expand Down
Loading
Loading