Skip to content

statistics: reduce allocation of types.Context - #52615

Merged
ti-chi-bot[bot] merged 14 commits into
pingcap:masterfrom
winoros:reduce-alloc-typectx
Apr 28, 2024
Merged

ti-chi-bot[bot] merged 14 commits into
pingcap:masterfrom
winoros:reduce-alloc-typectx

Conversation

@winoros

@winoros winoros commented Apr 15, 2024

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #52342

Problem Summary:

We still have #52429, but we can reduce the allocations first.

What changed and how does it work?

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 release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/planner SIG: Planner labels Apr 15, 2024
@codecov

codecov Bot commented Apr 15, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 55.6253%. Comparing base (40c81c0) to head (3a4f760).

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #52615         +/-   ##
=================================================
- Coverage   72.3860%   55.6253%   -16.7607%     
=================================================
  Files          1482       1593        +111     
  Lines        428754     598394     +169640     
=================================================
+ Hits         310358     332859      +22501     
- Misses        99088     242580     +143492     
- Partials      19308      22955       +3647     
Flag Coverage Δ
integration 36.9334% <77.7777%> (?)

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

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 49.8961% <ø> (+8.7287%) ⬆️

@winoros
winoros force-pushed the reduce-alloc-typectx branch 2 times, most recently from 293bc35 to c648886 Compare April 15, 2024 13:51
Comment thread pkg/statistics/handle/bootstrap.go Outdated
Comment thread pkg/statistics/handle/handle.go Outdated
@winoros
winoros force-pushed the reduce-alloc-typectx branch from c648886 to 6ada327 Compare April 15, 2024 13:59
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Apr 15, 2024
@0xPoe

0xPoe commented Apr 18, 2024

Copy link
Copy Markdown
Member

/cc

@ti-chi-bot
ti-chi-bot Bot requested a review from 0xPoe April 18, 2024 09:03

@0xPoe 0xPoe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you have any test results? Could you please put it on GitHub?

Comment thread pkg/domain/domain.go Outdated
Comment on lines +2267 to +2270
// Invalid date values may be inserted into table under some relaxed sql mode. Those values may exist in statistics.
// Hence, when reading statistics, we should skip invalid date check. See #39336.
sc := ctx.GetSessionVars().StmtCtx
sc.SetTypeFlags(sc.TypeFlags().WithIgnoreInvalidDateErr(true).WithIgnoreZeroInDate(true))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we use a function for it? Then we don't need to copy the comments and code again in other places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you have any good ideas?
I'm not sure how to make it better(

Comment thread pkg/session/session.go Outdated
prevSQL := s.sessionVars.StmtCtx.OriginalSQL
prevStmtType := s.sessionVars.StmtCtx.StmtType
prevTables := s.sessionVars.StmtCtx.Tables
prevTypeFlags := s.sessionVars.StmtCtx.TypeFlags()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need this change? Could you explain a little bit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The useCurrentSession will return a func as the clean func after the session executes a SQL.
We need to make sure that the CLEAN operation will not clean the flag we set.

return prefixLens, nil
}

// ExtractTopN extracts topn from histogram.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch!

@winoros

winoros commented Apr 18, 2024

Copy link
Copy Markdown
Member Author

Do you have any test results? Could you please put it on GitHub?

The test env is under rebuilding(

@winoros
winoros force-pushed the reduce-alloc-typectx branch from 7c679bd to b6faed1 Compare April 28, 2024 15:55
@ti-chi-bot ti-chi-bot Bot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 28, 2024
@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved labels Apr 28, 2024
@winoros
winoros force-pushed the reduce-alloc-typectx branch from 89487df to 3a4f760 Compare April 28, 2024 16:38

@time-and-fate time-and-fate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please note that not all places use flags with FlagIgnoreInvalidDateErr and FlagIgnoreZeroInDateErr.
Others LGTM.

@ti-chi-bot

ti-chi-bot Bot commented Apr 28, 2024

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, time-and-fate

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 Apr 28, 2024
@ti-chi-bot

ti-chi-bot Bot commented Apr 28, 2024

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2024-04-15 16:38:41.674694488 +0000 UTC m=+269740.785740938: ☑️ agreed by hawkingrei.
  • 2024-04-28 19:00:20.437909212 +0000 UTC m=+210974.195044785: ☑️ agreed by time-and-fate.

@winoros

winoros commented Apr 28, 2024

Copy link
Copy Markdown
Member Author

/retest

@ti-chi-bot
ti-chi-bot Bot merged commit 1d698c7 into pingcap:master Apr 28, 2024
@winoros
winoros deleted the reduce-alloc-typectx branch April 28, 2024 19:42
@winoros

winoros commented Apr 28, 2024

Copy link
Copy Markdown
Member Author

/cherrypick release-8.1

@ti-chi-bot

Copy link
Copy Markdown
Member

@winoros: new pull request created to branch release-8.1: #52963.

Details

In response to this:

/cherrypick release-8.1

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-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A lot of CPU is used to generate context when non-lite init stats

5 participants