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

statistics: improve out-of-range estimation strategy #26502

Merged
merged 32 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
df0db2d
use a new method to estimate out-of-range row count
time-and-fate Jul 22, 2021
c8f545a
fix tests
time-and-fate Jul 22, 2021
336287b
modify out-of-range check
time-and-fate Jul 23, 2021
21f442f
fix tests
time-and-fate Jul 23, 2021
6051b0c
add test
time-and-fate Jul 23, 2021
60e0eb5
Merge branch 'master' into issue26085
qw4990 Jul 26, 2021
d5279ce
change calculation method
time-and-fate Jul 27, 2021
1065d5b
fix test
time-and-fate Jul 27, 2021
fc21d22
handle MinNotNull and MaxValue and unsigned case
time-and-fate Jul 27, 2021
82274c8
fix test
time-and-fate Jul 27, 2021
bd7fd1b
fix test
time-and-fate Jul 27, 2021
4f0bed3
Merge remote-tracking branch 'upstream/master' into issue26085
time-and-fate Jul 27, 2021
fdf00e1
add test for unsigned case
time-and-fate Jul 27, 2021
ca9cb74
Merge branch 'master' into issue26085
time-and-fate Jul 27, 2021
7d0cb10
Merge branch 'master' into issue26085
time-and-fate Jul 27, 2021
c00e0b0
fix test
time-and-fate Jul 27, 2021
e1c8220
small fixup
time-and-fate Jul 27, 2021
145267a
Merge branch 'master' into issue26085
time-and-fate Jul 28, 2021
9e5d424
improve comments and variable names
time-and-fate Jul 29, 2021
6854f60
add test case
time-and-fate Jul 29, 2021
c804398
improve `commonPrefixLength` to simplify code
time-and-fate Jul 29, 2021
4b9e306
Merge remote-tracking branch 'upstream/master' into issue26085
time-and-fate Jul 29, 2021
e78460d
fix uniform distribution calculation and cleanup code
time-and-fate Jul 29, 2021
6dd8a95
fix test
time-and-fate Jul 30, 2021
ba43c32
fix test
time-and-fate Jul 30, 2021
568dbd9
small fixup
time-and-fate Jul 30, 2021
fe92bb1
Merge remote-tracking branch 'upstream/master' into issue26085
time-and-fate Jul 30, 2021
3a92ab8
Merge branch 'master' into issue26085
ti-chi-bot Aug 2, 2021
fc9e50e
Merge branch 'master' into issue26085
time-and-fate Aug 2, 2021
fadd55e
Merge branch 'master' into issue26085
ti-chi-bot Aug 2, 2021
458dfed
Merge branch 'master' into issue26085
ti-chi-bot Aug 2, 2021
1e2d1a0
Merge branch 'master' into issue26085
ti-chi-bot Aug 2, 2021
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
28 changes: 14 additions & 14 deletions cmd/explaintest/r/explain_complex_stats.result

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions planner/core/testdata/analyze_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"SQL": "explain format = 'brief' select * from t where a <= 5 and b <= 5",
"RatioOfPseudoEstimate": 10,
"Plan": [
"TableReader 29.77 root data:Selection",
"└─Selection 29.77 cop[tikv] le(test.t.a, 5), le(test.t.b, 5)",
"TableReader 28.80 root data:Selection",
"└─Selection 28.80 cop[tikv] le(test.t.a, 5), le(test.t.b, 5)",
" └─TableFullScan 80.00 cop[tikv] table:t keep order:false"
]
},
Expand Down Expand Up @@ -454,18 +454,18 @@
{
"SQL": "explain format = 'brief' select * from t where a = 7639902",
"Plan": [
"IndexReader 6.68 root index:IndexRangeScan",
"└─IndexRangeScan 6.68 cop[tikv] table:t, index:PRIMARY(a, c, b) range:[7639902,7639902], keep order:false"
"IndexReader 5.95 root index:IndexRangeScan",
"└─IndexRangeScan 5.95 cop[tikv] table:t, index:PRIMARY(a, c, b) range:[7639902,7639902], keep order:false"
]
},
{
"SQL": "explain format = 'brief' select c, b from t where a = 7639902 order by b asc limit 6",
"Plan": [
"Projection 6.00 root test.t.c, test.t.b",
"└─TopN 6.00 root test.t.b, offset:0, count:6",
" └─IndexReader 6.00 root index:TopN",
" └─TopN 6.00 cop[tikv] test.t.b, offset:0, count:6",
" └─IndexRangeScan 6.68 cop[tikv] table:t, index:PRIMARY(a, c, b) range:[7639902,7639902], keep order:false"
"Projection 5.95 root test.t.c, test.t.b",
"└─TopN 5.95 root test.t.b, offset:0, count:6",
" └─IndexReader 5.95 root index:TopN",
" └─TopN 5.95 cop[tikv] test.t.b, offset:0, count:6",
" └─IndexRangeScan 5.95 cop[tikv] table:t, index:PRIMARY(a, c, b) range:[7639902,7639902], keep order:false"
]
}
]
Expand Down
10 changes: 1 addition & 9 deletions statistics/cmsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,6 @@ func (c *TopN) Num() int {
return len(c.TopN)
}

// outOfRange checks whether the the given value falls back in [TopN.LowestOne, TopN.HighestOne].
func (c *TopN) outOfRange(val []byte) bool {
if c == nil || len(c.TopN) == 0 {
return true
}
return bytes.Compare(c.TopN[0].Encoded, val) > 0 || bytes.Compare(val, c.TopN[c.Num()-1].Encoded) > 0
}

// DecodedString returns the value with decoded result.
func (c *TopN) DecodedString(ctx sessionctx.Context, colTypes []byte) (string, error) {
builder := &strings.Builder{}
Expand Down Expand Up @@ -775,7 +767,7 @@ func MergePartTopN2GlobalTopN(sc *stmtctx.StatementContext, version int, topNs [
datum = d
}
// Get the row count which the value is equal to the encodedVal from histogram.
count := hists[j].equalRowCount(datum, isIndex)
count, _ := hists[j].equalRowCount(datum, isIndex)
if count != 0 {
counter[encodedVal] += count
// Remove the value corresponding to encodedVal from the histogram.
Expand Down
6 changes: 2 additions & 4 deletions statistics/handle/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,12 +1254,10 @@ func (h *Handle) RecalculateExpectCount(q *statistics.QueryFeedback) error {
expected := 0.0
if isIndex {
idx := t.Indices[id]
expected, err = idx.GetRowCount(sc, nil, ranges, t.ModifyCount)
expected *= idx.GetIncreaseFactor(t.Count)
expected, err = idx.GetRowCount(sc, nil, ranges, t.Count)
} else {
c := t.Columns[id]
expected, err = c.GetColumnRowCount(sc, ranges, t.ModifyCount, true)
expected *= c.GetIncreaseFactor(t.Count)
expected, err = c.GetColumnRowCount(sc, ranges, t.Count, true)
}
q.Expected = int64(expected)
return err
Expand Down
4 changes: 2 additions & 2 deletions statistics/handle/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1815,8 +1815,8 @@ func (s *testStatsSuite) TestAbnormalIndexFeedback(c *C) {
sql: "select * from t where a = 2 and b > 10",
hist: "column:2 ndv:20 totColSize:20\n" +
"num: 5 lower_bound: -9223372036854775808 upper_bound: 7 repeats: 0 ndv: 0\n" +
"num: 4 lower_bound: 7 upper_bound: 14 repeats: 0 ndv: 0\n" +
"num: 5 lower_bound: 14 upper_bound: 9223372036854775807 repeats: 0 ndv: 0",
"num: 6 lower_bound: 7 upper_bound: 14 repeats: 0 ndv: 0\n" +
"num: 8 lower_bound: 14 upper_bound: 9223372036854775807 repeats: 0 ndv: 0",
rangeID: tblInfo.Columns[1].ID,
idxID: tblInfo.Indices[0].ID,
eqCount: 3,
Expand Down
Loading