Skip to content

fix(function): optimize serial_extract for 3.0 (#24241) - #24255

Merged
5 commits merged into
matrixorigin:3.0-devfrom
jiangxinmeng1:fix/serial-extract-perf-24241-3.0
Apr 29, 2026
Merged

5 commits merged into
matrixorigin:3.0-devfrom
jiangxinmeng1:fix/serial-extract-perf-24241-3.0

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Apr 29, 2026 •

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 #24241

What this PR does / why we need it:

  • Cherry-pick of fix(function): optimize serial_extract to avoid full tuple deserialization #24246 to 3.0-dev branch
  • Add UnpackNthElement to deserialize only the Nth element from a serialized tuple, avoiding full deserialization
  • Add fast path in serial_extract for constant index parameter (the common case in DISTINCT queries on secondary index)
  • 7.9x speedup on DISTINCT queries over composite secondary index (14.9s → 1.9s aggregate phase on 5M rows)

Adaptation for 3.0

  • Removed yearCode case (not present in 3.0)
  • Adapted nil test case (3.0 Packer has no EncodeNull)

Test plan

  • Unit test TestUnpackNthElement passes
  • Local verification: 10M row table with 6-column composite index, DISTINCT aggregate 1209ms (vs ~15s without fix)
  • Builds successfully on 3.0-dev

🤖 Generated with Claude Code

@jiangxinmeng1
jiangxinmeng1 requested a review from a user April 29, 2026 09:01
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Apr 29, 2026
jiangxinmeng1 and others added 3 commits April 29, 2026 17:22
…ation (matrixorigin#24241)

When serial_extract is called with a constant index (the common case in
GROUP BY on composite secondary index), use UnpackNthElement to decode
only up to the target element instead of deserializing the entire tuple.
This reduces CPU overhead ~6x for DISTINCT queries on leading columns of
composite secondary indexes.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…tion

The BVT test expects "index out of range" without the index number.
Align UnpackNthElement's error message with the existing serial_extract
error format.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@ghost
ghost merged commit 3e1acd5 into matrixorigin:3.0-dev Apr 29, 2026
22 of 23 checks passed
This pull request was closed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants