pingcap / pingcap/tidb

Query result is not compatible with MySQL while using `if` clause

Open
#46,376 2 comments 0 reactions 1 assignee Claimed by @winoros View on GitHub
affects-6.1 affects-6.5 affects-7.1 affects-7.5 affects-8.1 affects-8.5 severity/major sig/planner type/compatibility
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Query result is not compatible with MySQL while using `if` clause

### 1. Minimal reproduce step (Required)

create table t1(c1 varchar(32));
insert into t1 values('sh'),('bj');

select if(1 is null,(select c1 from t1 limit 2),3);

### 2. What did you expect to see? (Required)

mysql> select if(1 is null,(select c1 from t1 limit 2),3);
+----------------------------------------------+
| if(1 is null,(select c1 from t1 limit 2),3) |
+----------------------------------------------+
| 3 |
+----------------------------------------------+
1 row in set (0.00 sec)

### 3. What did you see instead (Required)

MySQL 8.0:
mysql> select if(1 is null,(select c1 from t1 limit 2),3);
+----------------------------------------------+
| if(1 is null,(select c1 from t1 limit 2),3) |
+----------------------------------------------+
| 3 |
+----------------------------------------------+
1 row in set (0.00 sec)

TiDB:
mysql> select if(1 is null,(select c1 from t1 limit 2),3);
ERROR 1242 (21000): Subquery returns more than 1 row

### 4. What is your TiDB version? (Required)
v7.1.1, v6.5

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.