当前位置:Gxlcms > 数据库问题 > 【InnoDB】插入缓存,两次写,自适应hash索引

【InnoDB】插入缓存,两次写,自适应hash索引

时间:2021-07-01 10:21:17 帮助过:15人阅读

技术图片

doublewrite一共写了18 445个页,但实际的写入次数为434,(42:1)   基本上符合64:1。

如果发现你的系统在高峰时Innodb_dblwr_pages_written:Innodb_dblwr_writes远小于64:1,那么说明你的系统写入压力并不是很高。

如果操作系统在将页写入磁盘的过程中崩溃了,在恢复过程中,InnoDB存储引擎可以从共享表空间中的doublewrite中找到改页的一个副本,将其拷贝到表空间文件,再应用重做日志。下面显示了由doublewrite进行恢复的一种情况: 

090924 11:36:32 mysqld restarted
090924 11:36:33 InnoDB:Database was not shut down normally!
InnoDB:Starting crash recovery.
InnoDB:Reading tablespace information from the.ibd files……
InnoDB:Error:space id in fsp header 0,but in the page header 4294967295
InnoDB:Error:tablespace id 4294967295 in file./test/t.ibd is not sensible
InnoDB:Error:tablespace id 0 in file./test/t2.ibd is not sensible
090924 11:36:33 InnoDB:Operating system error number 40 in a file operation.
InnoDB:Error number 40 means‘Too many levels of symbolic links‘.
InnoDB:Some operating system error numbers are described at
InnoDB:http://dev.mysql.com/doc/refman/5.0/en/operating-system-error-codes.html
InnoDB:File name./now/member
InnoDB:File operation call:‘stat‘.
InnoDB:Error:os_file_readdir_next_file()returned-1 in
InnoDB:directory./now
InnoDB:Crash recovery may have failed for some.ibd files!
InnoDB:Restoring possible half-written data pages from the doublewrite
InnoDB:buffer……
 

参数skip_innodb_doublewrite可以禁止使用两次写功能,这时可能会发生前面提及的写失效问题。不过,如果你有多台从服务器(slave server),需要提供较快的性能(如slave上做的是RAID0),也许启用这个参数是一个办法。不过,在需要提供数据高可靠性的主服务器(master server)上,任何时候我们都应确保开启两次写功能。

注意:有些文件系统本身就提供了部分写失效的防范机制,如ZFS文件系统。在这种情况下,我们就不要启用doublewrite了。 

 

自适应哈希索引

哈希(hash)是一种非常快的查找方法,一般情况下查找的时间复杂度为O(1)。常用于连接(join)操作,如SQL Server和Oracle中的哈希连接(hash join)。但是SQL Server和Oracle等常见的数据库并不支持哈希索引(hash index)。MySQL的Heap存储引擎默认的索引类型为哈希,而InnoDB存储引擎提出了另一种实现方法,自适应哈希索引(adaptive hash index)。

InnoDB存储引擎会监控对表上索引的查找,如果观察到建立哈希索引可以带来速度的提升,则建立哈希索引,所以称之为自适应(adaptive)的。自适应哈希索引通过缓冲池的B+树构造而来,因此建立的速度很快。而且不需要将整个表都建哈希索引,InnoDB存储引擎会自动根据访问的频率和模式来为某些页建立哈希索引。

根据InnoDB的官方文档显示,启用自适应哈希索引后,读取和写入速度可以提高2倍;对于辅助索引的连接操作,性能可以提高5倍。自适应哈希索引是非常好的优化模式,其设计思想是数据库自优化(self-tuning),即无需DBA对数据库进行调整。

查看当前自适应哈希索引的使用状况:show engine innodb status\G

技术图片

技术图片

现在可以看到自适应哈希索引的使用信息了,包括自适应哈希索引的大小、使用情况、每秒使用自适应哈希索引搜索的情况。值得注意的是,哈希索引只能用来搜索等值的查询,如select * from table where index_col=‘xxx‘,而对于其他查找类型,如范围查找,是不能使用的。因此,这里出现了non-hash searches/s的情况。用hash searches:non-hash searches命令可以大概了解使用哈希索引后的效率。

由于自适应哈希索引是由InnoDB存储引擎控制的,所以这里的信息只供我们参考。不过我们可以通过参数innodb_adaptive_hash_index来禁用或启动此特性,默认为开启。

【InnoDB】插入缓存,两次写,自适应hash索引

标签:secondary   长度   监控   table   随机   slave   recover   ade   根据   

人气教程排行