Skip to content

fix: support SUM() over boolean expressions for MySQL compatibility - #24625

Merged
mergify[bot] merged 6 commits into
matrixorigin:3.0-devfrom
ULookup:fix/sum-bool-support
May 29, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:3.0-devfrom
ULookup:fix/sum-bool-support

Conversation

@ULookup

@ULookup ULookup commented May 27, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24547

What this PR does / why we need it:

MySQL coerces booleans to 0/1 in numeric contexts, so SUM(boolean_expr) is a common idiom for counting rows matching a condition (e.g. SUM(status = 'ERROR') for error-rate rollups over agent-trace tables). MatrixOne currently rejects this with bad value [BOOL].

Changes:

  • Add T_bool to SumSupportedTypes and SumReturnType in pkg/sql/plan/function/agg/sum.go
  • Add bool→uint64 fill/merge functions (aggSumOfBoolFill, aggSumOfBoolFills, aggSumOfBoolMerge) since Go's bool doesn't satisfy the generic numeric constraint used by the existing fill functions
  • Register the bool overload in RegisterSum2

The pattern follows existing MIN/MAX bool support (pkg/sql/plan/function/agg/max.go:132).

@ULookup
ULookup requested review from aunjgr and ouyuanning as code owners May 27, 2026 07:30
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@CLAassistant

CLAassistant commented May 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mergify
mergify Bot requested a review from XuPeng-SH May 27, 2026 07:31
@mergify mergify Bot added the kind/bug Something isn't working label May 27, 2026
ULookup added 2 commits May 27, 2026 01:15
MySQL coerces booleans to 0/1 in numeric contexts, so SUM(boolean_expr)
is a common idiom for counting matching rows. Add T_bool to
SumSupportedTypes and register bool->uint64 overload.
The median computation test case previously expected a "bad value [BOOL]"
error from SUM(y.val <= x.val). Now that SUM() supports boolean input,
update the expected result to the correct median output.
@ULookup
ULookup force-pushed the fix/sum-bool-support branch from c1afb90 to 06db786 Compare May 27, 2026 08:16
@ULookup
ULookup requested a review from a user May 27, 2026 08:16

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed from multiple angles: SUM(bool) support is wired consistently across supported types, return type inference, bool-specific fill/fills/merge paths, and registration. The behavior matches MySQL semantics (true->1, false->0), the diff is clean, and I did not find a blocker-level issue in the current changes.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed. Implementation and test coverage for SUM(bool) look good to me.

@mergify mergify Bot added the queued label May 29, 2026
@mergify

mergify Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-29 07:45 UTC · Rule: release-3.0
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-05-29 08:40 UTC · at 08576750a2424234cd68d9984cb28cccd3647e40 · squash

This pull request spent 55 minutes 40 seconds in the queue, including 54 minutes 53 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

@mergify
mergify Bot merged commit 8bf15e4 into matrixorigin:3.0-dev May 29, 2026
23 of 24 checks passed

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants