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: reduce allocation of types.Context #52615

Merged
merged 14 commits into from
Apr 28, 2024

Conversation

winoros
Copy link
Member

@winoros winoros commented Apr 15, 2024

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

codecov bot commented Apr 15, 2024

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

/cc

@ti-chi-bot ti-chi-bot bot requested a review from Rustin170506 April 18, 2024 09:03
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.

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

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
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
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(

@@ -1838,6 +1838,7 @@ func (s *session) useCurrentSession(execOption sqlexec.ExecOption) (*session, fu
prevSQL := s.sessionVars.StmtCtx.OriginalSQL
prevStmtType := s.sessionVars.StmtCtx.StmtType
prevTables := s.sessionVars.StmtCtx.Tables
prevTypeFlags := s.sessionVars.StmtCtx.TypeFlags()
Copy link
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
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.

@@ -1126,51 +1124,6 @@ func GetIndexPrefixLens(data []byte, numCols int) (prefixLens []int, err error)
return prefixLens, nil
}

// ExtractTopN extracts topn from histogram.
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

@winoros
Copy link
Member Author

winoros commented Apr 18, 2024

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

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

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.

Copy link

ti-chi-bot bot commented Apr 28, 2024

[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

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

ti-chi-bot bot commented Apr 28, 2024

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

winoros commented Apr 28, 2024

/retest

@ti-chi-bot ti-chi-bot bot merged commit 1d698c7 into pingcap:master Apr 28, 2024
21 of 23 checks passed
@winoros winoros deleted the reduce-alloc-typectx branch April 28, 2024 19:42
@winoros
Copy link
Member Author

winoros commented Apr 28, 2024

/cherrypick release-8.1

@ti-chi-bot
Copy link
Member

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

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