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

executor: add cache for approximate table count #44979

Merged
merged 16 commits into from Jul 3, 2023

Conversation

hawkingrei
Copy link
Member

@hawkingrei hawkingrei commented Jun 27, 2023

What problem does this PR solve?

Issue Number: close #44978

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

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 release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/needs-linked-issue labels Jun 27, 2023
@hawkingrei hawkingrei changed the title executor: add chache for approximate table count executor: add cache for approximate table count Jun 27, 2023
@pingcap pingcap deleted a comment from ti-chi-bot bot Jun 27, 2023
// GetApproximateTableCountFromStorage gets the approximate count of the table.
func (p *PDHelper) GetApproximateTableCountFromStorage(sctx sessionctx.Context, tid int64, dbName, tableName, partitionName string) (float64, bool) {
key := approximateTableCountKey(tid, dbName, tableName, partitionName)
if item := p.cacheForApproximateTableCountFromStorage.Get(key); item != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

GetApproximateTableCountFromStorage is the same as the old. but we add cache here.

@hawkingrei
Copy link
Member Author

/retest

1 similar comment
@hawkingrei
Copy link
Member Author

/retest

@@ -760,6 +761,7 @@ func setGlobalVars() {
} else {
executor.GlobalMemoryUsageTracker.SetBytesLimit(int64(cfg.Performance.ServerMemoryQuota))
}
executor.Start()
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 put this in setGlobalVars?
Seems a bit confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hope it is globally unique.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not in main()?

Copy link
Member

Choose a reason for hiding this comment

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

+1. My main points are:

  1. Currently, we only set up global states, i.e. setting global variables in setGlobalVars. But executor.Start() starts a background goroutine, which is quite different.
  2. If we call executor.Start() here and executor.Stop() in main(), they won't pair up and will make the code a bit confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -183,6 +184,16 @@ func init() {
CheckTableFastBucketSize.Store(1024)
}

// Start the backend components
Copy link
Member

Choose a reason for hiding this comment

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

I suggest add some comments since we are introducing the "backend components" new concept to this package.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

executor/internal/pdhelper/pd.go Show resolved Hide resolved
Copy link
Contributor

@chrysan chrysan left a comment

Choose a reason for hiding this comment

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

There's no ut in this PR, please do functional testing for this cache.

@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 3, 2023
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 3, 2023
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 3, 2023
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@hawkingrei
Copy link
Member Author

@chrysan @qw4990 PTAL

@ti-chi-bot ti-chi-bot bot deleted a comment from ti-chi-bot Jul 3, 2023
@ti-chi-bot ti-chi-bot bot added the lgtm label Jul 3, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jul 3, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrysan, 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:
  • OWNERS [chrysan,time-and-fate]

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

ti-chi-bot bot commented Jul 3, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-07-03 10:05:38.735168661 +0000 UTC m=+25570.668802081: ☑️ agreed by time-and-fate.
  • 2023-07-03 11:14:26.233520579 +0000 UTC m=+29698.167153999: ☑️ agreed by chrysan.

@ti-chi-bot ti-chi-bot bot merged commit 96dcbb7 into pingcap:master Jul 3, 2023
9 checks passed
@hawkingrei hawkingrei deleted the add_cache_cnt branch July 4, 2023 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add cache mechanism to line count estimation to reduce backend load
3 participants