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

context, executor: add a function to detach the TableReaderExecutor #54456

Merged
merged 1 commit into from
Jul 19, 2024

Conversation

YangKeao
Copy link
Member

@YangKeao YangKeao commented Jul 4, 2024

What problem does this PR solve?

Issue Number: close #53336

Problem Summary:

It's not safe to call Next (or other method) of an executor after the session is executing the next statement. We have split out a lot of Context and it's clear that the context depended by the TableReaderExecutor is safe to be re-used (after proper configuration) while executing another statement is running on the session.

What changed and how does it work?

This PR adds a Detach function to the executor package. After calling Detach, the session can be used to run other statements. It depends on the following assumption:

  • The StmtCtx will not be re-used. (For cursor-fetch scenario, it guaranteed by the logic inside ResetContextOfStmt).

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.

Release note

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner labels Jul 4, 2024
@YangKeao YangKeao changed the title context, executor: add a function to detach the TableReaderExecutor context, executor: add a function to detach the TableReaderExecutor Jul 4, 2024
@ti-chi-bot ti-chi-bot bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 4, 2024
@YangKeao YangKeao requested a review from lcwangchao July 4, 2024 10:43
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 4, 2024
@YangKeao YangKeao force-pushed the detach-executor branch 5 times, most recently from 0e754c7 to 28e5899 Compare July 4, 2024 11:50
Copy link

codecov bot commented Jul 4, 2024

Codecov Report

Attention: Patch coverage is 91.03448% with 13 lines in your changes missing coverage. Please review.

Project coverage is 56.3085%. Comparing base (cb6f913) to head (b3047b6).
Report is 3 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54456         +/-   ##
=================================================
- Coverage   72.7971%   56.3085%   -16.4887%     
=================================================
  Files          1553       1671        +118     
  Lines        437399     605844     +168445     
=================================================
+ Hits         318414     341142      +22728     
- Misses        99376     241346     +141970     
- Partials      19609      23356       +3747     
Flag Coverage Δ
integration 37.0288% <8.2758%> (?)
unit 71.7560% <91.0344%> (-0.0627%) ⬇️

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

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

pkg/expression/contextstatic/exprctx.go Outdated Show resolved Hide resolved
newCtx := treCtx

if ctx, ok := treCtx.ectx.(*contextsession.SessionExprContext); ok {
staticExprCtx := ctx.IntoStatic()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to make IntoStatic a static function and receives exprctx.BuildContext as input? So that we will need to try to cast the expr ctx to SessionExprContext

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a little weird. I think it'd be better to announce that it can only handle the SessionExprContext, as we may have many other implementations for exprctx.BuildContext.

For example, the NullRejectCheckExprContext { *SessionExprContext } also implements the exprctx.BuildContext. If we are going to implement a standalone static IntoStatic function, it'll have to handle this case. It's not easy to maintain all possible implementations in that function (though the only possible branch is the *contextsession.SessionExprContext).

@YangKeao
Copy link
Member Author

YangKeao commented Jul 8, 2024

/retest

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 9, 2024
@YangKeao YangKeao requested a review from qw4990 July 10, 2024 03:08
@YangKeao
Copy link
Member Author

/retest

@YangKeao YangKeao requested review from zanmato1984 and removed request for Rustin170506 July 10, 2024 03:25
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 10, 2024
Copy link

ti-chi-bot bot commented Jul 10, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-09 03:09:56.904139196 +0000 UTC m=+327094.139373311: ☑️ agreed by lcwangchao.
  • 2024-07-10 09:29:30.304411703 +0000 UTC m=+436267.539645813: ☑️ agreed by qw4990.

@zanmato1984 zanmato1984 requested review from XuHuaiyu and removed request for zanmato1984 July 10, 2024 11:06
@zanmato1984
Copy link
Contributor

@XuHuaiyu PTAL, thanks.

@YangKeao YangKeao force-pushed the detach-executor branch 2 times, most recently from 641b42e to 5ff6ee8 Compare July 15, 2024 05:20
@YangKeao
Copy link
Member Author

/retest

@YangKeao
Copy link
Member Author

/retest

1 similar comment
@YangKeao
Copy link
Member Author

/retest

// A simple way to fix it is to use the origianl SQLKiller, and wait for all cursor to be closed after
// receiving a kill signal and before resetting it. For now, it uses a newly created `SQLKiller` to avoid
// affecting the original one and keep safety.
newCtx.SQLKiller = &sqlkiller.SQLKiller{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to set the vars.SQLKiller instead of making a new one?

}
newChildren[i] = detached
}
copy(newExecutor.AllChildren(), newChildren)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little wired, can we use newExecutor.SetAllChildren(newChildren)

@YangKeao YangKeao force-pushed the detach-executor branch 2 times, most recently from 8b7c6de to c65147c Compare July 19, 2024 07:13
Copy link

ti-chi-bot bot commented Jul 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lcwangchao, qw4990, tangenta, XuHuaiyu

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 19, 2024
@YangKeao
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 13e4280 into pingcap:master Jul 19, 2024
23 checks passed
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a method to detach the context used by TableReaderExecutor
6 participants