Skip to content

fix: clear grouped BIT aggregate result null bitmap - #29360

Merged
XuPeng-SH merged 5 commits into
mainfrom
codex/issue-29323-grouped-bit-ctas
Sep 24, 2026
Merged

XuPeng-SH merged 5 commits into
mainfrom
codex/issue-29323-grouped-bit-ctas

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Fixes #29323

What this PR does / why we need it:

Grouped BIT_AND, BIT_OR, and BIT_XOR CTAS failed with Column 'v' cannot be null, although direct and derived grouped SELECT returned non-NULL values. Aggregate state initializes the full allocated result bitmap as NULL. Flush() filled the logical groups but left NULL bits in unused capacity; the CTAS INSERT checks that bitmap globally and rejected the batch.

After materializing each logical group's value or neutral identity, clear the complete result NULL bitmap for both fixed-width and binary-string aggregate implementations. Accumulation and merge retain their existing NULL state. The INSERT NOT NULL check and CTAS schema are unchanged. BIT results remain non-NULL, including all-NULL groups.

Unit tests assert values, identities, and a fully clear result bitmap. The embedded Go SQL integration test exercises the public frontend. Follow-up commit 0d73177135 adds normal-result mo-tester coverage for grouped CTAS with all three operations over numeric, BINARY, and VARBINARY inputs. It also checks direct and derived SELECT controls, an all-NULL group, and a genuine NOT NULL insertion rejection.

Validation and review

  • Issue [Bug]: grouped CTAS with BIT_AND, BIT_OR, or BIT_XOR fails during materialization #29323 reproduced the pre-fix public SQL error in 3/3 rounds on 95b1d2bfd9; the full-capacity bitmap initialization and CTAS bitmap check establish the first violating owner.
  • make cgo, make build, focused TestBitOps* (three selected tests), full pkg/sql/colexec/aggexec suite, go vet ./pkg/sql/colexec/aggexec ./pkg/tests/sqlintegration, and git diff --check passed locally.
  • TestGroupedBitwiseCTAS passed in the original-head Ubuntu UT CI. The original-head SCA, shared build, and UT coverage CI passed. The follow-up commit changes only BVT SQL and expected results, so those Go-code checks remain applicable to the same source.
  • test/distributed/cases/function/func_aggr_bitwise.test passed twice on the same freshly built single-instance service in normal result-comparison mode: each run had 187 total, 181 successful, six existing ignored, zero failed or abnormal. The new statements were executed; no test tables remained after either run.
  • Independent GPT-6 Astra design and full-change reviews passed with no unresolved blocker. This is a focused result-contract fix; no shared state, persistent format, or distributed protocol changes were introduced.

CI status and rollback

The previous multi-CN PROXY and PESSIMISTIC jobs failed before SQL execution because Quay rejected the pinned MinIO image pull with HTTP 401; the coverage merge then lacked their profiles. This infrastructure failure is tracked in #29367. The new commit's CI is pending. The local single-instance BVT does not establish multi-CN CI success.

Rollback: revert the grouped BIT aggregate fix and its associated test commits if a regression is found.

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

Add normal-result BVT coverage for grouped BIT_AND, BIT_OR, and BIT_XOR CTAS over integer, BINARY, and VARBINARY inputs. Check all-NULL identities, direct and derived SELECT controls, and a real NOT NULL constraint rejection.

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

Deep review of 1aad2df498ceb71808d9d9dfbb058705dc58c4fc (merge base 44e5226a21d7905a1d1e528d257321d2696c807b).

Recommendation: approve / no blocking findings. Submitted as COMMENT because the authenticated account is also the PR author. One non-blocking test-cost suggestion is attached inline.

Scope and correctness

Reviewed every hunk in all five changed files and traced the aggregate state, terminal Flush, output ownership, group consumer, and preinsert NOT NULL check. This is an ordinary focused bug fix; a separate feature design is unnecessary.

The cause and fix agree: aggregate state initializes NULL bits across allocated capacity; filling the logical groups alone leaves the tail set, while BatchDataNotNullCheck checks nulls.Any over the bitmap. Clearing the bitmap after neutral values are materialized restores the result-vector invariant in both fixed and byte implementations. It preserves the NULL-as-uninitialized marker during accumulation/merge and keeps actual NOT NULL enforcement intact.

Coverage includes BIT_AND/OR/XOR, numeric/BINARY/VARBINARY, ordinary and all-NULL groups, exact values, direct/derived SELECT controls, CTAS, and a genuine NULL insert rejected by a NOT NULL column. The new HasNull UT assertions observe the entire bitmap and directly catch the tail defect.

Unhappy paths and bounds

Check Review result
Q1: ownership / destruction Flush transfers vectors and detaches state pointers. Byte-path preallocation errors leave ownership with the executor; later SetBytesAt failure frees transferred outputs, while remaining vectors stay executor-owned. Successful outputs pass to group batches; executor and batch cleanup retain distinct owners. Clear adds no fallible allocation or ownership transfer.
Q2: waits / cancellation No new wait, goroutine, lock, or I/O in production. The SQL test uses the existing serialized shared fixture; rows/db are deferred closed and schema cleanup uses a fresh bounded context, including after assertion failure.
Q3: accumulation / memory No new accumulating state or retry loop. Clear reuses the existing bitmap storage. At the standard 8192-row aggregate chunk size, it clears up to 128 uint64 words (1 KiB) per output vector at terminal Flush.

Existing aggexec OOM/accounting tests cover byte fill/merge failure and wide-binary neutral-value output cleanup. No changed shared-state transition warrants an additional race run. API, wire/storage formats, tenant boundaries, and deployment configuration are unchanged.

Performance and engineering quality

The production change adds two terminal Clear calls and explanatory comments, with no new abstraction or framework. The extra work is proportional to bitmap capacity / 64, once per output vector, with no new allocations. This is a static cost assessment, not a throughput benchmark.

The shared SQL integration scenario currently executes nine CTAS statements. Combining the three input types per operation, as the BVT already does, would reduce this to three while retaining the nine result combinations. This is optional simplification, not a correctness blocker.

Validation evidence

  • Current-head enabled checks are green, including UT, UT coverage, SCA, both multi-CN BVT variants and required/summary checks: https://github.com/matrixorigin/matrixone/actions/runs/36032527630 . PR is mergeable.
  • Inspected existing focused BIT UT and full aggexec passing logs, plus the integration CI log (TestGroupedBitwiseCTAS, 22.46s). The latter is total test elapsed time, including fixture/admission effects; it does not establish DDL-only cost or quantify the suggested saving.
  • Inspected both same-instance BVT runs: each selected 187 cases, 181 passed, six pre-existing ignored, zero failed/abnormal; the new cases are not skipped. Recorded elapsed times were 11.751s and 10.317s.
  • The five reviewed source/test files are unchanged from validated pre-merge 0d73177135 to the current head; current-head CI additionally covers integration with the base. git diff --check passed and the review worktree is clean.

This review reused the inspected author/CI evidence; it did not rerun the test suites. No unresolved blocking correctness, cleanup, boundedness, or production-performance issue was found.

} {
for _, column := range []string{"b", "v"} {
table := schema + ".grouped_" + tc.fn + "_" + column
_, err := db.ExecContext(ctx, "create table "+table+" as select g, "+tc.fn+"("+column+") as value from "+schema+".src_binary group by g")

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.

Non-blocking test-cost simplification: this inner loop creates six binary CTAS tables in addition to the three numeric CTAS tables above. The BVT added in this PR already shows the smaller shape: one source with i, b, and v, then one CTAS per BIT operation containing all three result columns. Applying that shape here reduces nine CTAS statements to three while preserving all operation/type combinations, all-NULL neutral values, exact result assertions, and the direct/derived SELECT controls. Keep the existing shared fixture and cleanup; no new helper framework is needed. The observed 22.46s is total test time, so this suggestion does not claim a measured DDL saving.

@XuPeng-SH
XuPeng-SH merged commit 9875c6c into main Sep 24, 2026
23 of 25 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue-29323-grouped-bit-ctas branch September 24, 2026 19:16

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 kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: grouped CTAS with BIT_AND, BIT_OR, or BIT_XOR fails during materialization

2 participants