Skip to content

Commit

Permalink
statistics: change the dnv of default null column to 0 (#4825)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 authored Oct 19, 2017
1 parent 16eb0ae commit e035f66
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
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

0 comments on commit e035f66

Please sign in to comment.