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: add the missed runtime stats when the index merge partial task returns 0 row #35297

Merged
merged 9 commits into from
Jun 20, 2022
18 changes: 18 additions & 0 deletions executor/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,21 @@ func TestFix29401(t *testing.T) {
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`)
tk.MustExec(" explain select /*+ inl_hash_join(t1) */ * from tt123 t1 join tt123 t2 on t1.b=t2.e;")
}

func TestIssue35296(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int , c int, d int, e int,index ia(a), index ib(b), index ic(c), index idd(d), index ie(e));")

rows := tk.MustQuery("explain analyze select * from t where a = 10 or b = 30 or c = 10 or d = 1 or e = 90;").Rows()

require.Contains(t, rows[0][0], "IndexMerge")
require.NotRegexp(t, "^time:0s", rows[1][5])
require.NotRegexp(t, "^time:0s", rows[2][5])
require.NotRegexp(t, "^time:0s", rows[3][5])
require.NotRegexp(t, "^time:0s", rows[4][5])
require.NotRegexp(t, "^time:0s", rows[5][5])
}
3 changes: 3 additions & 0 deletions executor/index_merge_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ func (w *partialIndexWorker) fetchHandles(
return count, err
}
if len(handles) == 0 {
if basicStats != nil {
basicStats.Record(time.Since(start), chk.NumRows())
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the chk.NumRows() mean for partialIndexWorker?

Copy link
Member Author

@time-and-fate time-and-fate Jun 13, 2022

Choose a reason for hiding this comment

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

This line of code is the same as this line in the same function:

basicStats.Record(time.Since(start), chk.NumRows())

I just copied it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Theoretically, it should be the actual row count of this operator but in fact, it's useless.
Because the root operator of a partial worker has both root stats and cop stats, and according to getRuntimeInfo(), in this case, the actual row count in the cop stats will be used:

if runtimeStatsColl.ExistsRootStats(explainID) {
rootStats := runtimeStatsColl.GetRootStats(explainID)
analyzeInfo = rootStats.String()
actRows = strconv.FormatInt(rootStats.GetActRows(), 10)
} else {
actRows = "0"
}
if runtimeStatsColl.ExistsCopStats(explainID) {
if len(analyzeInfo) > 0 {
analyzeInfo += ", "
}
copStats := runtimeStatsColl.GetCopStats(explainID)
analyzeInfo += copStats.String()
actRows = strconv.FormatInt(copStats.GetActRows(), 10)
}

}
return count, nil
}
count += int64(len(handles))
Expand Down