[MDEV-12556] Possible performance problem with recursive CTE and UNION involving TEXT/BLOB columns Created: 2017-04-22 Updated: 2018-07-31 Resolved: 2017-04-28 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer - CTE |
| Affects Version/s: | 10.2 |
| Fix Version/s: | 10.2.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | 10.2-ga | ||
| Issue Links: |
|
||||||||
| Description |
|
The CTE below is intentionally endless. It's controlled by max_recursive_iterations, which works just fine. But the execution time is radically different, depending on whether we use a VARCHAR column, or a TEXT column of the same length.
If I understand the idea, with UNION the temporary table should never grow above 4 rows, so there is no reason for such long execution time. If I replace UNION with UNION ALL, execution time naturally grows, and it becomes approximately the same for VARCHAR and TEXT column. The result (final count) is the same, which shows that the number of iterations is the same too.
|
| Comments |
| Comment by Igor Babaev [ 2017-04-26 ] | ||||||||||||||||||||||||||||||
|
ANALYZE run for the above two queries shows why their performance is so different:
We see that when the second query is executed the temporary table <derived2> used to store the new rows for the next iteration contains far more than 4 rows that it should contain. | ||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2017-04-26 ] | ||||||||||||||||||||||||||||||
|
Actually the CTE tables in the queries from the reported test case should have stabilized after the first iteration. | ||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2017-04-26 ] | ||||||||||||||||||||||||||||||
|
Here's what happens: | ||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2017-04-28 ] | ||||||||||||||||||||||||||||||
|
The fix for this bug was pushed into the 10.2 tree. |