gongxun0928 opened a new pull request, #1864:
URL: https://github.com/apache/cloudberry/pull/1864

   Fixes #1767
   
   ### What does this PR do?
   
   Fixes a segment crash (SIGSEGV) that occurs when PAX tables with 
`minmax_columns` containing numeric types (int, bigint, numeric) undergo 
repeated DELETE operations. The crash happens in `datumCopy()` during the 
visibility-map statistics refresh path (`MicroPartitionStats::MergeRawInfo()`).
   
   Two bugs are fixed in 
`contrib/pax_storage/src/cpp/storage/micro_partition_stats.cc`:
   
   1. **Wrong type metadata in `FromValue()`**: The serialized SUM value was 
deserialized using the column's physical type (`typlen`/`typbyval`) instead of 
the SUM aggregate's return type (`rettyplen`/`rettypbyval`). For example, 
`sum(bigint)` returns `numeric`, so the stored SUM datum must be interpreted as 
`numeric`, not as `int8`. This mismatch produced an invalid `Datum` that 
crashed in `datumCopy()`.
   
   2. **Swapped arguments in `datumCopy()`**: The call passed `(value, typlen, 
typbyval)` but the wrapper signature is `datumCopy(value, typByVal, typLen)`. 
This swapped pass-by-value/pass-by-reference flags, leading to memory 
corruption.
   
   ### Type of Change
   - [x] Bug fix (non-breaking change)
   
   ### Breaking Changes
   None.
   
   ### Test Plan
   - [x] Unit tests added/updated — new regression test `delete_sum_stats` 
covering DELETE + INSERT + DELETE on int, bigint, and numeric columns with 
`minmax_columns` enabled
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   ### Impact
   
   **Performance:**
   None — fix only affects correctness of stats merging, not the hot path.
   
   **User-facing changes:**
   Fixes a crash that users could hit with DELETE on PAX tables with 
minmax_columns.
   
   **Dependencies:**
   None.
   
   ### Checklist
   - [x] Followed [contribution 
guide](https://cloudberry.apache.org/contribute/code)
   - [x] Added/updated documentation (regression test included)
   - [x] Reviewed code for security implications
   - [ ] Requested review from [cloudberry 
committers](https://github.com/orgs/apache/teams/cloudberry-committers)
   
   ### Additional Context
   
   Root cause analysis and reproduction steps are documented in issue #1767. 
The crash stack trace shows the failure path:
   
   ```
   libpostgres.so datumCopy
   pax.so cbdb::datumCopy
   pax.so pax::MicroPartitionStats::MergeRawInfo
   pax.so pax::MicroPartitionStatsUpdater::Update
   pax.so pax::TableDeleter::UpdateStatsInAuxTable
   pax.so pax::TableDeleter::DeleteWithVisibilityMap
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to