Skip to content

Commit

Permalink
executor: handle unsigned primary key for fast analyze (#11074) (#11099)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored and zz-jason committed Jul 6, 2019
1 parent c3346f2 commit 731e426
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ func (e *AnalyzeFastExec) updateCollectorSamples(sValue []byte, sKey kv.Key, sam
}
v = types.NewIntDatum(key)
}
if mysql.HasUnsignedFlag(e.pkInfo.Flag) {
v.SetUint64(uint64(v.GetInt64()))
}
if e.collectors[0].Samples[samplePos] == nil {
e.collectors[0].Samples[samplePos] = &statistics.SampleItem{}
}
Expand Down
7 changes: 7 additions & 0 deletions executor/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ func (s *testSuite1) TestFastAnalyze(c *C) {
tk.MustQuery("explain select a, b from t1 where a = 1 and b = 2").Check(testkit.Rows(
"IndexReader_6 2.00 root index:IndexScan_5",
"└─IndexScan_5 2.00 cop table:t1, index:a, b, range:[1 2,1 2], keep order:false"))

tk.MustExec("create table t2 (a bigint unsigned, primary key(a))")
tk.MustExec("insert into t2 values (0), (18446744073709551615)")
tk.MustExec("analyze table t2")
tk.MustQuery("show stats_buckets where table_name = 't2'").Check(testkit.Rows(
"test t2 a 0 0 1 1 0 0",
"test t2 a 0 1 2 1 18446744073709551615 18446744073709551615"))
}

func (s *testSuite1) TestAnalyzeIncremental(c *C) {
Expand Down

0 comments on commit 731e426

Please sign in to comment.