ONLY_FULL_GROUP_BY is bypassed for correlated scalar subquery referencing non-grouped outer column
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```sql
select @@sql_mode;
-- ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
-- ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
drop table if exists t10, t11;
create table t10(id int, biz_no int);
create table t11(id int, no int);
insert into t10(id, biz_no) values (1, 100);
insert into t10(id, biz_no) values (1, 101);
insert into t11(id, no) values (3, 100);
insert into t11(id, no) values (4, 101);
select id, (select count(*) from t11 where no = t10.biz_no)
from t10
where id = 1
group by id;
```
### 2. What did you expect to see? (Required)
TiDB should reject this query with ERROR 1055, consistent with MySQL 5.7 / 8.0 under ONLY_FULL_GROUP_BY.
Reason: the correlated scalar subquery references outer column t10.biz_no, but the outer query groups only by id. biz_no is neither grouped nor functionally dependent on id
### 3. What did you see instead (Required)
TiDB 8.5.5 does not return an error and instead returns one arbitrary row, for example:
1 1
### 4. What is your TiDB version? (Required)
v8.5.5
Contributor guide
Assessment
This issue has not been assessed yet.