Repository navigation
Description
Scope
Port the following six verified correctness fixes from 4.2-dev to main. This is a main-branch tracker, not a request to cherry-pick the referenced commits wholesale.
- Tested
main:87c44445f83e308ef12dd7ca0e570cec1e6690d9 - Compared with
4.2-dev:971bbf280fc94e914b1ad250a447002fbba69610 - Environment: macOS arm64, Go 1.27.1, fresh isolated
mo-servicebuilt from the tested main commit
Each item below was reproduced with SQL on that main build. Existing issues are linked where available; this tracker avoids opening duplicate bug reports.
Required fixes
1. Preserve the first ordering direction for repeated Top/MergeTop keys
References: #32396, 4.2-dev PR #32402.
CREATE TABLE t(id INT PRIMARY KEY, k INT);
INSERT INTO t VALUES (1,1),(2,2),(3,3),(4,4);
SELECT id,k FROM t ORDER BY k DESC,k ASC LIMIT 2;Main returns (1,1),(2,2). The first key is DESC, so the expected result is (4,4),(3,3). Reversing the two directions produces the opposite wrong result. Cover Top and MergeTop, NULL placement, spill, prepared reuse, and remote execution.
2. Keep prepared CTAS parameter ordinals aligned after projection pruning
Reference: 4.2-dev PR #32153. Only the prepared CTAS/placeholder portion is needed; the division and CTAS nullability fixes are already present on main.
SET @p1=11,@p2=22,@p3=33;
PREPARE p FROM
'CREATE TABLE t_mid AS SELECT a,c FROM
(SELECT CAST(? AS INT) a,CAST(? AS INT) b,CAST(? AS INT) c) s';
EXECUTE p USING @p1,@p2,@p3;
SELECT * FROM t_mid;Main returns a=11,c=22; expected a=11,c=33. The pruned middle placeholder must not shift the remaining parameter bindings. Also cover an unused placeholder and repeated execution.
3. Normalize raw prefix candidates before persisted pruning
References: #32822, 4.2-dev PR #32825. Main already has the nullable-vector guards and Shuffle sortedness preservation; this is the remaining raw empty/NUL prefix and persisted candidate-normalization case, not a request to port the whole PR.
CREATE TABLE t(k VARCHAR(64) PRIMARY KEY, id INT);
INSERT INTO t VALUES
('',1),('abc',2),('az',3),('zebra',4),
(CHAR(0),5),(CONCAT(CHAR(0),'xy'),6);
SELECT mo_ctl('dn','flush','test.t');
SELECT id FROM t WHERE prefix_in(k,(CHAR(0),'zz')) ORDER BY id;Main returns only 5,6; expected 4,5,6 because zz also matches zebra. Verify exact rows before and after flush/restart, empty and NUL prefixes, residual predicates, and NULL handling.
4. Rebuild DATA BRANCH lineage and protection after restore
References: #32820, 4.2-dev PR #32868.
After creating a database-level DATA BRANCH, snapshotting it, deleting it, and restoring the snapshot:
- restored rows remain readable and
dat_type='data-branch'; - the restored table has zero active lineage rows in
mo_catalog.mo_branch_metadata; DATA BRANCH DELETEfails withERROR 20101 ... is not an active branch table.
Restore must rebuild lineage and the necessary ancestor protection in the same transaction. Cover snapshot and PITR restore, table/database branches, ALTER history, rollback, sibling deletion, and cleanup.
5. Preserve exact ENUM member definitions through DDL and schema rebuilds
References: #30771, #32886, 4.2-dev PRs #32723 and #32887. This item is limited to the ENUM definition/replay work; unrelated SDK contract changes in #32723 are out of scope.
CREATE TABLE domain_src(
id INT PRIMARY KEY,
e ENUM('a,b','c','') NOT NULL DEFAULT 'a,b'
);
SHOW CREATE TABLE domain_src;Main renders the column as ENUM('a','b','c',''), incorrectly splitting the comma-bearing member. CREATE TABLE ... LIKE, ALTER TABLE ... MODIFY, and TRUNCATE/rebuild paths also fail to preserve the intended member mapping. Preserve declaration order, exact label bytes, ordinals, and legacy-data interpretation across replay and rebuilds.
6. Keep hidden ENUM/SET storage out of DISTINCT keys and recover visible values
Reference: 4.2-dev PR #32808.
On main, INSERT ... SELECT DISTINCT over ENUM values can produce duplicate visible values, and a direct framed-domain DISTINCT probe can fail with invalid argument cast to int. Hidden ENUM ordinals and SET bitmaps must not split identical visible tuples. After duplicate elimination, recover a canonical value from the visible result while preserving NULL, declared empty members, error ordinal zero, case-distinct labels, and domain remapping.
Validation required
For each item, provide a failing baseline and passing fixed result on the same main-based schema/data, plus focused regression tests and the relevant existing package/BVT suites. Compile-only evidence is not sufficient. Update the linked original issues when their main behavior changes.
The audit did not run the complete BVT. It excluded items whose semantics are already present on main and excluded optional performance work (#32459 and #32065) from this correctness tracker.
Activity
fix(sql): honor first ordering key in Top and MergeTop (#33042)