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: fix a bug which causes panic when using the clustered index and the new collation #21379

Merged
merged 4 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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