Skip to content

[4.2-dev] fix(sql): preserve COMPRESS bytes and add opt-in V2 - #33563

Merged
XuPeng-SH merged 3 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:fix/compression-contract-33557
Dec 1, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:fix/compression-contract-33557

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Feature

Which issue(s) this PR fixes:

issue #33557

What this PR does / why we need it:

Go 1.27.1 changes the raw DEFLATE bytes produced for the same input. A shutdown upgrade changed the output of COMPRESS(REPEAT('A', 40)) from 13 to 51 bytes, so an existing generated unique key could be missed. This change freezes the released 4.2 encoder, preserves the framing and existing SQL identity of COMPRESS(), and reuses the writer within each vector.

Add explicit COMPRESS_V2() using the existing klauspost/compress v1.18.7 dependency at level 6 and UNCOMPRESS_V2() to decode complete V1 and V2 streams into a BLOB. The V2 decoder verifies the declared length and stream end, with a 64 MiB decoded-size limit.

The shared byte-function template preserves the input row count for constant NULL, constant evaluation errors, and empty selections. Skipped rows carry only NULL, and reused flat NULL results clear previous descriptors before serialization.

Function Persistent ID
COMPRESS_V2() 639
UNCOMPRESS_V2() 640

Both V2 functions register overloads in the order VARCHAR, CHAR, TEXT, BLOB. The IDs were checked against 4.2-dev and main and are recorded in #33558. ID 638 belongs to IVF_EXACT_PK_IN. The original UNCOMPRESS() repair is tracked in #33555.

Validation

  • Go 1.26.4 function-package race tests and Go 1.27.1 compression and function-ID race tests passed. The compression SQL BVT passed 73 cases on each toolchain with 2 existing skips.

  • The private writer matched all 697 reference frames from Go 1.26.4, including inputs that cross the window and hash-offset limits. The CI coverage parser reported 83.23% changed-block coverage on the local race-test profile.

  • Reopened a data directory written by the official v4.2.9 binary. V1 generated unique keys matched and rejected duplicate inserts with error 1062. Stored expressions using both V2 functions survived the toolchain change, writes, restart, and logical restore.

  • Local incremental static analysis, Go vet, molint, error constructor checks, and source license checks passed.

  • The 256-row article-text SQL p50 was 19.41 ms on the Go 1.26.4 base, 9.72 ms for pinned V1, and 4.96 ms for V2. Single-row SQL was 0.530 ms on the base and 0.532 ms for pinned V1. The batch sizes were 89,977 bytes for both V1 builds and 89,322 bytes for V2. The Go 1.27.1 derivative preserved the exact V1 and V2 frames.

  • The NULL-result follow-up in 4832b41066 preserves both rows in the reported LEFT JOIN/INSERT and the expected NULL row in MINUS. Vector and function race tests passed on Go 1.26.4, with focused race tests on Go 1.27.1. The compression BVT passed twice on local macOS arm64 with 80 passes and 2 existing skips per run. Pinned molint and incremental lint passed for the affected packages. Review finding

Merge this standalone change ahead of the toolchain upgrade in #33538.

@XuPeng-SH
XuPeng-SH requested a review from fengttt as a code owner December 1, 2026 04:01
@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 →

@mergify

mergify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: e324f5f531fc2163ac2378ec1b49ca0c53e5a20f

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: e324f5f531fc2163ac2378ec1b49ca0c53e5a20f

Assessment: request_changes

The new shared result path breaks NULL handling for legacy COMPRESS and both V2 functions. The reduced copy of the released encoder and reuse of the existing V2 dependency are reasonable ways to preserve stored bytes, but the integration must preserve result cardinality before this change is ready.

Model: gpt-6.1-terra / max

Session: 01a22af4-cf2a-7f70-88e4-931bbf57d739 · slot 2 · generation 14

  • P2 pkg/sql/plan/function/func_compress.go:53: COMPRESS or COMPRESS_V2 receives a constant-NULL vector, or UNCOMPRESS_V2 receives a constant-NULL or malformed constant input. A null-extended column from a left join with an empty right side is one reachable example.
    Impact: The result vector can have length zero for a nonempty batch. An INSERT from the join fails with an INVALID-INSERT-BATCH-DIFF-LENGTH error, and a MINUS query can drop an expected NULL row.
    Evidence: The helper in baseTemplate.go marks NULL bits but appends no result values in its constant-NULL, constant-error and all-ignored branches. Current-head unit and embedded SQL probes reproduced the failure for all three functions. The same SQL test succeeded for legacy COMPRESS when its target-base per-row implementation was restored in a control overlay; the V2 cases still failed. Preserve the result length in those branches and add regression coverage for the join and malformed-input cases.

Validation:

  • The isolated runtime preflight passed, and the native provenance audit matched 170 source inputs and six retained artifacts.

  • An independent Go 1.26.4 comparison passed for 71 complete streams, including writer resets and inputs beyond the hash-offset threshold.

  • The selected compression-frame, malformed-stream, overload-contract and function-ID tests passed with explicit Go 1.26.4 and Go 1.27.1 executables. The current-head NULL-cardinality and public SQL reproducers failed as described in the finding.

  • The baseline control restored only the target-base COMPRESS body: its COMPRESS case succeeded, while the V2 cases continued to fail. git diff --check passed. Receipts and logs are indexed in attempt-1/review-evidence-index.json.

Limitations:

  • The linked issue identifies commit 6c05e42 as v4.2.9 source, which specifies Go 1.26.4, but the release tag, official binary and applicable hotfix list were not independently available. The release reopen, restart, logical-restore, BVT and performance results remain author-reported.

  • The Go 1.27.1 function tests ran with sonic/ast using its encoding/json fallback. Several CI jobs were still in progress in the frozen snapshot.

@XuPeng-SH

XuPeng-SH commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 4832b410661e03af764567b00d693a0a7c020573

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 4832b410661e03af764567b00d693a0a7c020573

Assessment: approve

The prior review’s NULL-cardinality defect is resolved. The pinned encoder preserves the existing COMPRESS implementation, while the opt-in V2 functions reuse an existing compression dependency and have separate persistent IDs. The corresponding main-branch port is tracked in issue #33558.

Model: gpt-6.1-terra / max

Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45

Validation:

  • The isolated-runtime preflight and native-input audit passed on the assigned head: checks/1796102187256280262-3.json and checks/1796102187678737135-32.json.

  • Focused compression, malformed-input, function-ID, NULL-cardinality, and vector-reuse tests passed under Go 1.26.4 and Go 1.27.1: checks/1796102322225557246-3.json and checks/1796102585128296498-3.json.

  • The prior LEFT JOIN/INSERT and MINUS regressions passed through the single-CN SQL frontend: checks/1796102445557166866-3.json.

  • Reused the earlier review’s successful 71-stream comparison with Go 1.26.4; the copied encoder and module inputs are unchanged in this revision.

Limitations:

  • The v4.2.9 binary reopen, V2 restart and logical-restore checks, and performance figures were reported by the author; the release binary and raw logs were unavailable for independent replay.

  • The Go 1.27.1 run used sonic’s encoding/json fallback. A full distributed test suite was not rerun.

This branch was successfully deployed

No deployments
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/enhancement kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants