[MDEV-6713] A join query is faster with index_condition_pushdown=off Created: 2014-09-09 Updated: 2022-12-27 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Description |
|
An example from customer: a join query is faster when one runs it with index_condition_pushdown=off. The difference is not big, but it's repeatable, so it is worth to investigate it. Query and dataset were provided by joffrey. Details are here in private comments (it's customer data). |
| Comments |
| Comment by Sergei Petrunia [ 2014-09-09 ] | |||||||||||||
|
Tried on current 10.0 tree, release build. Query execution time:
| |||||||||||||
| Comment by Elena Stepanova [ 2014-09-09 ] | |||||||||||||
|
Values from the current 10.0 tree revno 4383 (even scarier, but maybe it's a difference in build options; built as cmake && make): | |||||||||||||
| Comment by Sergei Petrunia [ 2014-09-17 ] | |||||||||||||
|
Investigation: InnoDB (and XtraDB too) has a "prefetch cache" that is used from When an index scan has read MYSQL_FETCH_CACHE_THRESHOLD=4 rows, then The the cache stores records in MySQL format. When ICP is not used, InnoDB will decode index tuple directly into the cache When ICP is used, row_search_for_mysql() needs to check ICP condition before
| |||||||||||||
| Comment by Sergei Petrunia [ 2014-09-17 ] | |||||||||||||
|
This works. However, suppose the table has a few VARCHAR(255) columns, but actual values are much shorter (typical). Let's assume the row we are unpacking has 10-byte values. | |||||||||||||
| Comment by Sergei Petrunia [ 2014-09-17 ] | |||||||||||||
|
Using the above as a guideline, I created an artificial dataset that would show the problem.. and it didn't work. It seems, I'm missing something here. | |||||||||||||
| Comment by Sergei Petrunia [ 2014-09-17 ] | |||||||||||||
|
Re-ran benchmark on the smaller query. Top CPU consumers when ICP=ON:
Top CPU consumers when ICP=OFF:
| |||||||||||||
| Comment by Sergei Petrunia [ 2014-09-17 ] | |||||||||||||
|
Again, the same picture, but ICP=ON has the new biggest user: row_sel_enqueue_cache_row_for_mysql | |||||||||||||
| Comment by Jan Lindström (Inactive) [ 2014-11-13 ] | |||||||||||||
|
Is this really a bug? In my understanding there is no certainty that ICP would help on all cases, When ICP is used, row_search_for_mysql() needs to check ICP condition before putting the row into cache. ICP condition can only be checked when index fields are in table->record[0]. | |||||||||||||
| Comment by Sergei Golubchik [ 2022-11-08 ] | |||||||||||||
|
It seems that when the condition selectivity is low (most of the rows match), ICP would add more overhead than it's worth. It is technically possible to estimate the selectivity of the ICP conidtion. But how to estimate the ICP overhead? | |||||||||||||
| Comment by Michael Widenius [ 2022-12-27 ] | |||||||||||||
|
In theory, Index_condition_pushdown should almost always be equal or faster. The more rows that does not match the condition, the bigger the difference. Even if all rows matches the condition, the difference should be practically neglectable in theory. (more of this below). The big benefits with index_condition_push_down
If there is even a few % of the rows that matches the condition, Index_condition_pushdown should perform better than not having it enabled. The extra overhead for index_condition_pushdown are:
To answer Sergei Golubchik, the above is not hard to estimate. Checking the index_condition should be neglect able as this is the same check we have to in the Reasons why index_condition_pushdown is slower:
|