Skip to content

Conversation

@wfxr
Copy link
Member

@wfxr wfxr commented Feb 2, 2026

What problem does this PR solve?

Issue Number: close #65957

Problem Summary:

According to the Stale Read product design, SELECT ... AS OF TIMESTAMP should only be used in implicit transactions with autocommit=1. However, it was possible to execute such statements even when autocommit=0.

What changed and how does it work?

This change adds a check for !IsAutocommit() in OnSelectTable and OnExecutePreparedStmt methods in pkg/sessiontxn/staleread/processor.go to properly reject AS OF TIMESTAMP queries when autocommit is disabled.

The error message is also updated from:

as of timestamp can't be set in transaction.

to:

as of timestamp can't be set in transaction or when autocommit is disabled.

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.

`SELECT ... AS OF TIMESTAMP` now returns an error when `autocommit=0`, aligning with the stale read design.

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

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

@wfxr
Copy link
Member Author

wfxr commented Feb 2, 2026

/retest

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.6046%. Comparing base (bbeaafd) to head (53a659e).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #65960        +/-   ##
================================================
- Coverage   77.7751%   77.6046%   -0.1705%     
================================================
  Files          2001       1923        -78     
  Lines        545618     533201     -12417     
================================================
- Hits         424355     413789     -10566     
+ Misses       119601     119406       -195     
+ Partials       1662          6      -1656     
Flag Coverage Δ
integration 41.5172% <83.3333%> (-6.6427%) ⬇️
unit 76.7217% <100.0000%> (+0.3203%) ⬆️

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

Components Coverage Δ
dumpling 56.7974% <ø> (ø)
parser ∅ <ø> (∅)
br 48.8730% <ø> (-12.0941%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wfxr wfxr force-pushed the stale-read/65957 branch from a0998ed to f58b7fe Compare February 2, 2026 07:33
@wfxr
Copy link
Member Author

wfxr commented Feb 2, 2026

/retest

wfxr added 2 commits February 2, 2026 18:33
According to the Stale Read product design, `SELECT ... AS OF TIMESTAMP`
should only be used in implicit transactions with autocommit=1. However,
it was possible to execute such statements even when autocommit=0.

This change adds a check for `!IsAutocommit()` in `OnSelectTable` and
`OnExecutePreparedStmt` methods to properly reject AS OF TIMESTAMP
queries when autocommit is disabled.

Close pingcap#65957
… change

Update the expected result to expect error 8135 when executing
AS OF TIMESTAMP query with autocommit disabled, matching the
behavior change in commit f58b7fe.
@wfxr wfxr force-pushed the stale-read/65957 branch from 54b1959 to 53a659e Compare February 2, 2026 10:33
@wfxr
Copy link
Member Author

wfxr commented Feb 2, 2026

/retest

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

Labels

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.

1 participant