-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
partition by RANGE COLUMNS on varchar column with collate _bin does not adjust pruning if query includes other collation #32749
Comments
Similar with the other way around (column defined with utf8mb4_general_ci but queried with utf8mb4_bin), notice that MySQL does pruning on the correct partition instead of loosening the pruning to all partitions!
^^ MySQL vs TiDB vv
|
/component tablepartition |
Hi @mjonss , some updates from me:
The collation-aware comparison pruning sounds reasonable but it leads to the wrong result...I don't know how it should be fixed. BTW, the pruning was collation-aware after #20879. PTAL @xiongjiwei and @wjhuang2016 , any idea on this? |
e.g. tidb> create table t (a varchar(255) charset utf8mb4 collate utf8mb4_bin) partition by range columns (a) (partition puppera values less than ("AAA"), partition plowera values less than ("aaaa"));
Query OK, 0 rows affected (0,00 sec)
tidb> insert into t values ("aa");
Query OK, 1 row affected (0,00 sec)
tidb> explain select * from t where a = "aa" collate utf8mb4_general_ci;
|
Yes, IMO I think your case is challenge for a database to do the 'correct prune'. BTW are you using MySQL 8? I found that for MySQL 5.7, it did "loosening the pruning to all partitions":
So some enhancements have been done in MySQL 8. |
mysql> create table t (a varchar(255) charset utf8mb4 collate utf8mb4_bin) partition by range columns (a) (partition puppera values less than ("AAA"), partition plowera values less than ("aaaa"), partition pp values less than ('hhhh'));
Query OK, 0 rows affected (0.09 sec)
mysql> insert into t values ("aa");
Query OK, 1 row affected (0.01 sec)
mysql> explain select * from t where a = "aa" collate utf8mb4_general_ci;
+----+-------------+-------+--------------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+--------------------+------+---------------+------+---------+------+------+----------+-------------+
| 1 | SIMPLE | t | puppera,plowera,pp | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using where |
+----+-------------+-------+--------------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.00 sec) even though we know partition |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
Skip pruning (or have some way to take into consideration the given collation), like MySQL:
3. What did you see instead (Required)
Using the same pruning as if the
collate
was not given in the select query:4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: