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

v5.4.0 list partition can't work after restarting tidb #32416

Closed
wshwsh12 opened this issue Feb 16, 2022 · 4 comments · Fixed by #32621 or #33199
Closed

v5.4.0 list partition can't work after restarting tidb #32416

wshwsh12 opened this issue Feb 16, 2022 · 4 comments · Fixed by #32621 or #33199
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@wshwsh12
Copy link
Contributor

wshwsh12 commented Feb 16, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

New v5.4.0 cluster with new collation, and run the following sql:

set @@session.tidb_enable_list_partition = ON;
set @@tidb_partition_prune_mode = 'dynamic';
drop table if exists github_events;
CREATE TABLE `github_events` (
`id` bigint(20) DEFAULT NULL,
`type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
PARTITION BY LIST COLUMNS(`type`)
(PARTITION `push_event` VALUES IN ("PushEvent"),
PARTITION `create_event` VALUES IN ("CreateEvent"),
PARTITION `pull_request_event` VALUES IN ("PullRequestEvent"),
PARTITION `watch_event` VALUES IN ("WatchEvent")
);
tidb> desc select id,type from github_events  where  type = 'WatchEvent';
+-------------------------+----------+-----------+-----------------------+-------------------------------------------+
| id                      | estRows  | task      | access object         | operator info                             |
+-------------------------+----------+-----------+-----------------------+-------------------------------------------+
| TableReader_7           | 10.00    | root      | partition:watch_event | data:Selection_6                          |
| └─Selection_6           | 10.00    | cop[tikv] |                       | eq(test.github_events.type, "WatchEvent") |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:github_events   | keep order:false, stats:pseudo            |
+-------------------------+----------+-----------+-----------------------+-------------------------------------------+
3 rows in set (0.00 sec)

Then restart tidb

tidb> desc select id,type from github_events  where  type = 'WatchEvent';
+-------------+---------+------+---------------+---------------+
| id          | estRows | task | access object | operator info |
+-------------+---------+------+---------------+---------------+
| TableDual_6 | 0.00    | root |               | rows:0        |
+-------------+---------+------+---------------+---------------+
1 row in set (0.00 sec)

set @@session.tidb_enable_list_partition = ON;
set @@tidb_partition_prune_mode = 'dynamic';

tidb>  desc select id,type from github_events  where  type = 'WatchEvent';
+-------------------------+----------+-----------+---------------------+-------------------------------------------+
| id                      | estRows  | task      | access object       | operator info                             |
+-------------------------+----------+-----------+---------------------+-------------------------------------------+
| TableReader_7           | 10.00    | root      | partition:dual      | data:Selection_6                          |
| └─Selection_6           | 10.00    | cop[tikv] |                     | eq(test.github_events.type, "WatchEvent") |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:github_events | keep order:false, stats:pseudo            |
+-------------------------+----------+-----------+---------------------+-------------------------------------------+
3 rows in set (0.00 sec)

And then upgrade to master(3738dec):
it works.. But I don't think it is a fix. There may be some potential problems.

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

All veresion can works. Or some explicit bug fix.

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

v5.4, master

@wshwsh12 wshwsh12 added the type/bug The issue is confirmed as a bug. label Feb 16, 2022
@wshwsh12
Copy link
Contributor Author

@Defined2014 @wjhuang2016 PTAL

@wshwsh12 wshwsh12 changed the title v5.4.0 list partition can't work in master v5.4.0 list partition can't work after restarting tidb Feb 16, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. labels Feb 17, 2022
@zimulala
Copy link
Contributor

@mjonss PTAL

@wjhuang2016
Copy link
Member

The problem is that, ForListPruning builds the hashMap in TableFromMeta, which is initialized before setting the new_collation.
Since that we need to rebuild the hashMap after setting the new_collation.

@zimulala zimulala self-assigned this Feb 23, 2022
@jebter jebter added the affects-5.4 This bug affects the 5.4.x(LTS) versions. label Feb 24, 2022
@ti-chi-bot ti-chi-bot removed the may-affects-5.4 This bug maybe affects 5.4.x versions. label Feb 24, 2022
@zimulala
Copy link
Contributor

zimulala commented Feb 24, 2022

This also affects the master. This problem can also occur in the following scenario:

  1. Set the new collation configuration item to false and run the SQL statement above (create list partition table).
  2. Restart the TiDB and execute the select statement.

The above scenario is analyzed in detail:

In step 1

  1. In the bootstrap phase, new collation is true
  2. After bootstrap ends, new collation is false.

In step 2

  1. In the bootstrap phase, new collation is true. ForListPruning builds the hashMap(generate the partition hash key) in TableFromMeta
  2. After bootstrap ends, new collation is false. The generated partition hash key could not be found in the hashMap.

@zimulala zimulala added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. and removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. labels Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
6 participants