-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: correct behavior of non-lite InitStats and stats sync load of no stats column #57803
base: master
Are you sure you want to change the base?
Conversation
296b172
to
d201740
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #57803 +/- ##
================================================
+ Coverage 72.8626% 73.7086% +0.8459%
================================================
Files 1677 1709 +32
Lines 464331 476385 +12054
================================================
+ Hits 338324 351137 +12813
+ Misses 105118 103599 -1519
- Partials 20889 21649 +760
Flags with carried forward coverage won't be shown. Click here to find out more.
|
d201740
to
16936a5
Compare
07b9bcf
to
4434c2a
Compare
4434c2a
to
0494095
Compare
fca25f1
to
f9f7ac1
Compare
if isConcurrency { | ||
require.Equal(t, uint8(0x3), table0.GetIdx(1).LastAnalyzePos.GetBytes()[0]) | ||
require.Equal(t, uint8(0x3), table0.GetIdx(2).LastAnalyzePos.GetBytes()[0]) | ||
} else { | ||
require.Equal(t, uint8(0x33), table0.GetCol(1).LastAnalyzePos.GetBytes()[0]) | ||
require.Equal(t, uint8(0x33), table0.GetCol(2).LastAnalyzePos.GetBytes()[0]) | ||
require.Equal(t, uint8(0x33), table0.GetCol(3).LastAnalyzePos.GetBytes()[0]) | ||
require.Equal(t, uint8(0x3), table0.GetIdx(1).LastAnalyzePos.GetBytes()[0]) | ||
require.Equal(t, uint8(0x3), table0.GetIdx(2).LastAnalyzePos.GetBytes()[0]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, we should not distinguish between the single thread init and the concurrent init.
This pr makes them consistent.
require.True(t, table0.GetCol(1).IsAllEvicted()) | ||
require.True(t, table0.GetCol(2).IsAllEvicted()) | ||
require.True(t, table0.GetCol(3).IsAllEvicted()) | ||
require.True(t, !table0.GetCol(4).IsStatsInitialized()) | ||
require.True(t, table0.GetCol(5).IsStatsInitialized()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
column 1/2/3 is analyzed. col4 is not analyzed and has no record in storage.
col5 is created by add column default value
so it has stats though it's not analyzed.
@@ -88,7 +88,7 @@ func testConcurrentlyInitStats(t *testing.T) { | |||
tk.MustQuery(fmt.Sprintf("explain select * from t%v where b = 1", i)).CheckNotContain("pseudo") | |||
} | |||
for i := 1; i < 10; i++ { | |||
tk.MustQuery(fmt.Sprintf("explain select * from t%v where c = 1", i)).CheckNotContain("pseudo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pk = 1
will result in PointGet. Will not trigger the stats load.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hawkingrei The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please summarize the changes made in your PR description? It's a bit difficult to understand what is happening in the PR.
@@ -619,6 +638,15 @@ func (*Handle) initStatsBuckets4Chunk(cache statstypes.StatsCache, iter *chunk.I | |||
} | |||
} | |||
|
|||
func initStatsBucketsSQLGen(isPaging bool) string { | |||
selectPrefix := "select /*+ ORDER_INDEX(mysql.stats_buckets,tbl) */ HIGH_PRIORITY table_id, is_index, hist_id, count, repeats, lower_bound, upper_bound, ndv from mysql.stats_buckets where is_index=1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems different from the old one. Could you please explain why we need is_index=1
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we've already not read the column's topn into memory. So reading the buckets here is a useless operation since the stats have already broken.
func (h *Handle) initStatsTopN(cache statstypes.StatsCache, totalMemory uint64) error { | ||
sql := "select /*+ ORDER_INDEX(mysql.stats_top_n,tbl)*/ HIGH_PRIORITY table_id, hist_id, value, count from mysql.stats_top_n where is_index = 1 order by table_id" | ||
sql := initStatsTopNSQLGen(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems different from the old one. Could you please explain why we need to remove is_index=1
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the is_index=1
is not removed. It's aligned with the non-concurrent version. This is to make the concurrent one and the non-concurrent one the same.
@@ -285,7 +298,7 @@ func (h *Handle) initStatsHistogramsLite(ctx context.Context, cache statstypes.S | |||
} | |||
|
|||
func (h *Handle) initStatsHistograms(is infoschema.InfoSchema, cache statstypes.StatsCache) error { | |||
sql := "select /*+ ORDER_INDEX(mysql.stats_histograms,tbl)*/ HIGH_PRIORITY table_id, is_index, hist_id, distinct_count, version, null_count, cm_sketch, tot_col_size, stats_ver, correlation, flag, last_analyze_pos from mysql.stats_histograms order by table_id" | |||
sql := initStatsHistogramsSQLGen(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems different from the old one. Could you please explain why we need to remove is_index=1 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you search the caller of the initStatsHistogramSQLGen
you will see that now initStatsHistogramsLite
, initStatsHistograms
, and initStatsHistogramsConcurrency
use the same SQL gen.
Actually, the SQL is not changed for initStatsHistogramsLite
and initStatsHistograms
. It just aligned the initStatsHistogramsConcurrency
with the other two.
Co-authored-by: Rustin <tech@rustin.me>
@winoros: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What problem does this PR solve?
Issue Number: close #57804
Problem Summary:
What changed and how does it work?
You can regard this pull request as a totally rewrite of #53399 and #53298
This pull reduced the possible stats state after the stats initialization finished. Now we'll get the same memory objects after a non-concurrent or current non-lite load.
Then use the unified status to make the
ColumnIsLoadNeeded
correct when one column even has no record in mysql.stats_histograms.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.