query returns incorrect result
- 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)
```
CREATE TABLE dp_organisation (
OrganisationId INT PRIMARY KEY,
ParentId INT
);
CREATE TABLE dp_organisation_member (
OrganisationId INT,
MemberId INT
);
INSERT INTO dp_organisation VALUES (1,NULL),(2,1),(3,2);
INSERT INTO dp_organisation_member VALUES (1,100),(2,200),(3,300);
SELECT * FROM dp_organisation_member t82
WHERE (
t82.`OrganisationId` = 1 OR FIND_IN_SET(t82.`OrganisationId`, (
SELECT GROUP_CONCAT(`Ids`) FROM (
SELECT @Level := @Level + 1 `Level`, @Ids := (
SELECT GROUP_CONCAT(`OrganisationId`)
FROM dp_organisation
WHERE FIND_IN_SET(`ParentId`, @Ids)
) `Ids`
FROM (SELECT @Ids := '1', @Level := 0) temp1
INNER JOIN dp_organisation ON NOT(ISNULL(@Ids))
) temp2
))
);
```
### 2. What did you expect to see? (Required)
results from mysql:
```
MySQL [testdb_1747812525959]> SELECT * FROM dp_organisation_member t82
-> WHERE (
-> t82.`OrganisationId` = 1 OR FIND_IN_SET(t82.`OrganisationId`, (
-> SELECT GROUP_CONCAT(`Ids`) FROM (
-> SELECT @Level := @Level + 1 `Level`, @Ids := (
-> SELECT GROUP_CONCAT(`OrganisationId`)
-> FROM dp_organisation
-> WHERE FIND_IN_SET(`ParentId`, @Ids)
-> ) `Ids`
-> FROM (SELECT @Ids := '1', @Level := 0) temp1
-> INNER JOIN dp_organisation ON NOT(ISNULL(@Ids))
-> ) temp2
-> ))
-> );
+----------------+----------+
| OrganisationId | MemberId |
+----------------+----------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----------------+----------+
3 rows in set, 4 warnings (0.00 sec)
MySQL [testdb_1747812525959]> select version();
+-----------+
| version() |
+-----------+
| 8.4.3 |
+-----------+
1 row in set (0.00 sec)
```
### 3. What did you see instead (Required)
```
MySQL [test]> SELECT * FROM dp_organisation_member t82
-> WHERE (
-> t82.`OrganisationId` = 1 OR FIND_IN_SET(t82.`OrganisationId`, (
-> SELECT GROUP_CONCAT(`Ids`) FROM (
-> SELECT @Level := @Level + 1 `Level`, @Ids := (
-> SELECT GROUP_CONCAT(`OrganisationId`)
-> FROM dp_organisation
-> WHERE FIND_IN_SET(`ParentId`, @Ids)
-> ) `Ids`
-> FROM (SELECT @Ids := '1', @Level := 0) temp1
-> INNER JOIN dp_organisation ON NOT(ISNULL(@Ids))
-> ) temp2
-> ))
-> );
+----------------+----------+
| OrganisationId | MemberId |
+----------------+----------+
| 1 | 100 |
+----------------+----------+
1 row in set (0.01 sec)
```
### 4. What is your TiDB version? (Required)
```
MySQL [test]> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.1
Edition: Community
Git Commit Hash: fea86c8e35ad4a86a5e1160701f99493c2ee547c
Git Branch: HEAD
UTC Build Time: 2025-01-16 07:38:34
GoVersion: go1.23.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.