[multistage] UNION queries produces wrong sorting results
- Dominant language
- Java
- Stars
- 6.1k
- Forks
- 1.5k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 189
Description
```
SELECT val FROM (
SELECT val, ord FROM (
SELECT CAST(1 AS INT) AS val, 1 AS ord
UNION ALL
SELECT CAST(3 AS INT) AS val, 3 AS ord
)
UNION ALL
SELECT val, ord FROM (
SELECT CAST(2.1 AS DOUBLE) AS val, 2 AS ord
UNION ALL
SELECT CAST(4.1 AS DOUBLE) AS val, 4 AS ord
)
)
ORDER BY ord
```
throws exception in final order-by comparison b/c of different data type (using either both DOUBLE or both INT are fine.
Contributor guide
Research direction
Start by running the SQL reproducer and tracing the multistage UNION handling through the final ORDER BY comparison. Investigate why mixed INT and DOUBLE values cause the comparison to fail, then verify that the query sorts by ord without an exception while the existing same-type cases continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100