Skip to content

fix: truncate floating BIT_COUNT inputs before counting bits - #30307

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/ed02c41e1648123295bbd560c4fb97f60da4539bd92bad6dd784f0b203b4a6e3
Oct 15, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/ed02c41e1648123295bbd560c4fb97f60da4539bd92bad6dd784f0b203b4a6e3

Conversation

@iamlinjunhong

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:

What this PR does / why we need it:

BIT_COUNT rounds fractional FLOAT/DOUBLE values before counting bits. For example, BIT_COUNT(CAST(3.5 AS DOUBLE)) returns 1 instead of MySQL's 2, and -3.5 returns 62 instead of 63.

Truncate FLOAT/DOUBLE inputs toward zero in their shared conversion helper and consolidate the signed conversion branch. Preserve existing saturation bounds, NaN errors, and architecture-safe negative integer conversion. DECIMAL keeps its existing rounding behavior. The conversion remains constant work per row with no allocations.

Extend the existing unit and SQL regressions for both floating types, signed fractions, zero/subunit values, NULL, clamp neighbors, prepared execution, and stored-column projections and filters. Retain integer, DECIMAL, string, and binary controls.

Validation on macOS arm64 with Go 1.27.1:

  • Reproduced the original SQL output 1 1 62 2 63; the fixed build returns 2 2 63 2 63.
  • Focused TestBitCount* tests and the full pkg/sql/plan/function package pass with -count=1 using the repository CGo wrapper.
  • Changed-package go vet and incremental golangci-lint pass (0 issues).
  • Built mo-service; normal mo-tester comparison of func_bit_count.test passes twice on the same isolated standalone instance (100/100 statements each). Verified fixture tables are removed after each run.

CI checks are pending. The issue remains open for the reporter to verify after merge.

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

@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 104aa83d33c4f3618bd3f7f3400e31828091b5c6

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 104aa83d33c4f3618bd3f7f3400e31828091b5c6

Assessment: approve

Reviewed the complete four-file delta and affected callers. Floating BIT_COUNT truncation belongs in the existing shared conversion helper. The change preserves boundary clamps, NaN errors, NULL handling and other numeric domains while removing unreachable logic. No actionable defects or material validation gaps remain. No additional allocation, state, I/O or concurrency cost was identified.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Verified the frozen head, merge-base and unchanged source; reconciled native-input provenance and successful repository-owned native build.

  • Passed 11 focused BIT_COUNT tests and all 2,084 top-level tests in pkg/sql/plan/function.

  • Passed two real SQL-session runs covering constants, projections, predicates, NULLs, SQL and binary prepared execution, and cleanup.

  • The regression test failed against the frozen-base function for both FLOAT and DOUBLE, then passed on the candidate.

  • go vet, formatting and diff checks passed. Commands, source fingerprints, exits and retained logs are reconciled in /home/xupeng/.local/state/mo-bot/jobs/4c320200bac1057c12762618/attempt-1/validation-audit.json; audit receipt 1792091370242251819-4.json records exit 0.

Limitations:

  • Local validation used Linux amd64 and a targeted real SQL probe, not the complete mo-tester result-file comparison. Raw CI and author validation logs were unavailable.

  • The linked issue body was absent; review assessed the supplied PR contract and regression examples.

  • No performance benchmark was run; the stateless conversion retains constant work per value.

@mergify mergify Bot added the queued label Oct 15, 2026
@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-15 19:12 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-15 20:52 UTC · at 69b62f152d2ec240f11dcf156c861e8bf742eb9c · squash

This pull request spent 1 hour 39 minutes 38 seconds in the queue, including 1 hour 2 minutes 16 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
ci — 706b2dd1 Deployed Oct 15, 2026 by mergify[bot]
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.

3 participants