[MDEV-29477] recursive query silently discards result after an arbitrary (?) threshold Created: 2022-09-06 Updated: 2022-09-09 Resolved: 2022-09-08 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer - CTE |
| Affects Version/s: | 10.6.8 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Paul Pogonyshev | Assignee: | Sergei Golubchik |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
mysql Ver 15.1 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper |
||
| Description |
|
To reproduce:
This returns 1001, while 10000 is expected. When replacing 10000 in the 'where' clause with a number not larger than 1001, the result matches expectation. Usecase: inner query is used to fetch N next numbers from a sequence in one statement. For "smaller" numbers it works without problems. Displayed behavior is very bad. I suspect there might be some reason and the threshold is configurable somewhere, but the application using the database has no way to know it. Returning too few rows without any errors or even warnings results in a hard-to-understand bug in our application, with practically no way to debug it. |
| Comments |
| Comment by Sergei Golubchik [ 2022-09-08 ] |
|
https://mariadb.com/kb/en/server-system-variables/#max_recursive_iterations |
| Comment by Paul Pogonyshev [ 2022-09-09 ] |
|
> used to prevent infinite loops in recursive CTEs That's a noble goal, presumingly it guards against bugs. However, in this case it's not a bug and I expect it to give correct result even if I specify 1000000. By silently returning something that I don't expect, MariaDB effectively triggers a bug downstream. E.g. Oracle Database also has an arbitrary limit, but it fails hard (with an exception) if it is hit. This is infinitely better than returning a wrong result, because I immediately know that something is wrong instead of letting it fail later in an unpredictable way. |
| Comment by Sergei Golubchik [ 2022-09-09 ] |
|
| Comment by Paul Pogonyshev [ 2022-09-09 ] |
|
Yeah, just add `max_select_rows`, set it 10000 and document. Then it will not be a bug when you silently return 10000 rows from a `select *` on a million-row table. And not wrong. |
| Comment by Sergei Golubchik [ 2022-09-09 ] |
|
https://mariadb.com/kb/en/server-system-variables/#sql_select_limit |
| Comment by Paul Pogonyshev [ 2022-09-09 ] |
|
Perfect. Just strange that is not 1000. |