Suboptimal AHI partitioning code to access AHI latches and hash tables

Bug #1218321 reported by Alexey Kopytov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Server moved to https://jira.percona.com/projects/PS
Fix Released
Low
Alexey Kopytov
5.1
Invalid
Undecided
Unassigned
5.5
Fix Released
Low
Alexey Kopytov
5.6
Fix Released
Low
Alexey Kopytov

Bug Description

The AHI partitioning code looks up the latch corresponding to a specific index through a helper (inline) function btr_search_get_latch(). Which calculates the offset into the array of latches as index->id modulo the number of AHI partitions. So it may end up calculating the same number many times per row, even though it is a constant for each particular index.

Additionally, for some unknown reasons slots in the array of latches are pointers to latches, rather than the actual latches.

So the following steps are performed whenever InnoDB wants to get an adaptive hash index latch:

1. Read index->id
2. calculate index->id % btr_search_index_num
3. read the base address of the latches array
4. read the latch pointer corresponding to the base address and the offset calculated on step #2.

By making the latch an attribute of the index struct (which it really is), the above can become:

1. Read index->search_latch

Which is not a big optimization in itself, but again that code is sometimes executed on critical code paths many times per each row, and that change also results in a bit cleaner code in a few places (e.g. we don't have to store the latch pointer in a control block of a buffer pool frame, and then do dirty reads and verify if block->index is in sync with block->btr_search_latch, etc.)

The same applies to hash tables protected by the corresponding latches.

Related branches

Revision history for this message
Alexey Kopytov (akopytov) wrote :

Does not technically apply to 5.6, but will be soon once AHI partitioning is ported there.

tags: added: ahi-partitions
description: updated
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-2041

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.