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

*: make package sqlexec not depend on sessionctx anymore #52031

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Mar 22, 2024

What problem does this PR solve?

Issue Number: close #52029

Problem Summary:

sqlexec is a package that defines interfaces to execute SQL. The session in TiDB implements these interfaces in sqlexec. However, in most cases, the session is provided to the coder as the type sessionctx.Context, if the coder wants to execute some SQL there, they have to cast sessionctx.Context to sqlexec.SQLExecutor or sqlexec.RestrictedSQLExecutor like this:

sctx := ... // sctx has the type `sessionctx.Context`
sctx.(sqlexec.SQLExecutor).ExecuteInternal(sql)

The above operation is dangerous because we have an assumption that the variable sctx must also implement sqlexec.SQLExecutor and this assumption is not guaranteed by the compiler. If one day we introduced a new type that implements sessionctx.Context but not implements sqlexec.SQLExecutor, the above code will panic.

Why not to make sessionctx.Context implement sqlexec.SQLExecutor? Because it has a reverse dependency that sqlexec.SQLExecutor depends on sessionctx.Context. And it is another problem because it means any package want to use sqlexec will also depend on sessionctx which also brings a large number of dependencies.

It's better to make a change to let sessionctx to depend on sqlexec instead.

What changed and how does it work?

In this PR:

  • Make a new package sysproctrack and move some related interface definitions to it.
  • Make sqlexec depend on sysproctrack instead of sessionctx.
  • Make sessionctx.Context depend on sqlexec and added two methods on it:
    • GetSQLExectuor to get a SQLExecutor
    • GetRestrictedSQLExecutor to get a RestrictedSQLExecutor
  • Replace most codes such as sctx.(sqlexec.SQLExecutor) to sctx.GetRestrictedSQLExecutor() to make the code stronger.

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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 22, 2024
Copy link

tiprow bot commented Mar 22, 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/test-infra repository.

Copy link

codecov bot commented Mar 22, 2024

Codecov Report

Merging #52031 (667de1d) into master (f8accca) will decrease coverage by 17.0226%.
Report is 26 commits behind head on master.
The diff coverage is 88.4328%.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #52031         +/-   ##
=================================================
- Coverage   72.4146%   55.3920%   -17.0226%     
=================================================
  Files          1481       1597        +116     
  Lines        365306     615494     +250188     
=================================================
+ Hits         264535     340935      +76400     
- Misses        81220     251233     +170013     
- Partials      19551      23326       +3775     
Flag Coverage Δ
integration 37.2586% <60.4477%> (?)
unit 71.0995% <83.8345%> (-1.2055%) ⬇️

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

Components Coverage Δ
dumpling 53.9957% <ø> (-2.3014%) ⬇️
parser ∅ <ø> (∅)
br 52.0731% <0.0000%> (+5.7000%) ⬆️

Copy link

ti-chi-bot bot commented Mar 25, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-03-25 05:30:24.471121595 +0000 UTC m=+1873051.493367978: ☑️ agreed by hawkingrei.
  • 2024-03-25 09:26:51.38226711 +0000 UTC m=+1887238.404513500: ☑️ agreed by xhebox.

Copy link
Contributor

@BornChanger BornChanger left a comment

Choose a reason for hiding this comment

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

br part lgtm

Copy link

ti-chi-bot bot commented Mar 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BornChanger, hawkingrei, lance6716, tangenta, xhebox

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 Mar 25, 2024
@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Mar 25, 2024

@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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/test-infra repository.

@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Mar 25, 2024

@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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/test-infra repository.

@ti-chi-bot ti-chi-bot bot merged commit 40456f3 into pingcap:master Mar 25, 2024
38 checks passed
@lcwangchao lcwangchao deleted the sqlexec branch March 25, 2024 12:01
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make sqlexec not depend on sessionctx
6 participants