Skip to content

fix(sql): align signed-zero index and vector HLL semantics - #29122

Merged
XuPeng-SH merged 4 commits into
mainfrom
issue/28695-28861-signed-zero
Sep 20, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
issue/28695-28861-signed-zero

Conversation

@XuPeng-SH

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:

Fixes #28695
Fixes #28861

What this PR does / why we need it:

Root cause

  • FLOAT/DOUBLE regular-index tuple keys preserve -0.0 and +0.0 as different physical bytes, while SQL predicates equate them. Index access conditions could therefore omit one SQL-equal row.
  • Vector HLL_ADD_AGG hashed raw vector bytes, while vector equality, GROUP BY, exact DISTINCT, and approximate DISTINCT use canonical vector keys.

Design and implementation

  • Reject FLOAT/DOUBLE secondary-index access conditions for equality, IN/BETWEEN, ranges, in_range, and OR combinations; retain the existing physical index encoding and evaluate the predicate on the base row.
  • Use the existing typed canonical key codec for new vector HLL_ADD_AGG states (v4 wire). Restored v2 states retain their raw hash domain; mixed non-empty v2/v4 merges are rejected instead of silently changing semantics. Rebuild from source rows is the migration path for historical v2 vector states.
  • Add MORPC v88 gating for canonical vector HLL_ADD. Remote workers on v77-v87 explicitly emit the raw v2 vector state so old and new workers cannot mix hash domains.
  • Add focused UTs, protocol/accounting/partial/persisted-state coverage, and BVT case/result pairs for both issues.

Validation evidence

  • git diff --check: PASS
  • gofmt -l on all changed Go files: PASS
  • GOWORK=off go list -mod=readonly ./pkg/sql/plan ./pkg/sql/colexec/aggexec ./pkg/sql/colexec/group ./pkg/sql/compile ./pkg/defines: PASS
  • Focused UTs: NOT VERIFIED. Native compilation is blocked on this machine by missing roaring.h, usearch.h, xxhash.h, and jemalloc.h.
  • Incremental SCA package closure: pkg/defines, pkg/sql/plan, pkg/sql/colexec/aggexec, pkg/sql/colexec/group, pkg/sql/compile.
  • Incremental go vet: NOT VERIFIED; the same missing native headers block package loading.
  • Incremental golangci-lint: NOT VERIFIED; local v2.5.0 binary was built with Go 1.24.4 while the repository targets Go 1.26.4.
  • BVT: NOT VERIFIED; no mo-tester is available in the environment. Added and format-checked:
    • test/distributed/cases/optimizer/issue_28695_signed_zero_index.test/.result
    • test/distributed/cases/function/issue_28861_vector_signed_zero.test/.result

QA, rollback, and remaining risk

  • QA covers signed-zero equality/IN/range/OR/prepared predicates, FLOAT and DOUBLE, unique-index control, composite-prefix residual filtering, vector f32/f64 exact/approx/HLL/group semantics, partial merge, persisted v2 append, and accounted scratch allocation.
  • Rollback is a normal branch/PR revert. The float-index change may reduce index selectivity/performance for float predicates until a decoded SQL-aware index access path is implemented.
  • Existing persisted raw v2 vector HLL states remain readable and raw-compatible; merging them with new v4 states fails explicitly and requires rebuilding from source rows.
  • GPU validation is not applicable to these SQL/index aggregate changes.

Review

  • GPT-6 medium final review: APPROVED after the compatibility and BVT fixes above.

@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 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

COMMENT — PASS at exact head 096cdebcf9b3e7988984dd8efcbc964c23593eb9; self-authored PR, so comment only. No actionable P0–P2 findings.

Traced index access/residual/order paths and vector HLL signed-zero canonicalization, serialization, compatibility, scratch ownership and cleanup. FLOAT/DOUBLE index access remains conservatively rejected; vector HLL inputs are not mutated; incompatible nonempty v2/v4 merges reject; MORPC v88 gates new producers. Exact-head CI is green.

Evidence gaps remain around individual regression execution, mixed-version deployment, repeated prepared/index-DDL execution, and NaN/BF16/F16 boundary behavior. Historical nonempty v2 vector sketches require rebuilding before merging with new v4 sketches.

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/L Denotes a PR that changes [500,999] lines

Projects

None yet

2 participants