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

executor: only show valid columns in stats_histogram #9487

Merged
merged 4 commits into from
Feb 28, 2019
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
4 changes: 4 additions & 0 deletions executor/show_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func (e *ShowExec) appendTableForStatsHistograms(dbName, tblName, partitionName
return
}
for _, col := range statsTbl.Columns {
// Pass a nil StatementContext to avoid column stats being marked as needed.
if col.IsInvalid(nil, false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass sc here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to mark column stats needed in show stats_histograms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about adding a comment like "pass a nil StatementContext to avoid column stats being marked as needed"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added, PTAL

continue
}
e.histogramToRow(dbName, tblName, partitionName, col.Info.Name.O, 0, col.Histogram, col.AvgColSize(statsTbl.Count))
}
for _, idx := range statsTbl.Indices {
Expand Down
15 changes: 14 additions & 1 deletion executor/show_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,26 @@ func (s *testSuite1) TestShowStatsHistograms(c *C) {
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int, b int)")
tk.MustExec("analyze table t")
result := tk.MustQuery("show stats_histograms").Sort()
result := tk.MustQuery("show stats_histograms")
c.Assert(len(result.Rows()), Equals, 0)
tk.MustExec("insert into t values(1,1)")
tk.MustExec("analyze table t")
result = tk.MustQuery("show stats_histograms").Sort()
c.Assert(len(result.Rows()), Equals, 2)
c.Assert(result.Rows()[0][3], Equals, "a")
c.Assert(result.Rows()[1][3], Equals, "b")
result = tk.MustQuery("show stats_histograms where column_name = 'a'")
c.Assert(len(result.Rows()), Equals, 1)
c.Assert(result.Rows()[0][3], Equals, "a")

tk.MustExec("drop table t")
tk.MustExec("create table t(a int, b int, c int, index idx_b(b), index idx_c_a(c, a))")
tk.MustExec("insert into t values(1,null,1),(2,null,2),(3,3,3),(4,null,4),(null,null,null)")
res := tk.MustQuery("show stats_histograms where table_name = 't'")
c.Assert(len(res.Rows()), Equals, 0)
tk.MustExec("analyze table t index idx_b")
res = tk.MustQuery("show stats_histograms where table_name = 't' and column_name = 'idx_b'")
c.Assert(len(res.Rows()), Equals, 1)
}

func (s *testSuite1) TestShowStatsBuckets(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (c *Column) IsInvalid(sc *stmtctx.StatementContext, collPseudo bool) bool {
if collPseudo && c.NotAccurate() {
return true
}
if c.NDV > 0 && c.Len() == 0 {
if c.NDV > 0 && c.Len() == 0 && sc != nil {
sc.SetHistogramsNotLoad()
histogramNeededColumns.insert(tableColumnID{tableID: c.PhysicalID, columnID: c.Info.ID})
}
Expand Down