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

table: Add CachedTableSupport and TemporaryTableSupport for MutateContext #54900

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

lcwangchao
Copy link
Collaborator

What problem does this PR solve?

Issue Number: close #54397

What changed and how does it work?

To avoid calling GetSessionVars in MutateContext, this PR added two extra methods GetCachedTableSupport and GetTemporaryTableSupport to handle temporary/cached tables in table operations. CachedTableSupport and GetTemporaryTableSupport are optional and can be nil in some scenes, ie, DDL reorg and lightning import.

This PR also changes the only method in AllocatorContext to AlternativeAllocators to return alternative allocators in context when allocating id. Now, it is only used by temporary table.

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. labels Jul 25, 2024
Copy link

tiprow bot commented Jul 25, 2024

Hi @lcwangchao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@lcwangchao lcwangchao force-pushed the mutatectx_temp_cached_table branch 2 times, most recently from fbe6501 to f1d2853 Compare July 25, 2024 06:48
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 4 lines in your changes missing coverage. Please review.

Project coverage is 56.0800%. Comparing base (1acb8f7) to head (f78c4a0).
Report is 10 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54900         +/-   ##
=================================================
- Coverage   72.8511%   56.0800%   -16.7712%     
=================================================
  Files          1558       1683        +125     
  Lines        438406     613413     +175007     
=================================================
+ Hits         319384     344002      +24618     
- Misses        99322     245909     +146587     
- Partials      19700      23502       +3802     
Flag Coverage Δ
integration 37.6189% <88.8888%> (?)
unit 71.7746% <87.5000%> (-0.0837%) ⬇️

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

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 52.6305% <ø> (+6.7562%) ⬆️

if tbl.TempTableType == model.TempTableGlobal {
if tempTbl := ctx.vars().GetTemporaryTable(tbl); tempTbl != nil {
if alloc := tempTbl.GetAutoIDAllocator(); alloc != nil {
return autoid.NewAllocators(false, alloc), true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why autoid.NewAllocators(false? Shouldn't it be autoid.NewAllocators(tbl.SepAutoInc()

What happen for this case, it uses a different autoid key encoding?

create global temporary table t (id int) on commit delete rows AUTO_ID_CACHE=1  

Copy link
Contributor

Choose a reason for hiding this comment

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

B.t.w, why we did not set Allocators for temp table in the past?
This function call increase object allocation by 1 op/s

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The code is from https://github.com/pingcap/tidb/pull/39041/files#diff-ccb2771ef1931990c0d0ce3703def7dd53bd21d00a8f6b40b59ca0115f776a60R1550
This PR does not change any code logic.

However, I think it's fine for the current code because the id allocation for memory table is pure in memory and does not share with other sessions.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 25, 2024
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 25, 2024
Copy link

ti-chi-bot bot commented Jul 25, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-25 08:49:44.931158098 +0000 UTC m=+1121406.922099564: ☑️ agreed by tiancaiamao.
  • 2024-07-25 10:48:20.942046838 +0000 UTC m=+1128522.932988322: ☑️ agreed by YangKeao.

Copy link

ti-chi-bot bot commented Jul 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tangenta, tiancaiamao, YangKeao

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 the approved label Jul 26, 2024
@ti-chi-bot ti-chi-bot bot merged commit 2ee8c99 into pingcap:master Jul 26, 2024
23 checks passed
morgo added a commit to morgo/tidb that referenced this pull request Jul 28, 2024
* upstream/master: (93 commits)
  disjoinset: add generic impl (pingcap#54917)
  planner: derive index filters for mv index paths (pingcap#54877)
  br: cli refactor backup error handling logic (pingcap#54697)
  expression: fix infinity loop in `timestampadd` (pingcap#54916)
  planner: import more expand test. (pingcap#54962)
  planner: use code-gen to generate CloneForPlanCache method for some operators (pingcap#54957)
  test: fix flaky test TestFailSchemaSyncer (pingcap#54958)
  planner: move logical show into logicalop pkg. (pingcap#54928)
  privilege: Remove TestAbnormalMySQLTable (pingcap#54925)
  resource_control: support unlimited keyword when setting the resource group (pingcap#54704)
  ddl: fix a data race on localRowCntListener Written() (pingcap#54484)
  lightning: fix SET SESSION on connection pool (pingcap#54927)
  planner: move logical mem-table to logicalop pkg. (pingcap#54903)
  table: Add `CachedTableSupport` and `TemporaryTableSupport` for `MutateContext` (pingcap#54900)
  executor: fix index_hash_join hang when context canceled (pingcap#54855)
  statistics: add metrics for unneeded analyze table (pingcap#54822)
  *: refine pipelined dml benchmarks (pingcap#54844)
  ddl: assign table IDs for jobs submitted to queue (pingcap#54880)
  *: avoid using Tables field of model.DBInfo, use API instead (pingcap#52302)
  planner: remove useless check (pingcap#54907)
  ...
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. 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.

Remove GetSessionVars in table.MutateContext
4 participants