Repository navigation
fix(function): make COMPRESS MySQL compatible - #27965
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? |
aptend
left a comment
There was a problem hiding this comment.
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.
|
Queued — the merge queue status continues in this comment ↓. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 18 minutes 49 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull 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.
Failing checks:
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
## 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>
## 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>
## 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>
What type of PR is this?
Which issue(s) this PR fixes:
close #23021
What this PR does / why we need it:
Root cause
COMPRESSandUNCOMPRESSclaimed 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.UNCOMPRESSalso returnedVARCHAR, which did not preserve arbitrary binary data.Changes
MaxBlobLenand grow buffers only with actual output.BLOBfromUNCOMPRESS.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
pkg/sql/plan/functiontests: PASS, 61.6% package coverage;go tool cover -functotal 64.8% (both increased by 0.3 percentage points from baseline).go vetand scopedmolint: PASS.make build-with-prebuilt-native: PASS.git diff --check, gofmt, license header, and dependency license checks: PASS.Tests not run
golangci-lintcould 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.