Skip to content

Conversation

@Angel98518
Copy link

What problem does this PR solve?

Issue Number: close #65957

According to the description in Stale Read Product Design, SELECT ... AS OF TIMESTAMP should only be used in implicit transactions with autocommit = 1. However, we can still successfully execute the SELECT ... AS OF TIMESTAMP statement even with autocommit = 0.

What changed and how does it work?

This PR adds validation to prevent SELECT ... AS OF TIMESTAMP from being used when autocommit = 0. The validation:

  1. Recursively checks if any table in the SELECT statement has an AS OF clause
  2. Checks if autocommit is disabled (autocommit = 0)
  3. Returns an appropriate error message if both conditions are true

Changes:

  • Add hasAsOfClauseInResultSet() helper to recursively check for AS OF clauses in ResultSetNode
  • Add hasAsOfClauseInSetOpr() helper to check set operations (UNION, etc.)
  • Add validation in ResetContextOfStmt() for both SelectStmt and SetOprStmt
  • Return ErrWrongUsage when AS OF TIMESTAMP is used with autocommit = 0

Check List

Tests

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

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

Prevent `SELECT ... AS OF TIMESTAMP` from being used when autocommit = 0, as it should only be used in implicit transactions with autocommit = 1.

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=Angel98518

Issue Number: close pingcap#65957

According to Stale Read Product Design, SELECT ... AS OF TIMESTAMP
should only be used in implicit transactions with autocommit = 1.

This commit adds validation to prevent AS OF TIMESTAMP from being used
when autocommit = 0, returning an appropriate error message.

Changes:
- Add hasAsOfClauseInResultSet() helper to recursively check for AS OF clauses
- Add hasAsOfClauseInSetOpr() helper to check set operations
- Add validation in ResetContextOfStmt() for SelectStmt and SetOprStmt
- Return ErrWrongUsage when AS OF TIMESTAMP is used with autocommit = 0

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=Angel98518
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Feb 2, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 2, 2026

[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

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

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

@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 Feb 2, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 2, 2026

Hi @Angel98518. 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 Feb 2, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 2, 2026

Welcome @Angel98518!

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

pingcap-cla-assistant bot commented Feb 2, 2026

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 2, 2026

[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 d3hunter 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

@tiprow
Copy link

tiprow bot commented Feb 2, 2026

Hi @Angel98518. 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.

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.

@Angel98518
Copy link
Author

/ok-to-test

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 2, 2026

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

Details

In response to this:

/ok-to-test

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.

@tiprow
Copy link

tiprow bot commented Feb 2, 2026

@Angel98518: 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.

Details

In response to this:

/ok-to-test

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.

@lance6716
Copy link
Contributor

#65960

This PR is earlier, please wait for it.

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 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent SELECT ... AS OF TIMESTAMP from being used during implicit txn with autocommit = 0.

2 participants