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) #9502

Merged
merged 2 commits into from Feb 28, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+19 −2
Diff settings

Always

Just for now

Next

executor: only show valid columns in `stats_histogram` (#9487)

  • Loading branch information...
eurekaka committed Feb 28, 2019
commit faf6ed7f7c4f1477e4c8f15991f48f9f9d2a8eed
@@ -54,6 +54,10 @@ func (e *ShowExec) fetchShowStatsHistogram() error {
statsTbl := h.GetTableStats(tbl)
if !statsTbl.Pseudo {
for _, col := range statsTbl.Columns {
// Pass a nil StatementContext to avoid column stats being marked as needed.
if statsTbl.ColumnIsInvalid(nil, col.ID) {
continue
}
e.histogramToRow(db.Name.O, tbl.Name.O, col.Info.Name.O, 0, col.Histogram, col.AvgColSize(statsTbl.Count))
}
for _, idx := range statsTbl.Indices {
@@ -42,13 +42,26 @@ func (s *testSuite) 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][2], Equals, "a")
c.Assert(result.Rows()[1][2], Equals, "b")
result = tk.MustQuery("show stats_histograms where column_name = 'a'")
c.Assert(len(result.Rows()), Equals, 1)
c.Assert(result.Rows()[0][2], 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 *testSuite) TestShowStatsBuckets(c *C) {
@@ -349,7 +349,7 @@ func (coll *HistColl) ColumnIsInvalid(sc *stmtctx.StatementContext, colID int64)
if !ok || coll.Pseudo && col.NotAccurate() {
return true
}
if col.NDV > 0 && col.Len() == 0 && coll.HavePhysicalID {
if col.NDV > 0 && col.Len() == 0 && coll.HavePhysicalID && sc != nil {
sc.SetHistogramsNotLoad()
histogramNeededColumns.insert(tableColumnID{tableID: coll.PhysicalID, columnID: col.Info.ID})
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.