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: change the dnv of default null column to 0 #4825

Merged
merged 3 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion statistics/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (h *Handle) insertColStats2KV(tableID int64, colInfo *model.ColumnInfo) err
}
if value.IsNull() {
// If the adding column has default value null, all the existing rows have null value on the newly added column.
_, err = exec.Execute(fmt.Sprintf("insert into mysql.stats_histograms (version, table_id, is_index, hist_id, distinct_count, null_count) values (%d, %d, 0, %d, 1, %d)", h.ctx.Txn().StartTS(), tableID, colInfo.ID, count))
_, err = exec.Execute(fmt.Sprintf("insert into mysql.stats_histograms (version, table_id, is_index, hist_id, distinct_count, null_count) values (%d, %d, 0, %d, 0, %d)", h.ctx.Txn().StartTS(), tableID, colInfo.ID, count))
if err != nil {
return errors.Trace(err)
}
Expand Down
1 change: 1 addition & 0 deletions statistics/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (s *testStatsCacheSuite) TestDDLHistogram(c *C) {
c.Assert(statsTbl.Pseudo, IsFalse)
sc := new(variable.StatementContext)
c.Assert(statsTbl.ColumnIsInvalid(tableInfo.Columns[2]), IsTrue)
c.Check(statsTbl.Columns[tableInfo.Columns[2].ID].NDV, Equals, int64(0))

testKit.MustExec("alter table t add column c3 int NOT NULL")
err = h.HandleDDLEvent(<-h.DDLEventCh())
Expand Down