[MDEV-27163] Very slow query with split_materialized optimizer Created: 2021-12-03 Updated: 2023-12-05 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.3.31 |
| Fix Version/s: | 10.3 |
| Type: | Bug | Priority: | Major |
| Reporter: | SirWill | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Ubuntu 20.04.3 LTS |
||
| Description |
|
We moved a database from MariaDB 10.2.39 to a new server with MariaDB version 10.3.31 and After troubleshooting for hours, we found out that the new split_materialized optimizer was causing the issue, which was enabled by default. With it enabled the query below takes over 2 minutes while it takes less than a second with it disabled. The query:
I also noticed that removing one of the joins on the wbb1_post table will make the query to complete fast with split_materialized enabled. Create table:
The table has 638543 entries. Query explain:
|
| Comments |
| Comment by Sergei Petrunia [ 2022-02-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Lookgin at the EXPLAINs: The query starts with reading table thread. We scan 5 threads:
Then, we join with table post on
The estimate is 1 (although one can imagine that the user 29630 has made more than one post in a thread). Then, we join with the derived table that computes per-thread totals for messages in last 30 days:
The plan that is not using LATERAL DERIVED uses range(time), there are 4K messages in the last month. The plan that is using LATERAL DERIVED reads all messages for each thread. There are 4 messages on average. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-02-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Don't see anything apparently wrong so far, the estimates shown in EXPLAIN do not indicate that the plan with LATERAL DERIVED would be much slower. Trying to imagine a situation where LATERAL DERIVED be much slower... But this doesn't explain this observation:
I assume the above talks about removing this part of the query:
The optimizer doesn't expect that it adds any fanout (EXPLAIN shows rows=1). One could imagine that in reality it does have large fanout (denote this as GUESS#2) in which case LATERAL DERIVED will execute the subquery more times when the extra LEFT JOIN (...) is present. If the subquery execution is expensive (as we guessed in GUESS#1), then together with GUESS#2 this would explain the observed behavior. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-02-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
SirWill, Is it possible to get the output of the following:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by SirWill [ 2022-02-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Julien Fritsch [ 2023-12-05 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Automated message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by JiraAutomate [ 2023-12-05 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Automated message: |