From 9e55944362e6971b25185c36b2d059f80bc2895e Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Fri, 3 Nov 2023 11:59:10 +0800 Subject: [PATCH] executor: reuse chunk for GetMatchedRowsAndPtrs calls (#48090) (#48103) close pingcap/tidb#48082 --- executor/benchmark_test.go | 10 ++++++++++ executor/hash_table.go | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/executor/benchmark_test.go b/executor/benchmark_test.go index 5bff882e426f6..7a05282ebc9ed 100644 --- a/executor/benchmark_test.go +++ b/executor/benchmark_test.go @@ -1130,6 +1130,16 @@ func BenchmarkHashJoinExec(b *testing.B) { b.Run(fmt.Sprintf("%v", cas), func(b *testing.B) { benchmarkHashJoinExecWithCase(b, cas) }) + + cols = []*types.FieldType{ + types.NewFieldType(mysql.TypeLonglong), + } + cas = defaultHashJoinTestCase(cols, 0, false) + cas.keyIdx = []int{0} + cas.disk = true + b.Run(fmt.Sprintf("%v", cas), func(b *testing.B) { + benchmarkHashJoinExecWithCase(b, cas) + }) } func BenchmarkOuterHashJoinExec(b *testing.B) { diff --git a/executor/hash_table.go b/executor/hash_table.go index 4afdef58e1973..1562b37e8014c 100644 --- a/executor/hash_table.go +++ b/executor/hash_table.go @@ -243,11 +243,10 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk // Some variables used for memTracker. var ( matchedDataSize = int64(cap(matched))*rowSize + int64(cap(matchedPtrs))*rowPtrSize - lastChunkBufPointer *chunk.Chunk = nil + lastChunkBufPointer *chunk.Chunk = c.chkBuf memDelta int64 = 0 needTrackMemUsage = cap(innerPtrs) > signalCheckpointForJoinMask ) - c.chkBuf = nil c.memTracker.Consume(-c.chkBufSizeForOneProbe) if needTrackMemUsage { c.memTracker.Consume(int64(cap(innerPtrs)) * rowPtrSize) @@ -265,7 +264,7 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk if err != nil { return nil, nil, err } - if needTrackMemUsage && c.chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil { + if c.chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil { lastChunkSize := lastChunkBufPointer.MemoryUsage() c.chkBufSizeForOneProbe += lastChunkSize memDelta += lastChunkSize