Skip to content

executor: fix slow log push down bug (#68765)#68822

Open
ti-chi-bot wants to merge 4 commits into
pingcap:release-nextgen-202603from
ti-chi-bot:cherry-pick-68765-to-release-nextgen-202603
Open

executor: fix slow log push down bug (#68765)#68822
ti-chi-bot wants to merge 4 commits into
pingcap:release-nextgen-202603from
ti-chi-bot:cherry-pick-68765-to-release-nextgen-202603

Conversation

@ti-chi-bot
Copy link
Copy Markdown
Member

@ti-chi-bot ti-chi-bot commented Jun 1, 2026

This is an automated cherry-pick of #68765

What problem does this PR solve?

Issue Number: close #68758

bug 1: if the new line symbol is at the ending of internal chunk, the file scan will be finsihed too early because empty string will break the loop

bug 2: slow log has some time drift because record time and write time is different. We should tolerate it

Problem Summary:

What changed and how does it work?

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.

checked with real slow log files collected from user.

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

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved accuracy of slow query log filtering with time-range boundary handling.
    • Enhanced reverse-scan functionality for slow query logs, particularly with large entries.
  • Tests

    • Added comprehensive test coverage for slow-query reverse-scan edge cases and time boundary conditions.

lance6716 added 4 commits June 1, 2026 02:13
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
Signed-off-by: lance6716 <lance6716@gmail.com>
@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202603 labels Jun 1, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 1, 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 tammyxia 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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d4318ccc-00f4-406c-8130-e698d874ec54

📥 Commits

Reviewing files that changed from the base of the PR and between af202b4 and c7bfca9.

📒 Files selected for processing (2)
  • pkg/executor/slow_query.go
  • pkg/executor/slow_query_test.go

📝 Walkthrough

Walkthrough

This PR fixes a slow-log query regression by introducing internal time-tolerance boundaries during reverse-scan and file-discovery operations. The tolerance widens the search windows to prevent boundary-adjacent logs from being omitted, addressing the issue where queries returned fewer rows than expected.

Changes

Slow Query Time Tolerance Implementation

Layer / File(s) Summary
Time Tolerance Constant and Helper Functions
pkg/executor/slow_query.go
Defines slowLogTimeRangeInternalTolerance constant and introduces slowLogMayOverlapTimeRangeWithTolerance and slowLogTimeWithTolerance helpers that compute tolerance-adjusted time boundaries for overlap detection. Extracts line-splitting into splitSlowLogLines helper to normalize \r\n line endings and trim trailing empty lines.
Reverse-Scan and File-Discovery Updates
pkg/executor/slow_query.go
Updates reverse-scan initialization to widen minStartTime using tolerance, refactors file discovery (getAllFiles) to apply tolerance-adjusted comparisons when filtering candidate files, and modifies file-end time overlap checks and compressed-log pruning to use tolerance-widened boundaries instead of strict comparisons.
Test Helpers, Imports, and Extended Coverage
pkg/executor/slow_query_test.go
Normalizes pkg/meta/model import path, renames TestSplitbyColon to TestSplitByColon, adds getTimeColIdxFromRetrieverOutput helper to locate the "Time" column in retriever output, and extends TestSlowQueryRetrieverReversedScanWithLimit with a cross-chunk boundary case. Introduces new TestSlowQueryRetrieverReversedScanWithTimeJitter test validating forward and reverse scan behavior under millisecond jitter around time-range boundaries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/M, cherry-pick-approved, approved, lgtm, type/cherry-pick-for-release-nextgen-20251011

Suggested reviewers

  • gengliqi
  • wshwsh12
  • hawkingrei

Poem

🐰 A tolerance for time's gentle sway,
Where logs at boundaries won't slip away.
Wider windows catch each line with care,
Reverse scans now skip no logs out there! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing a slow log push down bug in the executor package, which aligns with the primary objectives of the PR.
Description check ✅ Passed The description identifies the linked issue (#68758), explains two specific bugs being fixed, lists completed tests, and follows the template structure despite being an automated cherry-pick.
Linked Issues check ✅ Passed The code changes directly address both bugs mentioned in issue #68758: introducing tolerance for time drift in slow log scanning [#68758] and fixing early termination when newlines fall at chunk boundaries [#68758].
Out of Scope Changes check ✅ Passed All changes are scoped to slow query execution logic: tolerance-adjusted time range comparisons, helper functions for overlap checking, newline handling refactoring, and corresponding test updates with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

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

Labels

release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202603

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants