[MDEV-25020] SELECT if there is IN clause with binary UUID in binary form is extremely slow since MariaDB 10.5.9 Created: 2021-03-01 Updated: 2023-10-24 Resolved: 2022-08-01 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.5.9, 10.5.13 |
| Fix Version/s: | 10.5.17, 10.6.9, 10.7.5, 10.8.4 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Ján Forgáč | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 2 |
| Labels: | performance | ||
| Environment: |
Linux |
||
| Attachments: |
|
||||||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
table with primery key binary(16) `SELECT from table WHERE key IN (binary form ids, ....)` is extremly slow while `SELECT from table WHERE key IN ((0x11e6a2ad166fc342abde002590a2360a), IDs in binary form I mean this: https://tinyurl.com/ycfyftby |
| Comments |
| Comment by Sergei Petrunia [ 2021-06-09 ] | ||||||||||||||||||||||||
|
I was unable to reproduce. Can you share more details:
| ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2021-06-09 ] | ||||||||||||||||||||||||
|
Closing as "Cannot reproduce" for now. Feel free to re-open when more data is available. | ||||||||||||||||||||||||
| Comment by Ján Forgáč [ 2021-06-10 ] | ||||||||||||||||||||||||
|
Rapid performance drop is obvious if in IN (....) are thousands or ten of thousands items.
Are these outputs enough for identifiing the problem? I think I do not have privilege to reopen this issue. Do I? | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2021-06-15 ] | ||||||||||||||||||||||||
|
Re-opening | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-05-16 ] | ||||||||||||||||||||||||
|
Analyzing the data in the provided files.
Query plans:
| ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-05-16 ] | ||||||||||||||||||||||||
|
That is, for lookups on binary field, 10.1 was faster than 10.2. | ||||||||||||||||||||||||
| Comment by Wei Jiang [ 2022-05-27 ] | ||||||||||||||||||||||||
|
I have observed the slowness even in 10.5.8 but the symptoms wasn't there on 10.5.4. | ||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2022-07-27 ] | ||||||||||||||||||||||||
|
explain takes much more time in 10.5 as compared to 10.1 (140 sec vs 0.1 sec, ymmv). 99.66% of the time 10.5 spends in SEL_ARG::update_weight_locally() With
explain in 10.5 runs with the same speed as in 10.1 | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-07-27 ] | ||||||||||||||||||||||||
|
Indeed, the call to update_weight_locally() is the problem. update_weight_locally() traverses the whole SEL_ARG tree ("locally" means it doesn't walk across next_key_part edges). Lets consider a call
where tree1 has a lot of SEL_ARG nodes, The code in key_or() will use RB-Tree descend to find the location in tree1 where tree2 should be put in (grep for key1->find_range(key2) call). This takes O(LOG(N)). Adding O(N) in update_weight_locally() will indeed cause a big slowdown. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-07-27 ] | ||||||||||||||||||||||||
|
Note that SEL_ARG::tree_delete() and SEL_ARG::insert() do update the value of SEL_ARG::weight. key_or() also messes with SEL_ARG nodes directly, when it joins trees with SEL_ARG objects representing identical or overlapping intervals. I've went through the code and it looks like neither of these direct SEL_ARG modifications change the weight of the tree. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-07-27 ] | ||||||||||||||||||||||||
|
This patch passes the tests:
The only remaining place that uses update_weight_locally() is and_all_keys(). One can't just remove the update_weight_locally() call from there. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-07-27 ] | ||||||||||||||||||||||||
|
https://github.com/MariaDB/server/commit/d17ed38893fa0213575813975212c8f4227c9972 | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-08-01 ] | ||||||||||||||||||||||||
|
Addressed review input by Monty and pushed into 10.5 |