<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>程式設計 遇上 小提琴 &#187; Performance</title>
	<atom:link href="http://blog.ez2learn.com/tag/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ez2learn.com</link>
	<description>Victor&#039;s個人部落格，關於程式設計與小提琴</description>
	<lastBuildDate>Tue, 07 Feb 2012 03:26:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>為什麼MySQL的InnoDB Select Count(*)這麼慢</title>
		<link>http://blog.ez2learn.com/2009/01/31/the-reason-of-slow-select-count/</link>
		<comments>http://blog.ez2learn.com/2009/01/31/the-reason-of-slow-select-count/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 04:01:13 +0000</pubDate>
		<dc:creator>victor</dc:creator>
				<category><![CDATA[中文文章]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[好站]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[資料庫]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[效能]]></category>

		<guid isPermaLink="false">http://blog.ez2learn.com/?p=501</guid>
		<description><![CDATA[為什麼MySQL的InnoDB Select Count(*)這麼慢 <a href="http://blog.ez2learn.com/2009/01/31/the-reason-of-slow-select-count/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>在美國租的主機不停的在抓資料，現在已經到了3百萬筆了，對於要知道筆數，最直觀的方式就是使用</p>
<blockquote><p>Select Count(*) From xxx</p></blockquote>
<p>但是我發現這樣極奇的慢，我們可能覺得很奇怪，以設計上來看，通常應該都要有個欄位是用來記錄這個資料表有多少筆資料，何以可以慢到這種地步，在上網找一堆資料，終於發現了原因，原來因為InnoDB可能有不通的交易同時發生，每筆交易中，可能會有刪除、新增等等事件發生，所以可以說每筆交易裡看到的筆數都是不一樣的，因此每次select count(*)都要做整張表的掃描，到了百萬的數量級，會這麼慢是理所當然的，替代的做法，可以使用</p>
<blockquote><p>Show Table Status Like &#8216;xxx&#8217;</p></blockquote>
<p>裡面有個欄位是行數，不過那個數字會和真的數字有差別，欄位裡的數字比較"髒"，但是以大部份的用途，像我們會用到Select Count(*)通常是想知道裡面有幾筆資料，不是很要緊的數字的話，其實差一些也不會怎樣，最經典的應用通常是"我們的網站有xxx個會員"，根本沒人會在意那個數字差了一點</p>
<p>這問題的答案我是在這篇文章裡找到的</p>
<h3 id="post-127" class="post-title"><a rel="bookmark" href="http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/">COUNT(*) for Innodb Tables</a></h3>
<p class="post-title">我發現那真的是一個很棒的部落格</p>
<h1><a href="http://www.mysqlperformanceblog.com"><span class="nolink">MySQL Performance Blog</span></a></h1>
<p>如同上面所寫的</p>
<blockquote><p>Everything about MySQL Performance</p></blockquote>
<p>裡面只談MySQL的效能問題，如何提升的做法，作者群似乎是來自一家專門幫忙提升MySQL資料庫效能的公司，遇到MySQL效能的問題這個部落格應該可以找到很好的答案，除此之外他們也有出一本<a href="http://www.amazon.com/gp/product/0596101716?ie=UTF8&amp;tag=perinc-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596101716">High Performance MySQL, Second Edition</a>的書</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ez2learn.com/2009/01/31/the-reason-of-slow-select-count/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

