Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting a partitioned table from a normal table results in duplicate data for the primary key #55721

Closed
harry1129 opened this issue Aug 28, 2024 · 3 comments
Assignees
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. component/tablepartition This issue is related to Table Partition of TiDB. impact/inconsistency incorrect/inconsistency/inconsistent severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@harry1129
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> create table t1(id bigint,id_1 bigint,name varchar(10),primary key (id) NONCLUSTERED);
Query OK, 0 rows affected (0.08 sec)

mysql> insert into t1 values(1,1,'AA'),(2,2,'BB'),(3,3,'CC'),(4,4,'DD');
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> alter table t1 partition by hash(id_1) partitions 4;
Query OK, 0 rows affected, 1 warning (1.58 sec)

mysql> insert into t1 values(2,1,'AA');
Query OK, 1 row affected (0.00 sec)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v7.5.3
Edition: Community
Git Commit Hash: 70bfd90035cc81e80d78b4f1f76ca4baef8a5756
Git Branch: HEAD
UTC Build Time: 2024-07-31 13:17:12
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

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

mysql> alter table t1 partition by hash(id_1) partitions 4;
ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

3. What did you see instead (Required)

mysql> alter table t1 partition by hash(id_1) partitions 4;
Query OK, 0 rows affected, 1 warning (1.58 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v7.5.3
Edition: Community
Git Commit Hash: 70bfd90035cc81e80d78b4f1f76ca4baef8a5756
Git Branch: HEAD
UTC Build Time: 2024-07-31 13:17:12
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

PS: v8.3.0 does not reproduce this issue

@harry1129 harry1129 added the type/bug The issue is confirmed as a bug. label Aug 28, 2024
@Defined2014 Defined2014 added sig/sql-infra SIG: SQL Infra component/tablepartition This issue is related to Table Partition of TiDB. labels Aug 28, 2024
@harry1129
Copy link
Author

This may result in incorrect data for the query

mysql> create table t1(id bigint,id_1 bigint,name varchar(10),primary key (id) CLUSTERED);
Query OK, 0 rows affected (0.08 sec)

mysql> insert into t1 values(1,1,'AA'),(2,2,'BB'),(3,3,'CC'),(4,4,'DD');
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> alter table t1 partition by hash(id_1) partitions 4;
Query OK, 0 rows affected, 1 warning (0.78 sec)

mysql> insert into t1 values(2,1,'AA');
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+----+------+------+
| id | id_1 | name |
+----+------+------+
|  3 |    3 | CC   |
|  1 |    1 | AA   |
|  2 |    1 | AA   |
|  4 |    4 | DD   |
|  2 |    2 | BB   |
+----+------+------+
5 rows in set, 1 warning (0.01 sec)

mysql> select * from t1 partition(p0);
+----+------+------+
| id | id_1 | name |
+----+------+------+
|  4 |    4 | DD   |
+----+------+------+
1 row in set, 1 warning (0.01 sec)

mysql> select * from t1 partition(p1);
+----+------+------+
| id | id_1 | name |
+----+------+------+
|  1 |    1 | AA   |
|  2 |    1 | AA   |
+----+------+------+
2 rows in set, 1 warning (0.00 sec)

mysql> select * from t1 partition(p2);
+----+------+------+
| id | id_1 | name |
+----+------+------+
|  2 |    2 | BB   |
+----+------+------+
1 row in set, 1 warning (0.00 sec)

mysql> select * from t1 partition(p3);
+----+------+------+
| id | id_1 | name |
+----+------+------+
|  3 |    3 | CC   |
+----+------+------+
1 row in set, 1 warning (0.00 sec)

mysql> analyze table t1;
Query OK, 0 rows affected, 8 warnings (0.09 sec)

mysql> select * from t1 where id in (1,2,3);
+----+------+------+
| id | id_1 | name |
+----+------+------+
|  1 |    1 | AA   |
|  2 |    2 | BB   |
|  3 |    3 | CC   |
+----+------+------+
3 rows in set (0.00 sec)

mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.5.3
Edition: Community
Git Commit Hash: 70bfd90035cc81e80d78b4f1f76ca4baef8a5756
Git Branch: HEAD
UTC Build Time: 2024-07-31 13:17:12
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

@mjonss
Copy link
Contributor

mjonss commented Aug 29, 2024

Seems to affect 7.5 series, not 7.1 or 8.0/8.1.

@jebter jebter added severity/major impact/inconsistency incorrect/inconsistency/inconsistent labels Aug 30, 2024
@mjonss mjonss added affects-7.5 This bug affects the 7.5.x(LTS) versions. and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 labels Aug 30, 2024
@Defined2014 Defined2014 reopened this Oct 29, 2024
@ti-chi-bot ti-chi-bot added the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 1, 2024
@ti-chi-bot ti-chi-bot bot removed the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 4, 2024
ti-chi-bot bot pushed a commit that referenced this issue Dec 4, 2024
@mjonss
Copy link
Contributor

mjonss commented Dec 4, 2024

Merged into release-7.5 (#55770).

@mjonss mjonss closed this as completed Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. component/tablepartition This issue is related to Table Partition of TiDB. impact/inconsistency incorrect/inconsistency/inconsistent severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

5 participants