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

EXCHANGE PARTITION issue: Non-partitioned tables that nonmatch the partition definition can be swapped successfully #46492

Closed
snowballbear opened this issue Aug 30, 2023 · 6 comments · Fixed by #46533
Assignees
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 component/tablepartition This issue is related to Table Partition of TiDB. found/gs found by gs severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@snowballbear
Copy link

Bug Report

image https://docs.pingcap.com/tidb/v6.5/partitioned-table#partition-management

1. Minimal reproduce step (Required)

partition table:
mysql> create table test_p(id int,create_ts datetime,name varchar(10)) partition by list columns(create_ts)(partition p20230829 values in ('2023-08-29'),partition p20230830 values in ('2023-08-30'));
Query OK, 0 rows affected (0.13 sec)
mysql> insert into test_p values (1,'2023-08-29','a');
Query OK, 1 row affected (0.01 sec)
mysql> insert into test_p values (2,'2023-08-30','b');
Query OK, 1 row affected (0.01 sec)
mysql> insert into test_p values (3,'2023-08-31','c');
ERROR 1526 (HY000): Table has no partition for value from column_list

non-partitioned table:
mysql> create table test_p_swap(id int,create_ts datetime,name varchar(10));
Query OK, 0 rows affected (0.12 sec)
mysql> insert into test_p_swap values (3,'2023-08-31','c');
Query OK, 1 row affected (0.01 sec)

exchange partition:
mysql> alter table test_p EXCHANGE PARTITION p20230829 WITH TABLE test_p_swap;
Query OK, 0 rows affected, 1 warning (0.25 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------------------------------------+
| Warning | 1105 | after the exchange, please analyze related table of the exchange to update statistics |
+---------+------+---------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from test_p;
+------+---------------------+------+
| id | create_ts | name |
+------+---------------------+------+
| 2 | 2023-08-30 00:00:00 | b |
| 3 | 2023-08-31 00:00:00 | c |
+------+---------------------+------+
2 rows in set, 1 warning (0.00 sec)

mysql> show create table test_p;
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test_p | CREATE TABLE test_p (
id int(11) DEFAULT NULL,
create_ts datetime DEFAULT NULL,
name varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY LIST COLUMNS(create_ts)
(PARTITION p20230829 VALUES IN ('2023-08-29'),
PARTITION p20230830 VALUES IN ('2023-08-30')) |
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

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

The exchange partition statement will fail.

3. What did you see instead (Required)

Non-partitioned tables that nonmatch the partition definition can be swapped successfully.

4. What is your TiDB version? (Required)

v6.5.3

@snowballbear snowballbear added the type/bug The issue is confirmed as a bug. label Aug 30, 2023
@jiyfhust
Copy link
Contributor

/assign

@jackysp
Copy link
Member

jackysp commented Aug 30, 2023

master also seems to have this bug. PTAL @mjonss

@jackysp jackysp added the component/tablepartition This issue is related to Table Partition of TiDB. label Aug 30, 2023
@ti-chi-bot ti-chi-bot bot added may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Aug 30, 2023
@mjonss
Copy link
Contributor

mjonss commented Aug 30, 2023

@jiyfhust I did not mean to take over this issue, but I found some more issues with null handling, and created a PR to check and fix them as well.

There are some more tests needed, if you like please propose some, otherwise I will complete them soon, to get the PR ready for review.

Most likely there are more issues with null handling and VALIDATE of EXCHANGE PARTITION.

@jiyfhust
Copy link
Contributor

There are some more tests needed, if you like please propose some, otherwise I will complete them soon, to get the PR ready for review.

Great, I'm glad you can fix them soon.

@jackysp
Copy link
Member

jackysp commented Sep 5, 2023

cc @ryangao0513

@ti-chi-bot ti-chi-bot added affects-5.4 This bug affects 5.4.x versions. affects-6.1 labels Sep 15, 2023
@jackysp
Copy link
Member

jackysp commented Sep 21, 2023

/found gs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 component/tablepartition This issue is related to Table Partition of TiDB. found/gs found by gs severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants