Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: in 子查询中,数值重复,结果异常
Bug Report
Clearly and accurately describe the issue you found. Providing any steps to reproduce the problem can help the development team address it promptly.
[TiDB Version] v7.1.0+
[Impact of the Bug]
Incorrect query results
[Possible Steps to Reproduce the Issue]
Create table:
CREATE TABLE `in_test` (
`id` bigint(20) unsigned NOT NULL,
`name` varchar(45) NOT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED*/,
KEY `inx_name` (`name`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`id`) PARTITIONS 128;
Insert data:
insert into in_test(id, name)
values(6700402571, 'Zhang San'), (1624923463, 'Li Si'), (5837848666, 'Wang Wu'), (6542259574, 'Zhao Liu');
Query data:
SELECT id, `name` FROM `in_test` WHERE id IN
(1624923463, 1624923463, 5837848666, 5837848666, 6700402571, 6700402571, 6542259574, 6542259574);
Query results:
Execution plan:
Third-party tool, SQLyog:
Is SQLyog used to query TiDB or MySQL?
Checked on the same TiDB server.
The table is a non-clustered table, and there are no issues when querying again.
It seems to be a bug with the clustered table.
The same SQL in the same database should not return different results. You can check the reason.
Can other partners reproduce this?
Version 7.3.0 can reproduce the issue. The result is normal after removing the hash PARTITION.
opened 06:54AM - 08 Sep 23 UTC
closed 02:25AM - 12 Sep 23 UTC
type/bug
sig/sql-infra
severity/critical
affects-7.1
found/community
## Bug Report
Please answer these questions before submitting your issue. Tha… nks!
### 1. Minimal reproduce step (Required)
```
`CREATE TABLE `in_test` (
`id` bigint(20) unsigned NOT NULL ,
`name` varchar(45) NOT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
KEY `inx_name` (`name`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`id`) PARTITIONS 128; `
`insert into in_test(id,name)
values(6700402571,'张三'),(1624923463,'李四'),(5837848666,'王五'),(6542259574,'赵六');`
`select id,
`name`
from `in_test`
where id in
(1624923463, 1624923463, 5837848666, 5837848666, 6700402571, 6700402571, 6542259574,6542259574);`
```
### 2. What did you expect to see? (Required)
```
id |estRows|actRows|task|access object |execution info |operator info |memory|disk|
-----------------+-------+-------+----+-----------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+------+----+
Batch_Point_Get_1|8.00 |4 |root|table:in_test, partition:p11,p71,p90,p118|time:2.66ms, loops:2, BatchGet:{num_rpc:4, total_time:6.66ms}, tikv_wall_time: 1.48ms, scan_detail: {total_process_keys: 4, total_process_keys_size: 256, total_keys: 4, get_snapshot_time: 217.9µs, rocksdb: {block: {}}}|handle:[1624923463 1624923463 5837848666 5837848666 6700402571 6700402571 6542259574 6542259574], keep order:false, desc:false|N/A |N/A |
```
### 3. What did you see instead (Required)
```
id |estRows|actRows|task|access object |execution info |operator info |memory|disk|
-----------------+-------+-------+----+-----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+------+----+
Batch_Point_Get_1|8.00 |1 |root|table:in_test, partition:p11,p71,p90,p118|time:918.7µs, loops:2, RU:0.500977, BatchGet:{num_rpc:2, total_time:1.58ms}, tikv_wall_time: 988.5µs, scan_detail: {total_process_keys: 1, total_process_keys_size: 64, total_keys: 4, get_snapshot_time: 617.1µs, rocksdb: {block: {cache_hit_count: 25}}}|handle:[1624923463 1624923463 5837848666 5837848666 6700402571 6700402571 6542259574 6542259574], keep order:false, desc:false|N/A |N/A |
```
### 4. What is your TiDB version? (Required)
7.1.1 / 7.1.0
It seems that it has also been submitted on GitHub.
That is a bug caused by hash partition + clustered index.
Oh, you’re quick to jump on the question
【 TiDB 版本】 7.1.1 / 7.1.0 问题:in 子查询执行计划错误,实际结果与返回结果不一致 建表: CREATE TABLE `in_test` ( `id` bigint(20) unsigned NOT NULL , `name` varchar(45) NOT NULL, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP , `update_time` timestamp...
阅读时间: 2 mins 🕑
赞: 4 ❤
opened 06:54AM - 08 Sep 23 UTC
closed 02:25AM - 12 Sep 23 UTC
type/bug
sig/sql-infra
severity/critical
affects-7.1
found/community
## Bug Report
Please answer these questions before submitting your issue. Tha… nks!
### 1. Minimal reproduce step (Required)
```
`CREATE TABLE `in_test` (
`id` bigint(20) unsigned NOT NULL ,
`name` varchar(45) NOT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
KEY `inx_name` (`name`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`id`) PARTITIONS 128; `
`insert into in_test(id,name)
values(6700402571,'张三'),(1624923463,'李四'),(5837848666,'王五'),(6542259574,'赵六');`
`select id,
`name`
from `in_test`
where id in
(1624923463, 1624923463, 5837848666, 5837848666, 6700402571, 6700402571, 6542259574,6542259574);`
```
### 2. What did you expect to see? (Required)
```
id |estRows|actRows|task|access object |execution info |operator info |memory|disk|
-----------------+-------+-------+----+-----------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+------+----+
Batch_Point_Get_1|8.00 |4 |root|table:in_test, partition:p11,p71,p90,p118|time:2.66ms, loops:2, BatchGet:{num_rpc:4, total_time:6.66ms}, tikv_wall_time: 1.48ms, scan_detail: {total_process_keys: 4, total_process_keys_size: 256, total_keys: 4, get_snapshot_time: 217.9µs, rocksdb: {block: {}}}|handle:[1624923463 1624923463 5837848666 5837848666 6700402571 6700402571 6542259574 6542259574], keep order:false, desc:false|N/A |N/A |
```
### 3. What did you see instead (Required)
```
id |estRows|actRows|task|access object |execution info |operator info |memory|disk|
-----------------+-------+-------+----+-----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+------+----+
Batch_Point_Get_1|8.00 |1 |root|table:in_test, partition:p11,p71,p90,p118|time:918.7µs, loops:2, RU:0.500977, BatchGet:{num_rpc:2, total_time:1.58ms}, tikv_wall_time: 988.5µs, scan_detail: {total_process_keys: 1, total_process_keys_size: 64, total_keys: 4, get_snapshot_time: 617.1µs, rocksdb: {block: {cache_hit_count: 25}}}|handle:[1624923463 1624923463 5837848666 5837848666 6700402571 6700402571 6542259574 6542259574], keep order:false, desc:false|N/A |N/A |
```
### 4. What is your TiDB version? (Required)
7.1.1 / 7.1.0
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.