<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>评论：mysql distinct和group by谁更好</title>
	<atom:link href="http://blog.51yip.com/mysql/1105.html/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.51yip.com/mysql/1105.html</link>
	<description>－－一步，二步，三步，N步，二行脚印</description>
	<lastBuildDate>Tue, 07 Jun 2022 01:26:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>来自：张映</title>
		<link>http://blog.51yip.com/mysql/1105.html/comment-page-1#comment-349</link>
		<dc:creator>张映</dc:creator>
		<pubDate>Fri, 26 Nov 2010 01:43:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.51yip.com/?p=1105#comment-349</guid>
		<description>索引就好比是一本书的目录，如果这本书很厚的话，找起东西来比较麻烦的，比如汉语字典，找字的时候，我们会先去找目录，因为这样找比较快一点。如果一本书，只有十几页，这个时候，我们找东西，根本不要去看目录了，因为这样更浪费时间。

从你贴出来的数据看，你测试的数据表里面，数据量比较小，这个时候加索引反而会影响速度的。</description>
		<content:encoded><![CDATA[<p>索引就好比是一本书的目录，如果这本书很厚的话，找起东西来比较麻烦的，比如汉语字典，找字的时候，我们会先去找目录，因为这样找比较快一点。如果一本书，只有十几页，这个时候，我们找东西，根本不要去看目录了，因为这样更浪费时间。</p>
<p>从你贴出来的数据看，你测试的数据表里面，数据量比较小，这个时候加索引反而会影响速度的。</p>
]]></content:encoded>
	</item>
	<item>
		<title>来自：kenny</title>
		<link>http://blog.51yip.com/mysql/1105.html/comment-page-1#comment-348</link>
		<dc:creator>kenny</dc:creator>
		<pubDate>Fri, 26 Nov 2010 01:22:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.51yip.com/?p=1105#comment-348</guid>
		<description>存储过程
DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`dis`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `dis`(num int(10))
begin
declare i int(10);
set i = 1;
while i &lt;= num do
insert into dis_group (num) values (floor(rand()*100));
set i=i+1;
end while;
end$$

DELIMITER ;
&#124; Query_ID &#124; Duration   &#124; Query                                    &#124;
+----------+------------+------------------------------------------+
&#124;        1 &#124; 0.00099400 &#124; show variables like &quot;%pro%&quot;              &#124; 
&#124;        2 &#124; 0.09483400 &#124; select distinct(num) from dis_group      &#124; 
&#124;        3 &#124; 0.09505400 &#124; select num from dis_group group by num   &#124; 
&#124;        4 &#124; 0.00004600 &#124; select num from dis_group group by num   &#124; 
&#124;        5 &#124; 0.00004200 &#124; select distinct(num) from dis_group      &#124; 
&#124;        6 &#124; 0.00004400 &#124; select distinct(num) from dis_group      &#124; 
&#124;        7 &#124; 0.00004400 &#124; select num from dis_group group by num   &#124; 
&#124;        8 &#124; 0.00004700 &#124; select distinct(num) from dis_group      &#124; 
&#124;        9 &#124; 0.00004400 &#124; select num from dis_group group by num   &#124; 
&#124;       10 &#124; 1.00069100 &#124; create index num_index on dis_group(num) &#124; 
&#124;       11 &#124; 0.00362300 &#124; select num from dis_group group by num   &#124; 
&#124;       12 &#124; 0.00200000 &#124; select distinct(num) from dis_group      &#124; 
&#124;       13 &#124; 0.00091000 &#124; select distinct(num) from dis_group      &#124; 
&#124;       14 &#124; 0.00098700 &#124; select num from dis_group group by num   &#124; 
&#124;       15 &#124; 0.00090600 &#124; select num from dis_group group by num 

我的结果中，没加索引前速度更快。估计我的机子太烂了~~</description>
		<content:encoded><![CDATA[<p>存储过程<br />
DELIMITER $$</p>
<p>DROP PROCEDURE IF EXISTS `test`.`dis`$$</p>
<p>CREATE DEFINER=`root`@`localhost` PROCEDURE `dis`(num int(10))<br />
begin<br />
declare i int(10);<br />
set i = 1;<br />
while i &lt;= num do<br />
insert into dis_group (num) values (floor(rand()*100));<br />
set i=i+1;<br />
end while;<br />
end$$</p>
<p>DELIMITER ;<br />
| Query_ID | Duration   | Query                                    |<br />
+----------+------------+------------------------------------------+<br />
|        1 | 0.00099400 | show variables like &quot;%pro%&quot;              |<br />
|        2 | 0.09483400 | select distinct(num) from dis_group      |<br />
|        3 | 0.09505400 | select num from dis_group group by num   |<br />
|        4 | 0.00004600 | select num from dis_group group by num   |<br />
|        5 | 0.00004200 | select distinct(num) from dis_group      |<br />
|        6 | 0.00004400 | select distinct(num) from dis_group      |<br />
|        7 | 0.00004400 | select num from dis_group group by num   |<br />
|        8 | 0.00004700 | select distinct(num) from dis_group      |<br />
|        9 | 0.00004400 | select num from dis_group group by num   |<br />
|       10 | 1.00069100 | create index num_index on dis_group(num) |<br />
|       11 | 0.00362300 | select num from dis_group group by num   |<br />
|       12 | 0.00200000 | select distinct(num) from dis_group      |<br />
|       13 | 0.00091000 | select distinct(num) from dis_group      |<br />
|       14 | 0.00098700 | select num from dis_group group by num   |<br />
|       15 | 0.00090600 | select num from dis_group group by num </p>
<p>我的结果中，没加索引前速度更快。估计我的机子太烂了~~</p>
]]></content:encoded>
	</item>
</channel>
</rss>
