[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

statistics: correct behavior of non-lite InitStats and stats sync load of no stats column #57803

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

winoros
Copy link
Member
@winoros winoros commented Nov 28, 2024

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

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 28, 2024
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 28, 2024
Copy link
codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 86.44068% with 8 lines in your changes missing coverage. Please review.

Project coverage is 73.7086%. Comparing base (cc59ab0) to head (6d003ca).
Report is 18 commits behind head on master.

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     
Flag Coverage Δ
integration 46.1183% <27.1186%> (?)
unit 72.2994% <86.4406%> (+0.0366%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 45.1196% <ø> (-0.5911%) ⬇️

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 28, 2024
@winoros winoros changed the title statistics: try to eliminate the unnecessary log for sync load statistics: try to eliminate the unnecessary log for sync load | tidb-test=pr/2435 Nov 28, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 28, 2024
@winoros winoros changed the title statistics: try to eliminate the unnecessary log for sync load | tidb-test=pr/2435 statistics: try to eliminate the unnecessary log for sync load Nov 28, 2024
@winoros winoros changed the title statistics: try to eliminate the unnecessary log for sync load statistics: correct some behavior of non-lite InitStats and stats sync load Nov 28, 2024
@winoros winoros changed the title statistics: correct some behavior of non-lite InitStats and stats sync load statistics: correct behavior of non-lite InitStats and stats sync load of no stats column Nov 28, 2024
Comment on lines -369 to -378
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])
}
Copy link
Member Author
@winoros winoros Nov 28, 2024

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.

Comment on lines +376 to +380
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())
Copy link
Member Author

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")
Copy link
Member Author

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.

Copy link
ti-chi-bot bot commented Nov 29, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 29, 2024
Copy link
ti-chi-bot bot commented Nov 29, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-29 01:19:10.185011604 +0000 UTC m=+772137.804666119: ☑️ agreed by hawkingrei.

Copy link
Member
@Rustin170506 Rustin170506 left a 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"
Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author
@winoros winoros Dec 2, 2024

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)
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
tiprow bot commented Dec 2, 2024

@winoros: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow 6d003ca link true /test fast_test_tiprow

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Too many unnecessary log for sync load when stats is not exists
3 participants