Skip to content
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
50 changes: 50 additions & 0 deletions pkg/sql/colexec/dedupjoin/join_generation_pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2026 Matrix Origin
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dedupjoin

import (
"bytes"
"testing"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/sql/colexec"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/stretchr/testify/require"
)

func TestDedupJoinResetReleasesGenerationJoinBatches(t *testing.T) {
proc := testutil.NewProcessWithOwnedMPool(t, "", mpool.MustNewZero())
defer proc.Free()
source := batch.NewWithSize(1)
source.Vecs[0] = vector.NewVec(types.T_varchar.ToType())
require.NoError(t, vector.AppendBytes(source.Vecs[0], bytes.Repeat([]byte("x"), 1024), false, proc.Mp()))
source.SetRowCount(1)
defer source.Clean(proc.Mp())
baseline := proc.Mp().CurrNB()

join := &DedupJoin{}
defer join.Free(proc, false, nil)
join.ctr.joinBat1, join.ctr.cfs1 = colexec.NewJoinBatch(source, proc.Mp())
join.ctr.joinBat2, join.ctr.cfs2 = colexec.NewJoinBatch(source, proc.Mp())
require.NoError(t, colexec.SetJoinBatchValues(join.ctr.joinBat1, source, 0, 1, join.ctr.cfs1))
require.NoError(t, colexec.SetJoinBatchValues(join.ctr.joinBat2, source, 0, 1, join.ctr.cfs2))
require.Greater(t, proc.Mp().CurrNB(), baseline)

join.Reset(proc, false, nil)
require.Equal(t, baseline, proc.Mp().CurrNB(), "Reset must release allocations owned by the previous process")
require.Nil(t, join.ctr.joinBat1)
require.Nil(t, join.ctr.joinBat2)
require.Nil(t, join.ctr.cfs1)
require.Nil(t, join.ctr.cfs2)
}
3 changes: 3 additions & 0 deletions pkg/sql/colexec/dedupjoin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ func (dedupJoin *DedupJoin) Reset(proc *process.Process, pipelineFailed bool, er
ctr.cleanBucketState(proc)
ctr.cleanExprExecutor()
ctr.cleanStableUpdateVecs(proc)
ctr.cleanBatch(proc)
if ctr.spillEngine != nil {
ctr.spillEngine.Cleanup(proc)
ctr.spillEngine = nil
Expand Down Expand Up @@ -608,6 +609,8 @@ func (ctr *container) cleanBatch(proc *process.Process) {
ctr.joinBat2.Clean(proc.GetMPool())
ctr.joinBat2 = nil
}
ctr.cfs1 = nil
ctr.cfs2 = nil
clear(ctr.savedVecs)
ctr.savedVecs = nil
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/sql/colexec/hashjoin/join_generation_pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2026 Matrix Origin
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package hashjoin

import (
"bytes"
"testing"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/sql/colexec"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/stretchr/testify/require"
)

func TestHashJoinResetReleasesGenerationJoinBatches(t *testing.T) {
proc := testutil.NewProcessWithOwnedMPool(t, "", mpool.MustNewZero())
defer proc.Free()
source := batch.NewWithSize(1)
source.Vecs[0] = vector.NewVec(types.T_varchar.ToType())
require.NoError(t, vector.AppendBytes(source.Vecs[0], bytes.Repeat([]byte("x"), 1024), false, proc.Mp()))
source.SetRowCount(1)
defer source.Clean(proc.Mp())
baseline := proc.Mp().CurrNB()

join := &HashJoin{}
defer join.Free(proc, false, nil)
join.ctr.joinBats = make([]*batch.Batch, 2)
join.ctr.joinBats[0], join.ctr.cfs1 = colexec.NewJoinBatch(source, proc.Mp())
join.ctr.joinBats[1], join.ctr.cfs2 = colexec.NewJoinBatch(source, proc.Mp())
require.NoError(t, colexec.SetJoinBatchValues(join.ctr.joinBats[0], source, 0, 1, join.ctr.cfs1))
require.NoError(t, colexec.SetJoinBatchValues(join.ctr.joinBats[1], source, 0, 1, join.ctr.cfs2))
require.Greater(t, proc.Mp().CurrNB(), baseline)

join.Reset(proc, false, nil)
require.Equal(t, baseline, proc.Mp().CurrNB(), "Reset must release allocations owned by the previous process")
require.Nil(t, join.ctr.joinBats[0])
require.Nil(t, join.ctr.joinBats[1])
require.Nil(t, join.ctr.cfs1)
require.Nil(t, join.ctr.cfs2)
}
8 changes: 3 additions & 5 deletions pkg/sql/colexec/hashjoin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,7 @@ func (hashJoin *HashJoin) Reset(proc *process.Process, pipelineFailed bool, err
ctr.cleanNonEqCondExecutor()
ctr.joinDiagnosticActivation = nil
ctr.joinDiagnosticActivated = false
if ctr.resBat != nil {
ctr.resBat.Clean(proc.GetMPool())
ctr.resBat = nil
}
ctr.freeRightRowsMatched(proc)
ctr.cleanBatch(proc)
ctr.rightMatchedIter = nil
ctr.skipProbe = false
ctr.bitmapSynced = false
Expand Down Expand Up @@ -531,6 +527,8 @@ func (ctr *container) cleanBatch(proc *process.Process) {
ctr.joinBats[i] = nil
}
}
ctr.cfs1 = nil
ctr.cfs2 = nil
ctr.freeRightRowsMatched(proc)
}

Expand Down
38 changes: 38 additions & 0 deletions pkg/sql/colexec/indexjoin/join_generation_pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2026 Matrix Origin
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package indexjoin

import (
"bytes"
"testing"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/stretchr/testify/require"
)

func TestIndexJoinResetReleasesGenerationResultBuffer(t *testing.T) {
proc := testutil.NewProcessWithOwnedMPool(t, "", mpool.MustNewZero())
defer proc.Free()
join := &IndexJoin{}
defer join.Free(proc, false, nil)
join.ctr.buf = batch.NewOffHeapWithSize(1)
join.ctr.buf.Vecs[0] = vector.NewOffHeapVecWithType(types.T_varchar.ToType())
require.NoError(t, vector.AppendBytes(join.ctr.buf.Vecs[0], bytes.Repeat([]byte("x"), 1024), false, proc.Mp()))
require.Greater(t, proc.Mp().CurrNB(), int64(0))

join.Reset(proc, false, nil)
require.Zero(t, proc.Mp().CurrNB(), "Reset must release the previous generation's result buffer")
require.Nil(t, join.ctr.buf)
}
3 changes: 2 additions & 1 deletion pkg/sql/colexec/indexjoin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (indexJoin *IndexJoin) Release() {
func (indexJoin *IndexJoin) Reset(proc *process.Process, pipelineFailed bool, err error) {
indexJoin.ctr.state = Probe
if indexJoin.ctr.buf != nil {
indexJoin.ctr.buf.CleanOnlyData()
indexJoin.ctr.buf.Clean(proc.Mp())
indexJoin.ctr.buf = nil
}
}

Expand Down
46 changes: 46 additions & 0 deletions pkg/sql/colexec/loopjoin/join_generation_pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2026 Matrix Origin
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package loopjoin

import (
"bytes"
"testing"

"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/sql/colexec"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/stretchr/testify/require"
)

func TestLoopJoinResetReleasesGenerationJoinBatch(t *testing.T) {
proc := testutil.NewProcessWithOwnedMPool(t, "", mpool.MustNewZero())
defer proc.Free()
source := batch.NewWithSize(1)
source.Vecs[0] = vector.NewVec(types.T_varchar.ToType())
require.NoError(t, vector.AppendBytes(source.Vecs[0], bytes.Repeat([]byte("x"), 1024), false, proc.Mp()))
source.SetRowCount(1)
defer source.Clean(proc.Mp())
baseline := proc.Mp().CurrNB()

join := &LoopJoin{}
defer join.Free(proc, false, nil)
join.ctr.joinBat, join.ctr.cfs = colexec.NewJoinBatch(source, proc.Mp())
require.NoError(t, colexec.SetJoinBatchValues(join.ctr.joinBat, source, 0, 1, join.ctr.cfs))
require.Greater(t, proc.Mp().CurrNB(), baseline)

join.Reset(proc, false, nil)
require.Equal(t, baseline, proc.Mp().CurrNB(), "Reset must release allocations owned by the previous process")
require.Nil(t, join.ctr.joinBat)
require.Nil(t, join.ctr.cfs)
}
6 changes: 2 additions & 4 deletions pkg/sql/colexec/loopjoin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,7 @@ func (loopJoin *LoopJoin) Reset(proc *process.Process, pipelineFailed bool, err
// of carrying generation-bound storage across Reset.
ctr.cleanNonEqCondExecutor()
ctr.cleanHashMap()
if ctr.resBat != nil {
ctr.resBat.Clean(proc.GetMPool())
ctr.resBat = nil
}
ctr.cleanBatch(proc.Mp())
ctr.state = Build
ctr.inBat = nil
ctr.probeIdx = 0
Expand Down Expand Up @@ -322,6 +319,7 @@ func (ctr *container) cleanBatch(mp *mpool.MPool) {
ctr.joinBat.Clean(mp)
ctr.joinBat = nil
}
ctr.cfs = nil
}

func (ctr *container) cleanNonEqCondExecutor() {
Expand Down