pingcap / pingcap/tidb

Inconsistent results while executing queries on partitioned table in transaction

Open
#71,011 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/execution type/bug
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
create table t0(c0 bool default true ) partition by range(c0) (partition p0 values less than (1000), partition p1 values less than (6730), partition p2 values less than (13417), partition p3 values less than (14761), partition p4 values less than (maxvalue));
create index i70 on t0(c0 asc);
replace into t0(c0) values (false);

CREATE TABLE t0_oracle LIKE t0;
alter table t0_oracle remove partitioning;
INSERT INTO t0_oracle SELECT * FROM t0;
SET SESSION transaction_isolation = 'REPEATABLE-READ';

BEGIN PESSIMISTIC;
INSERT IGNORE INTO t0 VALUES (1218788580);
SELECT DISTINCT t0.c0 FROM t0 WHERE ((t0.c0)=(CAST(SYSTEM_USER() AS DATE)));

BEGIN PESSIMISTIC;
INSERT IGNORE INTO t0_oracle VALUES (1218788580);
SELECT DISTINCT t0_oracle.c0 FROM t0_oracle WHERE ((t0_oracle.c0)=(CAST(SYSTEM_USER() AS DATE)));
```

### 2. What did you expect to see? (Required)
SELECT statements return same results.

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

```sql
mysql> SELECT DISTINCT t0.c0 FROM t0 WHERE ((t0.c0)=(CAST(SYSTEM_USER() AS DATE)));
Empty set, 1 warning (0.00 sec)

mysql> SELECT DISTINCT t0_oracle.c0 FROM t0_oracle WHERE ((t0_oracle.c0)=(CAST(SYSTEM_USER() AS DATE)));
+------+
| c0 |
+------+
| 0 |
+------+
1 row in set, 1 warning (0.00 sec)

```

### 4. What is your TiDB version? (Required)
```sql
mysql> select version();
+-----------------------------------------------------+
| version() |
+-----------------------------------------------------+
| 8.0.11-TiDB-v9.0.0-beta.1.pre-640-g24903d6b24-dirty |
+-----------------------------------------------------+
1 row in set (0.00 sec)

```

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied SQL reproduction on TiDB v9.0.0-beta.1.pre-640-g24903d6b24, comparing the partitioned table with the table after partitioning is removed under REPEATABLE-READ and pessimistic transactions. Trace query execution for the two SELECT statements and confirm done when both return the same result.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.