Skip to content

Commit

Permalink
statistics: fix a bug which causes panic when using the clustered ind…
Browse files Browse the repository at this point in the history
…ex and the new collation (#21379)

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
  • Loading branch information
wjhuang2016 authored Dec 1, 2020
1 parent c94e0df commit 5131514
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
19 changes: 19 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8029,3 +8029,22 @@ func (s *testIntegrationSuite) TestIssue19892(c *C) {
tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00"))
}
}

func (s *testIntegrationSerialSuite) TestIssue20876(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@tidb_enable_clustered_index=1;")
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("CREATE TABLE `t` (" +
" `a` char(10) COLLATE utf8mb4_unicode_ci NOT NULL," +
" `b` char(20) COLLATE utf8mb4_general_ci NOT NULL," +
" `c` int(11) NOT NULL," +
" PRIMARY KEY (`a`,`b`,`c`)," +
" KEY `idx` (`a`)" +
")")
tk.MustExec("insert into t values ('#', 'C', 10), ('$', 'c', 20), ('$', 'c', 30), ('a', 'a', 10), ('A', 'A', 30)")
tk.MustExec("analyze table t")
tk.MustQuery("select * from t where a='#';").Check(testkit.Rows("# C 10"))
}
12 changes: 2 additions & 10 deletions statistics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,18 +820,10 @@ func (c *Column) GetColumnRowCount(sc *stmtctx.StatementContext, ranges []*range
highVal := *rg.HighVal[0].Clone()
lowVal := *rg.LowVal[0].Clone()
if highVal.Kind() == types.KindString {
highVal.SetBytesAsString(collate.GetCollator(
highVal.Collation()).Key(highVal.GetString()),
highVal.Collation(),
uint32(highVal.Length()),
)
highVal.SetBytes(collate.GetCollator(highVal.Collation()).Key(highVal.GetString()))
}
if lowVal.Kind() == types.KindString {
lowVal.SetBytesAsString(collate.GetCollator(
lowVal.Collation()).Key(lowVal.GetString()),
lowVal.Collation(),
uint32(lowVal.Length()),
)
lowVal.SetBytes(collate.GetCollator(lowVal.Collation()).Key(lowVal.GetString()))
}
cmp, err := lowVal.CompareDatum(sc, &highVal)
if err != nil {
Expand Down

0 comments on commit 5131514

Please sign in to comment.