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) (#21408)
  • Loading branch information
ti-srebot authored May 11, 2021
1 parent d5a2432 commit aaa770a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 18 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7748,6 +7748,24 @@ func (s *testIntegrationSerialSuite) TestCollationIndexJoin(c *C) {
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1815 Optimizer Hint /*+ INL_MERGE_JOIN(t2) */ is inapplicable"))
}

func (s *testIntegrationSerialSuite) TestIssue20876(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
tk := testkit.NewTestKit(c, s.store)
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"))
}

func (s *testIntegrationSuite) TestIssue19892(c *C) {
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
Expand Down
12 changes: 2 additions & 10 deletions statistics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,18 +793,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 aaa770a

Please sign in to comment.