Open aytrack opened 2 years ago
MySQL supports this, so we should plan for adding support for this too.
And internally it seems like it should be possible to add support, since like 'aaaa%'
is already rewritten as range ('aaaaa','aaaab')
:
tidb> explain select * from t2 where a like 'aaaaa%';
+-------------------------------+---------+-----------+----------------------+---------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------------+---------+-----------+----------------------+---------------------------------------------------------+
| IndexLookUp_11 | 250.00 | root | partition:all | |
| ├─IndexRangeScan_8(Build) | 250.00 | cop[tikv] | table:t2, index:a(a) | range:["aaaaa","aaaab"), keep order:false, stats:pseudo |
| └─Selection_10(Probe) | 250.00 | cop[tikv] | | like(test.t2.a, "aaaaa%", 92) |
| └─TableRowIDScan_9 | 250.00 | cop[tikv] | table:t2 | keep order:false, stats:pseudo |
+-------------------------------+---------+-----------+----------------------+---------------------------------------------------------+
tidb> explain select * from t2 where a between "aaaaa" and "aaaab";
+-------------------------------+---------+-----------+----------------------+---------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------------+---------+-----------+----------------------+---------------------------------------------------------+
| IndexLookUp_11 | 250.00 | root | partition:p1 | |
| ├─IndexRangeScan_8(Build) | 250.00 | cop[tikv] | table:t2, index:a(a) | range:["aaaaa","aaaab"], keep order:false, stats:pseudo |
| └─Selection_10(Probe) | 250.00 | cop[tikv] | | ge(test.t2.a, "aaaaa"), le(test.t2.a, "aaaab") |
| └─TableRowIDScan_9 | 250.00 | cop[tikv] | table:t2 | keep order:false, stats:pseudo |
+-------------------------------+---------+-----------+----------------------+---------------------------------------------------------+
4 rows in set (0,00 sec)
But we also need to check collation, so the like operator does works with case insensitive matches as well.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
explain select * from t2 where a like 'aaaaa%';
using partition p1;explain select * from t2 where a like 'bbbbb%';
using partition p2;3. What did you see instead (Required)
4. What is your TiDB version? (Required)