Repository navigation
fix: clear grouped BIT aggregate result null bitmap - #29360
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
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
left a comment
There was a problem hiding this comment.
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
0d73177135to the current head; current-head CI additionally covers integration with the base.git diff --checkpassed 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") |
There was a problem hiding this comment.
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.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29323
What this PR does / why we need it:
Grouped
BIT_AND,BIT_OR, andBIT_XORCTAS failed withColumn '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
0d73177135adds 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
95b1d2bfd9; the full-capacity bitmap initialization and CTAS bitmap check establish the first violating owner.make cgo,make build, focusedTestBitOps*(three selected tests), fullpkg/sql/colexec/aggexecsuite,go vet ./pkg/sql/colexec/aggexec ./pkg/tests/sqlintegration, andgit diff --checkpassed locally.TestGroupedBitwiseCTASpassed 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.testpassed 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.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.