[MDEV-28073] Slow query performance in MariaDB when using many tables Created: 2022-03-10 Updated: 2022-09-19 Resolved: 2022-06-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.2.27, 10.6.5 |
| Fix Version/s: | 10.6.8, 10.7.4, 10.8.3, 10.9.1 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Maria M Pflaum | Assignee: | Michael Widenius |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
Looking for root cause for the following problem: The customer found that by setting the optimizer_search_depth=10 the amount of time is similar to original run times. They tested 11 through 15 as well. They noticed `optimizer_search_depth=10` performed identically to `optimizer_search_depth=0` and `optimizer_search_depth=7`. However, `optimizer_search_depth=11` started to show degraded performance. They saw that at `optimizer_search_depth=15`, there was no, discernible difference between that and the default `optimizer_search_depth=62`. Below are the steps to reproduce the issue. Optimizer trace with default optimzer_search_depth takes 12 hours and we were unable to capture the data. Relevant files are attached to case CS0379791 as CS0379791-March102022.tar.gz |
| Comments |
| Comment by Michael Widenius [ 2022-04-26 ] |
|
I am looking at this now.
This means that almost all combinations has the same cost, which means that the optimizer is going trough roughly 24! = 6.2E+23 combinations. After discussing this with Sergei Petrunia, we come up with the following ideas to speed up the optimizer stage:
This should cut down the number of combinations notable. |
| Comment by Michael Widenius [ 2022-05-24 ] |
|
A comment on the current patch: I am now working on several new ideas of how to get down the combinations checked by the optimizer. Some of them will be in 10.6, |
| Comment by Michael Widenius [ 2022-06-03 ] |
|
I am almost done with this task. The current work consist of:
The effect of all this is a significant improvement of the speed of greedy_optimizer when table pruning is enabled. In MariaDB 10.6 default, the above tests takes a VERY long time. Of the above work, the first 2 parts of the work are scheduled to be added to MariaDB 10.6 and the last works are scheduled for 10.10 You can find this work in bb-10.6-monty (until it is pushed to 10.6 and 10.10) |
| Comment by Sergei Golubchik [ 2022-06-12 ] |
|
Commit https://github.com/MariaDB/server/commit/b729896d00e was pushed and released in 10.6.8. As far as I understand, it fixes some cases. Other cases will be fixed in 10.10, to avoid confusion they should get a new MDEV number. monty, that case that rob.schwyzer@mariadb.com is talking about — was it supposed to be fixed in 10.6 or in 10.10? |
| Comment by Michael Widenius [ 2022-06-14 ] |
|
The code in bb-10.6-monty# was updated since we spoked last time with the changes that has already gone into 10.6 (which is just some small improvements to greedy_search() as list in my post above). This is why optimizer_prune_level could not be changed. The state of the original test case: Note that in 10.6, the main reason it is faster than before was the EQ_REF shortcuting that was done in April. This only solves special cases where there are a lot of EQ_REF tables. The code in 10.10 is more general and can solve a wider range of cases. |
| Comment by Sergei Golubchik [ 2022-08-05 ] |
|
Note Some optimizations related to the original test case were implemented in 10.6.8 (10.7.4, 10.8.3), some in 10.6.9 (10.7.5, 10.8.4). |