You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix UNION column mapping bug in nested multi-way operations
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]>
Query: `WITH visible_collection_ids AS (SELECT id FROM collection AS c WHERE (1 <> c.id))
11253
+
SELECT 5 AS model_ranking, c.id, c.name, c.description, c.entity_id, c.display, c.collection_preview, c.dataset_query, c.collection_id, 'card' AS model
11254
+
FROM report_card AS c WHERE (c.dashboard_id IS NULL) AND (archived = FALSE) AND (c.type = 'question')
11255
+
UNION
11256
+
SELECT 7 AS model_ranking, id, name, name AS description, entity_id, NULL AS display, NULL AS collection_preview, NULL AS dataset_query, id AS collection_id, 'collection' AS model
11257
+
FROM collection AS col WHERE (archived = FALSE) AND (id <> 1) AND (personal_owner_id IS NULL) AND (namespace IS NULL)
11258
+
UNION
11259
+
SELECT 1 AS model_ranking, d.id, d.name, d.description, d.entity_id, NULL AS display, NULL AS collection_preview, NULL AS dataset_query, NULL AS collection_id, 'dashboard' AS model
11260
+
FROM report_dashboard AS d WHERE (archived = FALSE)`,
0 commit comments