[MDEV-4189] Poor execution plan for single-table grouping query with limit clause Created: 2013-02-19 Updated: 2019-05-19 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.1, 5.5.29, 5.1.67, 5.2.14 |
| Fix Version/s: | 10.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Igor Babaev | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | order-by-optimization | ||
| Description |
|
In many cases, when there is no index compatible with the group list of a query over one table, and, at the same time, a range condition over an index can be extracted from the WHERE clause, the optimizer chooses the execution plan over this range rather than a table scan plan as soon as the query uses a limit clause. The problem can be demonstrated on the following test case. Create and populate table t1 with following commands:
Then you'll see with any MariaDB version/release that the query
is executed with a table scan,
is executed with a range scan that is very inefficient here:
|
| Comments |
| Comment by Sergei Petrunia [ 2013-02-25 ] | |||||||||||||||||||||||||||||||||||||
|
We have also agreed that current code is wrong in not taking the presence of GROUP BY into account; "limit" parameter of test_quick_select() should be the same as it was during the regular range analysis. (But note the ICP difference I've marked above. Perhaps, this is hitting some bug.) | |||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2013-05-04 ] | |||||||||||||||||||||||||||||||||||||
|
make_join_statistics() calls get_quick_record_count() with join->row_limit
get_quick_record_count passes that number to test_quick_select() as its
That is, the idea "always pass the same limit parameter to test_quick_select()"
| |||||||||||||||||||||||||||||||||||||
| Comment by Daniel Black [ 2015-06-22 ] | |||||||||||||||||||||||||||||||||||||
|
is this patch worth applying now? | |||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2019-05-19 ] | |||||||||||||||||||||||||||||||||||||
|
In connection with |