Skip to content

fix(function): make COMPRESS MySQL compatible - #27965

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-23021
Sep 1, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-23021

Conversation

@Lundomn

@Lundomn Lundomn commented Sep 1, 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:

close #23021

What this PR does / why we need it:

Root cause

COMPRESS and UNCOMPRESS claimed to use zlib but actually used raw DEFLATE. As a result, MatrixOne output was not MySQL compatible, MySQL-compressed values could not be decoded, empty input had different behavior, and the untrusted length prefix could drive a large allocation. UNCOMPRESS also returned VARCHAR, which did not preserve arbitrary binary data.

Changes

  • Encode the MySQL format: a 4-byte little-endian original-length prefix followed by a zlib stream.
  • Match MySQL empty-input, trailing-space marker, length-mask, and output-capacity semantics.
  • Bound compression and decompression output by MaxBlobLen and grow buffers only with actual output.
  • Return BLOB from UNCOMPRESS.
  • Keep previously persisted MatrixOne raw-DEFLATE values readable.
  • Add deterministic unit, boundary, failure-path, fuzz, and distributed SQL regression coverage.

Compatibility and boundaries

New MatrixOne versions can read both MySQL zlib values and legacy MatrixOne raw-DEFLATE values. Older MatrixOne versions cannot read newly written zlib values. Invalid or oversized compressed data returns NULL; MatrixOne does not currently emit the same zlib warnings as MySQL.

Validation

  • Full pkg/sql/plan/function tests: PASS, 61.6% package coverage; go tool cover -func total 64.8% (both increased by 0.3 percentage points from baseline).
  • Changed compression functions: 76% to 100% coverage.
  • Focused race tests: PASS.
  • Fuzz after final rebase: PASS, 9,965 executions and 70 interesting inputs in 10 seconds.
  • go vet and scoped molint: PASS.
  • make build-with-prebuilt-native: PASS.
  • Protocol E2E on the newly built server, including text protocol, prepared binary values, dynamic columns, NULL, invalid data, long input, and BLOB metadata: PASS twice.
  • MySQL 8.0.42 interoperability in both directions: PASS.
  • git diff --check, gofmt, license header, and dependency license checks: PASS.

Tests not run

  • The Java mo-tester BVT runner was unavailable because this host has no JRE. The modified distributed SQL cases were exercised through direct protocol E2E instead.
  • Scoped golangci-lint could not complete because its importer cannot decode Go 1.27 export data version 4, including standard-library packages. go vet, molint, compilation, and tests all completed successfully.

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

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep-reviewed exact head c0044a4cc6a5ab1843546aae44c443a0db9389b8 against base/merge-base cf6bcf79edffa68c7bb09a1d39dbc2eeba6afa65, including every production/test hunk, issue #23021, MySQL's reference implementation and binary-string contract, function overload/type consumers, legacy raw-DEFLATE compatibility, length masking/capacity semantics, invalid and oversized inputs, and the compression-stream Q1–Q3 resource/boundedness paths.

The implementation matches the relevant MySQL semantics: a four-byte masked length prefix plus zlib stream, empty-input behavior, the trailing-space marker, capacity rather than exact advertised-length handling, BLOB output metadata, and 0 for short non-NULL UNCOMPRESSED_LENGTH input. Previously persisted MatrixOne raw-DEFLATE values remain readable. Compression and decompression grow only to MaxBlobLen; every zlib/flate reader or writer is closed exactly once on success and failure; all I/O is bounded in-memory work, with no leaked resource or unbounded wait/accumulation path.

The increment from the earlier exact head 09127bd1707c4d4ce04b6dbdfd97271c285050fe changes only the BVT expectation for the intentional BLOB/JDBC rendering of the Unicode bytes. It now matches the exact output observed when the prior head executed the case (and the established AES binary-function convention); production code and the other 78 passing statements are unchanged. Local exact-head focused compression/decompression tests passed 10 times and the full ./pkg/sql/plan/function suite passed once with the required CGO artifacts. New-head CI is still running, but no remaining correctness, lifecycle, compatibility, security, performance, or delivery blocker was found.

@mergify

mergify Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of exact head c0044a4cc6a5ab1843546aae44c443a0db9389b8 against base and merge-base cf6bcf79edffa68c7bb09a1d39dbc2eeba6afa65.

I read every production and test hunk, issue #23021, the official MySQL 8.4 Item_func_compress, Item_func_uncompress, and Item_func_uncompressed_length implementations, function registration and type consumers, previous MatrixOne raw-DEFLATE behavior, and exact-head validation.

No blocker found.

Correctness and compatibility: the implementation now emits the MySQL four-byte little-endian length plus zlib stream, preserves empty input and the trailing-space marker, masks the two reserved length bits, treats the stored length as output capacity, and returns binary BLOB metadata. New readers remain backward-compatible with persisted MatrixOne raw-DEFLATE values. The documented one-way rolling compatibility limitation is real and explicit.

Counterexamples and unhappy paths: short input, truncated streams, bad checksums, preset dictionaries, oversized and forged length headers, output shorter or longer than the advertised capacity, trailing bytes and concatenated streams, NULL and selected rows, arbitrary binary bytes, Unicode, and legacy empty/raw streams all reach bounded terminal behavior. Every zlib or flate reader is closed exactly once after creation. No shared state, wait chain, retry loop, log path, or persistent resource is introduced.

Performance and boundedness: compression and decompression remain linear in processed bytes and are capped by types.MaxBlobLen at 64 MiB. Buffer growth follows actual output instead of eagerly allocating an untrusted advertised size. Legacy fallback adds one bounded raw-DEFLATE attempt only after zlib rejection; there is no unbounded amplification or log storm.

Evidence reused at this exact head: build, Linux UT, coverage, SCA, and both executable BVT jobs are green; the changed func_string_compress.test is present in the BVT selection log. The focused compression tests and full owning-package run recorded by the other exact-head review also pass. I did not substitute a local Darwin run because this isolated worktree does not contain matching native CGo artifacts.

@mergify mergify Bot added the queued label Sep 1, 2026
@mergify

mergify Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-01 12:02 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-01 12:21 UTC · at 936ed713dd2a4375be289344a06390461e2d5494

This pull request spent 18 minutes 49 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #27965 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit f551799 into matrixorigin:main Sep 1, 2026
25 of 26 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 1, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

close matrixorigin#23021

## What this PR does / why we need it:

### Root cause

`COMPRESS` and `UNCOMPRESS` claimed to use zlib but actually used raw
DEFLATE. As a result, MatrixOne output was not MySQL compatible,
MySQL-compressed values could not be decoded, empty input had different
behavior, and the untrusted length prefix could drive a large
allocation. `UNCOMPRESS` also returned `VARCHAR`, which did not preserve
arbitrary binary data.

### Changes

- Encode the MySQL format: a 4-byte little-endian original-length prefix
followed by a zlib stream.
- Match MySQL empty-input, trailing-space marker, length-mask, and
output-capacity semantics.
- Bound compression and decompression output by `MaxBlobLen` and grow
buffers only with actual output.
- Return `BLOB` from `UNCOMPRESS`.
- Keep previously persisted MatrixOne raw-DEFLATE values readable.
- Add deterministic unit, boundary, failure-path, fuzz, and distributed
SQL regression coverage.

### Compatibility and boundaries

New MatrixOne versions can read both MySQL zlib values and legacy
MatrixOne raw-DEFLATE values. Older MatrixOne versions cannot read newly
written zlib values. Invalid or oversized compressed data returns
`NULL`; MatrixOne does not currently emit the same zlib warnings as
MySQL.

### Validation

- Full `pkg/sql/plan/function` tests: PASS, 61.6% package coverage; `go
tool cover -func` total 64.8% (both increased by 0.3 percentage points
from baseline).
- Changed compression functions: 76% to 100% coverage.
- Focused race tests: PASS.
- Fuzz after final rebase: PASS, 9,965 executions and 70 interesting
inputs in 10 seconds.
- `go vet` and scoped `molint`: PASS.
- `make build-with-prebuilt-native`: PASS.
- Protocol E2E on the newly built server, including text protocol,
prepared binary values, dynamic columns, NULL, invalid data, long input,
and BLOB metadata: PASS twice.
- MySQL 8.0.42 interoperability in both directions: PASS.
- `git diff --check`, gofmt, license header, and dependency license
checks: PASS.

### Tests not run

- The Java mo-tester BVT runner was unavailable because this host has no
JRE. The modified distributed SQL cases were exercised through direct
protocol E2E instead.
- Scoped `golangci-lint` could not complete because its importer cannot
decode Go 1.27 export data version 4, including standard-library
packages. `go vet`, `molint`, compilation, and tests all completed
successfully.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

close matrixorigin#23021

## What this PR does / why we need it:

### Root cause

`COMPRESS` and `UNCOMPRESS` claimed to use zlib but actually used raw
DEFLATE. As a result, MatrixOne output was not MySQL compatible,
MySQL-compressed values could not be decoded, empty input had different
behavior, and the untrusted length prefix could drive a large
allocation. `UNCOMPRESS` also returned `VARCHAR`, which did not preserve
arbitrary binary data.

### Changes

- Encode the MySQL format: a 4-byte little-endian original-length prefix
followed by a zlib stream.
- Match MySQL empty-input, trailing-space marker, length-mask, and
output-capacity semantics.
- Bound compression and decompression output by `MaxBlobLen` and grow
buffers only with actual output.
- Return `BLOB` from `UNCOMPRESS`.
- Keep previously persisted MatrixOne raw-DEFLATE values readable.
- Add deterministic unit, boundary, failure-path, fuzz, and distributed
SQL regression coverage.

### Compatibility and boundaries

New MatrixOne versions can read both MySQL zlib values and legacy
MatrixOne raw-DEFLATE values. Older MatrixOne versions cannot read newly
written zlib values. Invalid or oversized compressed data returns
`NULL`; MatrixOne does not currently emit the same zlib warnings as
MySQL.

### Validation

- Full `pkg/sql/plan/function` tests: PASS, 61.6% package coverage; `go
tool cover -func` total 64.8% (both increased by 0.3 percentage points
from baseline).
- Changed compression functions: 76% to 100% coverage.
- Focused race tests: PASS.
- Fuzz after final rebase: PASS, 9,965 executions and 70 interesting
inputs in 10 seconds.
- `go vet` and scoped `molint`: PASS.
- `make build-with-prebuilt-native`: PASS.
- Protocol E2E on the newly built server, including text protocol,
prepared binary values, dynamic columns, NULL, invalid data, long input,
and BLOB metadata: PASS twice.
- MySQL 8.0.42 interoperability in both directions: PASS.
- `git diff --check`, gofmt, license header, and dependency license
checks: PASS.

### Tests not run

- The Java mo-tester BVT runner was unavailable because this host has no
JRE. The modified distributed SQL cases were exercised through direct
protocol E2E instead.
- Scoped `golangci-lint` could not complete because its importer cannot
decode Go 1.27 export data version 4, including standard-library
packages. `go vet`, `molint`, compilation, and tests all completed
successfully.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

close matrixorigin#23021

## What this PR does / why we need it:

### Root cause

`COMPRESS` and `UNCOMPRESS` claimed to use zlib but actually used raw
DEFLATE. As a result, MatrixOne output was not MySQL compatible,
MySQL-compressed values could not be decoded, empty input had different
behavior, and the untrusted length prefix could drive a large
allocation. `UNCOMPRESS` also returned `VARCHAR`, which did not preserve
arbitrary binary data.

### Changes

- Encode the MySQL format: a 4-byte little-endian original-length prefix
followed by a zlib stream.
- Match MySQL empty-input, trailing-space marker, length-mask, and
output-capacity semantics.
- Bound compression and decompression output by `MaxBlobLen` and grow
buffers only with actual output.
- Return `BLOB` from `UNCOMPRESS`.
- Keep previously persisted MatrixOne raw-DEFLATE values readable.
- Add deterministic unit, boundary, failure-path, fuzz, and distributed
SQL regression coverage.

### Compatibility and boundaries

New MatrixOne versions can read both MySQL zlib values and legacy
MatrixOne raw-DEFLATE values. Older MatrixOne versions cannot read newly
written zlib values. Invalid or oversized compressed data returns
`NULL`; MatrixOne does not currently emit the same zlib warnings as
MySQL.

### Validation

- Full `pkg/sql/plan/function` tests: PASS, 61.6% package coverage; `go
tool cover -func` total 64.8% (both increased by 0.3 percentage points
from baseline).
- Changed compression functions: 76% to 100% coverage.
- Focused race tests: PASS.
- Fuzz after final rebase: PASS, 9,965 executions and 70 interesting
inputs in 10 seconds.
- `go vet` and scoped `molint`: PASS.
- `make build-with-prebuilt-native`: PASS.
- Protocol E2E on the newly built server, including text protocol,
prepared binary values, dynamic columns, NULL, invalid data, long input,
and BLOB metadata: PASS twice.
- MySQL 8.0.42 interoperability in both directions: PASS.
- `git diff --check`, gofmt, license header, and dependency license
checks: PASS.

### Tests not run

- The Java mo-tester BVT runner was unavailable because this host has no
JRE. The modified distributed SQL cases were exercised through direct
protocol E2E instead.
- Scoped `golangci-lint` could not complete because its importer cannot
decode Go 1.27 export data version 4, including standard-library
packages. `go vet`, `molint`, compilation, and tests all completed
successfully.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
ci — 936ed713 Deployed Sep 1, 2026 by mergify[bot] via Matrixone Utils CI / Coverage #49911
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQL function not implemented: COMPRESS

4 participants