7.4.5.3. Midpoint Insertion Strategy
By default, the key cache management system uses a simple LRU strategy for choosing key cache blocks to be evicted, but it also supports a more sophisticated method called the midpoint insertion strategy.
Key Cache管理系统默认使用LRU策略来选择丢弃的block,它同样支持一种更复杂的方法:midpoint insertion strategy。
When using the midpoint insertion strategy, the LRU chain is divided into two parts: a hot sublist and a warm sublist. The division point between two parts is not fixed, but the key cache management system takes care that the warm part is not “too short,” always containing at least key_cache_division_limit percent of the key cache blocks. key_cache_division_limit is a component of structured key cache variables, so its value is a parameter that can be set per cache.
当使用midpoint insertion strategy策略时,LRU的链被分成两部分:hot子链和warm子链。分割点不是固定的,但是Key Cache管理系统控制着warm子链,不会让它过于短,至少是key_cache_division_limit的百分比于Key Cache的长度。key_cache_division_limit是Key Cache的系统变量,所以它可以为每个Cache设置。
When an index block is read from a table into the key cache, it is placed at the end of the warm sublist. After a certain number of hits (accesses of the block), it is promoted to the hot sublist. At present, the number of hits required to promote a block (3) is the same for all index blocks.
当一个索引块被从表中读取到Key Cache中时,它被放在warm子链的尾部。在一定数量的访问(点击)后,(其实在这之前该block已经在warm子链的开始部分了)它被提升到hot子链中。在目前来说,对该block的访问次数是所有的index blocks的总和(数字的等同)。
A block promoted into the hot sublist is placed at the end of the list. The block then circulates within this sublist. If the block stays at the beginning of the sublist for a long enough time, it is demoted to the warm sublist. This time is determined by the value of the key_cache_age_threshold component of the key cache.
当一个block被提升到hot子链时,它是放在hot子链的尾部。然后该block开始在hot子链中循环。如果该block在hot子链的开始部分待了很长时间,它会被降到warm子链。这次决定的是key_cache_age_threshold系统变量。

The threshold value prescribes that, for a key cache containing N blocks, the block at the beginning of the hot sublist not accessed within the last N × key_cache_age_threshold / 100 hits is to be moved to the beginning of the warm sublist. It then becomes the first candidate for eviction, because blocks for replacement always are taken from the beginning of the warm sublist.
假定Key Cache中有N个blocks,临界值规定了:在hot子链开始部分的block在最近的(N × key_cache_age_threshold / 100)次访问中没有涉及的话被放回warm子链的开始部分。key_cache_age_threshold决定了频率的高低(最小值100)。然后该block成为最有可能被丢弃的,因为新的block替换就发生在warm子链的开始部分。
The midpoint insertion strategy allows you to keep more-valued blocks always in the cache. If you prefer to use the plain LRU strategy, leave the key_cache_division_limit value set to its default of 100.
midpoint insertion strategy能让你保持重要的block始终在Cache中(设置key_cache_age_threshold即可)。如果你还是想使用LRU策略,那么将key_cache_division_limit设置成默认的100
The midpoint insertion strategy helps to improve performance when execution of a query that requires an index scan effectively pushes out of the cache all the index blocks corresponding to valuable high-level B-tree nodes. To avoid this, you must use a midpoint insertion strategy with the key_cache_division_limit set to much less than 100. Then valuable frequently hit nodes are preserved in the hot sublist during an index scan operation as well.
midpoint insertion strategy帮助你提升执行全索引扫描时几乎所有的Cache(warm子链的部分)都要替换成新的B树节点的性能。为了避免对性能产生较大的影响,你必须将key_cache_division_limit设置成小于100(有效地控制其影响范围)。这样重要的经常访问的节点在全索引扫描时就被保护在hot子链中。
总结:相当于在一个LRU链上虚拟了两个链(hot和warm),全索引扫描时不会波及全部。