Repository navigation
Description
Goal
Land SQL compression compatibility as a standalone change on 4.2-dev ahead of the Go 1.27.1 upgrade in #33538. Support the current Go 1.26.4 toolchain and verify the same behavior under Go 1.27.1.
Why this is needed
COMPRESS() currently uses Go's standard-library DEFLATE encoder. In a local shutdown upgrade from v4.2.9 to Go 1.27.1 without pinning the encoder, 40 ASCII A characters compressed to 13 bytes before the upgrade and 51 bytes after it. A lookup by HEX(COMPRESS(s)) missed an existing stored unique key, and a second insert of the same source value succeeded. The same encoded value also stopped fitting in VARBINARY(32). Reproduction details in #33538
Scope
- Pin the encoder used by
COMPRESS()to the released 4.2 behavior. Preserve existing bytes, SQL function identity, and generated-column expressions. - Add opt-in
COMPRESS_V2()using level 6 of the existingklauspost/compress v1.18.7dependency. Give the new function its own persistent identity. - Add
UNCOMPRESS_V2()to read complete V1 and V2 streams into a BLOB, with bounded output and input validation. Track the fix for the originalUNCOMPRESS()separately in [Bug]: 4.2-dev UNCOMPRESS returns NULL for valid multi-block COMPRESS output #33555.
Acceptance
- Resolve the V2 function ID collision in this standalone compression PR. The draft in [4.2-dev] build: upgrade to Go 1.27.1 #33538 used 638 for
COMPRESS_V2, and 4.2-dev now assigns 638 toIVF_EXACT_PK_IN. Allocate separate free IDs for both V2 functions against the current 4.2-dev and main registries. Keep the existing IVF and compression IDs stable, and carry the final V2 IDs and overload order forward in D24 ([Subtask]: D24 [4.2-to-main] Preserve SQL compression contracts across the next major upgrade #33558). Collision evidence - Verify exact V1 and V2 bytes and round trips with both Go 1.26.4 and Go 1.27.1. Include binary data, empty and NULL values, multi-block streams, and corrupt input.
- Reopen a released 4.2 data directory and verify that stored V1 keys remain searchable and reject duplicates. Verify that stored V2 expressions retain their identity across restart and logical restore.
- Measure single-row and batch SQL performance and compressed size with both encoders. The existing 256-row article-text workload measured a p50 of 16.19 ms with V1 and 11.04 ms with V2. Measurements in #33538
Land this issue's standalone PR before merging the Go 1.27.1 upgrade in #33538. Rebase the upgrade on the merged compression change.
Activity
[4.2-dev] fix(sql): preserve COMPRESS bytes and add opt-in V2 (#33563)
XuPeng-SH commentedon Dec 1, 2026
独立验收补充,范围是 Go 1.26.4 的最终合入版本。用官方 v4.2.9 Linux/amd64 (
6c05e42) 创建含HEX(COMPRESS(s))的 STORED UNIQUE 列和VARBINARY(32)对照,干净停机。使用 精确合并等价制品(build024971e7,与4.2-dev合并efbab93e同树)打开同一原始数据目录。两侧二进制.go.buildinfo都是 Go 1.26.4。REPEAT('A',40)得到相同的 13 字节 V1 帧2800000072241200020000FFFF;重算键仍找到原行;重复源值仍返回 1062。旧压缩行可解出 40 字节,新压缩行仍能写入VARBINARY(32)。SHOW CREATE TABLE加逻辑行重放能在新表重建同一帧。UNCOMPRESS_V2解码 V1/V2 均保留00FF80,不完整输入与 NULL 对照按预期返回 NULL。三次服务日志均确认Shutdown complete。