Cache of MyISAM table

Source: Internet
Author: User

A friend of www.2cto.com asked a question today. The original Article is: mysql5.1, MyISAM table, select count (*) as total FROM m_bff WHERE from_uid = '000000' AND isdeleted = 0. From_uid has an index. The speed of executing this sentence for the first time is slow. It takes more than one second. The speed of using show profile is slow on Sending data. However, when I add SQL _no_cache, the execution takes only 0.01 seconds. Many sentences are similar. The first time the execution is slow, the addition of SQL _no_cache is not slow, and the Key_blocks_unused is also large, what is the reason for this? The problem is summarized as follows: why is the first query of the MyISAM table much slower than the second query? Recall the differences between innodb and MyISAM. One of the most important aspects is that MyISAM only caches index content, while innodb not only caches indexes but also data. It should be said that every time MyISAM queries data, there should be no big speed gap between Disk Access. In fact, there is an OS-level File Cache between MyISAM files and the operating system. The guess is the ghost of the OS file cache. Www.2cto.com: The verification method is actually very simple. Run cat 3>/proc/sys/vm/drop_caches with root permission in shell to clear the OS file cache, run SQL again to see if the speed is the same as that of the first run. Result: echo 3/proc/sys/vm/drop_caches slowed down again. It seems that the problem you mentioned is extended: after knowing the feature of MyISAM, you can use the File pre-read Method for Data push. Assume that a table is a hotspot table and the operating system has more memory. We can use cat table. MYD>/dev/null to load the file into the OS file cache. In this way, when data of some users is accessed for the first time, there will be no slow query.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.