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

planner: use collected predicate columns to do stats sync load #56813

Merged
merged 17 commits into from
Nov 12, 2024

Conversation

winoros
Copy link
Member

@winoros winoros commented Oct 23, 2024

What problem does this PR solve?

Issue Number: close #56812

Problem Summary:

What changed and how does it work?

Just as the issue said, we can directly use predicate columns that we collect to decide the statistics' loading.

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.

Improve the performance of statistics' sync loading
优化统计信息同步加载的性能

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. sig/planner SIG: Planner labels Oct 23, 2024
@hawkingrei hawkingrei self-requested a review October 23, 2024 15:47
Copy link

codecov bot commented Oct 23, 2024

Codecov Report

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

Project coverage is 73.7650%. Comparing base (f973f19) to head (a602491).
Report is 2 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #56813        +/-   ##
================================================
+ Coverage   72.9101%   73.7650%   +0.8548%     
================================================
  Files          1669       1699        +30     
  Lines        461114     469377      +8263     
================================================
+ Hits         336199     346236     +10037     
+ Misses       104270     101821      -2449     
- Partials      20645      21320       +675     
Flag Coverage Δ
integration 46.2312% <73.4567%> (?)
unit 72.3498% <95.0617%> (+0.0662%) ⬆️

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 45.1426% <ø> (+0.0370%) ⬆️

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 27, 2024
@hawkingrei hawkingrei self-requested a review October 27, 2024 02:33
@hawkingrei
Copy link
Member

@winoros Please fix the linter first.

@winoros winoros force-pushed the simplify-stats-syncload branch from fdebb75 to cf41c5c Compare November 4, 2024 15:36
@winoros winoros force-pushed the simplify-stats-syncload branch from 9009e6b to 8935218 Compare November 4, 2024 20:53
@@ -77,7 +77,7 @@ func TestPlanStatsLoad(t *testing.T) {
switch pp := p.(type) {
case *plannercore.PhysicalTableReader:
stats := pp.StatsInfo().HistColl
require.Equal(t, 0, countFullStats(stats, tableInfo.Columns[1].ID))
Copy link
Member Author

Choose a reason for hiding this comment

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

The unneeded stats now is just fully unloaded.

@@ -483,5 +483,6 @@ func TestPartialStatsInExplain(t *testing.T) {
output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(sql).Rows())
})
tk.MustQuery(sql).Check(testkit.Rows(output[i].Result...))
require.NoError(t, dom.StatsHandle().LoadNeededHistograms(dom.InfoSchema()))
Copy link
Member Author

Choose a reason for hiding this comment

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

Since only stats of predicates will be loaded, only stats of a from table tp is loaded into memory.
So for the first SQL, the stats of index ic and column b are not loaded into memory, becoming unInitialized. I use a LoadNeededHistograms to tell you that the actual stats is correct.

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.

Thanks!

pkg/planner/core/collect_column_stats_usage.go Outdated Show resolved Hide resolved
pkg/planner/core/rule_collect_plan_stats.go Outdated Show resolved Hide resolved
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.

Sorry, I’m not very familiar with this code. So I asked some questions that I didn't understand.

Thank you!

I will take another look tomorrow to make sure I fully understand it.

if !fullLoad {
continue
}
if statsHandle == nil {
Copy link
Member

Choose a reason for hiding this comment

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

I guess we can move this check outside.

}
tblInfo := tblID2TblInfo[neededCol.TableID]
if tblInfo == nil {
continue
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain a little bit why this is possible?

// If we already collected some columns that need trigger sync laoding on this table, we don't need to
// additionally do anything for determinate mode.
if physTblIDsWithNeededCols.Has(physicalTblID) ||
statsHandle == nil {
Copy link
Member

Choose a reason for hiding this comment

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

If we do the stats handle check, I guess we don't need to do it here.

}
// Choose the first column we meet to trigger stats loading.
if colToTriggerLoad == nil {
colToTriggerLoad = &model.TableItemID{TableID: int64(physicalTblID), ID: col.ID, IsIndex: false}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to break out here?

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.

rest LGTM


// 2. get the stats table

// If we already collected some columns that need trigger sync laoding on this table, we don't need to
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If we already collected some columns that need trigger sync laoding on this table, we don't need to
// If we already collected some columns that need trigger sync loading on this table, we don't need to

Comment on lines 128 to 129
// 2. get the stats table

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 2. get the stats table
// 2. get the stats table

@winoros winoros force-pushed the simplify-stats-syncload branch from d589bd6 to a602491 Compare November 12, 2024 13:52
Copy link

tiprow bot commented Nov 12, 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 a602491 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.

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.

Looks good to me. Thanks! 👍

Copy link

ti-chi-bot bot commented Nov 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, Rustin170506

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 12, 2024
Copy link

ti-chi-bot bot commented Nov 12, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-27 02:32:43.036999949 +0000 UTC m=+144275.876155479: ☑️ agreed by hawkingrei.
  • 2024-11-12 14:18:25.179707982 +0000 UTC m=+365867.370576979: ☑️ agreed by Rustin170506.

@ti-chi-bot ti-chi-bot bot merged commit 5caa238 into pingcap:master Nov 12, 2024
23 of 24 checks passed
@winoros winoros deleted the simplify-stats-syncload branch November 13, 2024 05:53
@winoros
Copy link
Member Author

winoros commented Nov 13, 2024

/cherrypick release-8.5

@ti-chi-bot
Copy link
Member

@winoros: new pull request created to branch release-8.5: #57340.

In response to this:

/cherrypick release-8.5

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 ti-community-infra/tichi repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use collected predicate columns to decide the loading of column statistics
4 participants