Skip to content

pkg/planner: avoid eliminating max/min over binary literals - #67394

Merged
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
hawkingrei:issue-67040-repro-20260329
Mar 30, 2026
Merged

pkg/planner: avoid eliminating max/min over binary literals#67394
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
hawkingrei:issue-67040-repro-20260329

Conversation

@hawkingrei

@hawkingrei hawkingrei commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #67040

Problem Summary:

MAX/MIN over a binary literal can return different results depending on whether the GROUP BY
column is rewritten as a unique-key aggregation-elimination case. The eliminated path returned 42
with no warning, while the non-eliminated path returned 0 with warning 1292 Truncated incorrect DOUBLE value: '*'.

What changed and how does it work?

  • Skip aggregation elimination for MAX/MIN when the argument is a binary literal.
  • Add a planner regression case that covers both MAX and MIN for unique-key and plain GROUP BY
    schemas.

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

Summary by CodeRabbit

  • Bug Fixes

    • Corrected aggregation function handling for binary literal values to ensure consistent query output.
  • Tests

    • Added regression test validating aggregation query behavior with binary literals.

@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 28, 2026
@coderabbitai

coderabbitai Bot commented Mar 28, 2026

Copy link
Copy Markdown

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: 11186211-94f3-4591-81b6-076a453e16c9

📥 Commits

Reviewing files that changed from the base of the PR and between 682b45d and 558c99b.

📒 Files selected for processing (1)
  • pkg/planner/core/issuetest/planner_issue_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/planner/core/issuetest/planner_issue_test.go

📝 Walkthrough

Walkthrough

This PR addresses a regression where ABS(MAX(b'101010')) with GROUP BY produced inconsistent results depending on column constraints. The fix adds a regression test and modifies the aggregation elimination rule to prevent rewriting MAX/MIN expressions with binary literal arguments.

Changes

Cohort / File(s) Summary
Test case for binary literal aggregation regression
pkg/planner/core/issuetest/planner_issue_test.go
Adds test case abs-max-binary-literal-group-by-unique-key that verifies ABS(MAX(b'101010')) with GROUP BY produces consistent results (0 rows with warning) regardless of column constraints (ZEROFILL NOT NULL UNIQUE).
Aggregation elimination rule update
pkg/planner/core/rule_aggregation_elimination.go
Modified rewriteExpr to skip aggregation elimination rewriting for MAX/MIN when the first argument is a binary literal; non-binary-literal arguments continue to be rewritten via wrapCastFunction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

release-note, size/M

Suggested reviewers

  • qw4990
  • AilinKid

Poem

🐰 A binary hop through MAX and MIN,
Where literals once led us to sin,
Now ZEROFILL won't confuse,
Constraints no longer abuse,
Aggregation flows true—we all win!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: preventing aggregation elimination for MAX/MIN over binary literals in the planner.
Linked Issues check ✅ Passed The PR successfully addresses issue #67040 by preventing aggregation elimination for MAX/MIN with binary literal arguments, ensuring consistent results across different GROUP BY schemas.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the MAX/MIN aggregation elimination bug: test case regression, planner logic update, and helper utilities.

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

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

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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.

…7040-repro-20260329

# Conflicts:
#	pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel
@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 Mar 28, 2026
@codecov

codecov Bot commented Mar 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.0335%. Comparing base (25eacc4) to head (558c99b).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #67394        +/-   ##
================================================
+ Coverage   77.7922%   79.0335%   +1.2413%     
================================================
  Files          2023       1960        -63     
  Lines        556481     547051      -9430     
================================================
- Hits         432899     432354       -545     
+ Misses       121834     113664      -8170     
+ Partials       1748       1033       -715     
Flag Coverage Δ
integration 45.0236% <62.5000%> (-3.1035%) ⬇️
unit 77.0311% <100.0000%> (+0.6846%) ⬆️

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

Components Coverage Δ
dumpling 61.5065% <ø> (ø)
parser ∅ <ø> (∅)
br 65.8676% <ø> (+5.0298%) ⬆️
🚀 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.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

@hawkingrei hawkingrei added the AI-Correction Bugfix by AI label Mar 30, 2026
@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 30, 2026

Copy link
Copy Markdown

Review failed due to infrastructure/execution failure after retries. Please re-trigger review.

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 30, 2026
@ti-chi-bot

ti-chi-bot Bot commented Mar 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, qw4990

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

The pull request process is described 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

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 30, 2026
@ti-chi-bot

ti-chi-bot Bot commented Mar 30, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-03-30 06:19:08.34162252 +0000 UTC m=+159553.546982577: ☑️ agreed by qw4990.
  • 2026-03-30 06:31:34.583567886 +0000 UTC m=+160299.788927933: ☑️ agreed by AilinKid.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

@ti-chi-bot
ti-chi-bot Bot merged commit 8c2319e into pingcap:master Mar 30, 2026
35 checks passed
@ti-chi-bot

ti-chi-bot Bot commented Mar 30, 2026

Copy link
Copy Markdown

@hawkingrei: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test-next-gen 558c99b link unknown /test pull-unit-test-next-gen

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

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

Labels

AI-Correction Bugfix by AI approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner 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.

Unexpected Result Difference in ABS and MAX Aggregation with ZEROFILL NOT NULL UNIQUE Constraints

3 participants