pingcap / pingcap/tidb

`ENUM` numeric predicates wrong through `UNION ALL`

Open
#70,457 2 comments 0 reactions 0 assignees View on GitHub
contribution may-affects-25.10 may-affects-26.3 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/critical sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report
Please see the repro, it seems TiDB's behavior is different from MySQL's through a `UNION ALL` view.

### 1. Minimal reproduce step (Required)
```sql
CREATE TABLE tb2 (e ENUM('a','b','c'));
INSERT INTO tb2 VALUES ('a'),('b'),('c');
CREATE VIEW v AS SELECT e FROM tb2 UNION ALL SELECT e FROM tb2 WHERE FALSE;

-- DESCRIBE v; -- e varchar(1) (MySQL also reports varchar(1))
SELECT e FROM v WHERE e = 1; -- TiDB: 0 rows; MySQL: ('a')
SELECT e FROM v WHERE e = 0; -- TiDB: 3 rows; MySQL: 0 rows
```
Without the UNION ALL, the result is expected:
```sql
-- plain derived table (no UNION) keeps ENUM and ordinal compare:
SELECT e FROM (SELECT e FROM tb) AS d WHERE e = 1; -- ('a')
```
### 2. What did you expect to see? (Required)
Please see the repro.
### 3. What did you see instead (Required)
Please see the repro.
### 4. What is your TiDB version? (Required)

`tidb 8.0.11-TiDB-v9.0.0-beta.2.pre-2051-g3bea8196a5`

Contributor guide

Open the contributing guide

Research direction

Start with the SQL reproduction in the issue and compare ENUM handling for a plain derived table versus a UNION ALL view, including the reported DESCRIBE result. Trace the UNION ALL type-coercion path in TiDB and add or run a regression test showing that comparisons with 1 and 0 match MySQL's results.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.