Skip to content

Conversation

@elianddb
Copy link
Contributor

@elianddb elianddb commented Aug 5, 2025

Fixes dolthub/dolt#9628
Fixed column scrambling in UNION queries with 3+ branches. The bug caused duplicate rows with wrong column positions when processing nested UNION operations like (A UNION B) UNION C.
SetOp nodes now preserve schema order by recursing to left child instead of using sorted column set.

Fixed column scrambling in complex UNION queries with 3+ branches and 10+ columns. The bug caused duplicate rows with wrong column positions when processing nested UNION operations like (A UNION B) UNION C.

Root cause: colIdsForRel() used sorted ColSet.ForEach() for SetOp nodes, losing original SELECT column order. This caused wrong column mappings in mergeSetOpSchemas() for nested UNIONs.

Solution: SetOp nodes now preserve schema order by recursing to left child instead of using sorted column set, matching MySQL behavior.

Added regression test that reproduces the exact threshold where bug occurs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
},
},
{
Name: "UNION column mapping bug - issue 9628",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need the issue number here if you have the github link in a comment. But if you want to keep it, can you specify it's dolt#9628 (since we also have issues in gms) ?

Copy link
Contributor

@angelamayxie angelamayxie left a comment

Choose a reason for hiding this comment

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

lgtm, just some super minor comments

@elianddb elianddb merged commit 7ee1006 into main Aug 6, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants