Skip to content

planner, executor: allow tidb_request_source_type and tidb_low_resolution_tso in SET_VAR hints - #70797

Draft
cgtz wants to merge 1 commit into
pingcap:masterfrom
cgtz:casey-getz--setvar-request-source-low-res-tso
Draft

planner, executor: allow tidb_request_source_type and tidb_low_resolution_tso in SET_VAR hints#70797
cgtz wants to merge 1 commit into
pingcap:masterfrom
cgtz:casey-getz--setvar-request-source-low-res-tso

Conversation

@cgtz

@cgtz cgtz commented Sep 2, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: close #70796

Problem Summary:

tidb_request_source_type and tidb_low_resolution_tso can only be set for a whole session. Applications that share connections cannot tag a single query with a request source or let a single query read with a low-resolution TSO without affecting every following statement on the connection.

What changed and how does it work?

Both variables are now accepted by the SET_VAR optimizer hint, so they can be scoped to one statement:

SELECT /*+ SET_VAR(tidb_request_source_type='lightning') */ ... ;
SELECT /*+ SET_VAR(tidb_low_resolution_tso=ON) */ ... ;
  • pkg/sessionctx/variable/setvar_affect.go: mark both variables as verified hint-updatable.
  • pkg/executor/select.go: when the hinted variables are restored at the start of the next statement, also restore the transaction's request source type. The transaction copies the request source type once when it is activated and shares that struct with its snapshots, so the hinted value reaches the transaction through the statement's snapshot but was never undone, and a following COMMIT would prewrite/commit with the hinted source. TestRequestSource covers this.

tidb_low_resolution_tso needs no extra plumbing because the read TSO is requested after hints are applied.

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

Support setting `tidb_request_source_type` and `tidb_low_resolution_tso` for a single statement through the `SET_VAR` optimizer hint.
@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-tests-checked do-not-merge/needs-triage-completed labels Sep 2, 2026
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ti-chi-bot ti-chi-bot Bot added contribution This PR is from a community contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 2, 2026
@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

Hi @cgtz. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@ti-chi-bot ti-chi-bot Bot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Sep 2, 2026
@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

Welcome @cgtz!

It looks like this is your first PR to pingcap/tidb 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb. 😃

@pingcap-cla-assistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Casey Getz seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ti-chi-bot ti-chi-bot Bot added the sig/planner SIG: Planner label Sep 2, 2026
@cgtz
cgtz force-pushed the casey-getz--setvar-request-source-low-res-tso branch from fbc05ac to b4bf4e0 Compare September 2, 2026 02:05
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 2, 2026
@cgtz
cgtz force-pushed the casey-getz--setvar-request-source-low-res-tso branch from b4bf4e0 to 58bd6ad Compare September 2, 2026 03:34
@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 2, 2026
…tion_tso in SET_VAR hints

Mark both variables as verified hint-updatable so they can be scoped to a
single statement. A SET_VAR on tidb_request_source_type is also pushed into
an active transaction and restored with the session variable, because the
transaction copies the request source type when it is activated.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cgtz
cgtz force-pushed the casey-getz--setvar-request-source-low-res-tso branch from 58bd6ad to 3571ae7 Compare September 2, 2026 04:25
@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-tests-checked label, please finished the tests then check the finished items in description.

For example:

Tests <!-- At least one of them must be included. -->

- [x] Unit test
- [ ] Integration test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No code

‼️ Must keep the HTML comments <!-- At least one of them must be included. -->

📖 For more info, you can check the "Contribute Code" section in the development guide.

1 similar comment
@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-tests-checked label, please finished the tests then check the finished items in description.

For example:

Tests <!-- At least one of them must be included. -->

- [x] Unit test
- [ ] Integration test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No code

‼️ Must keep the HTML comments <!-- At least one of them must be included. -->

📖 For more info, you can check the "Contribute Code" section in the development guide.

@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign gmhdbjd for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. do-not-merge/needs-tests-checked do-not-merge/needs-triage-completed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

1 participant