Skip to content

Commit

Permalink
statistics: fix old bucket4Merging to merge new data (#49169) (#49187)
Browse files Browse the repository at this point in the history
close #49168
  • Loading branch information
ti-chi-bot authored Dec 6, 2023
1 parent 1643e00 commit 456628e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/statistics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ go_library(
"//pkg/util/dbterror",
"//pkg/util/fastrand",
"//pkg/util/hack",
"//pkg/util/intest",
"//pkg/util/logutil",
"//pkg/util/mathutil",
"//pkg/util/memory",
Expand Down
7 changes: 7 additions & 0 deletions pkg/statistics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/codec"
"github.com/pingcap/tidb/pkg/util/collate"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/ranger"
"github.com/pingcap/tipb/go-tipb"
Expand Down Expand Up @@ -1180,6 +1181,9 @@ func newbucket4MergingForRecycle() *bucket4Merging {

func releasebucket4MergingForRecycle(b *bucket4Merging) {
b.disjointNDV = 0
b.Repeat = 0
b.NDV = 0
b.Count = 0
bucket4MergingPool.Put(b)
}

Expand Down Expand Up @@ -1367,6 +1371,9 @@ func mergePartitionBuckets(sc *stmtctx.StatementContext, buckets []*bucket4Mergi
right := buckets[len(buckets)-1].Clone()

totNDV := int64(0)
intest.Assert(res.Count == 0, "Count in the new bucket4Merging should be 0")
intest.Assert(res.Repeat == 0, "Repeat in the new bucket4Merging should be 0")
intest.Assert(res.NDV == 0, "NDV in the new bucket4Merging bucket4Merging should be 0")
for i := len(buckets) - 1; i >= 0; i-- {
totNDV += buckets[i].NDV
res.Count += buckets[i].Count
Expand Down

0 comments on commit 456628e

Please sign in to comment.