<?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"
	>
<channel>
	<title>Comments on: A challenge: partition a character set in MySQL</title>
	<atom:link href="http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/</link>
	<description>Stay curious!</description>
	<pubDate>Tue, 06 Jan 2009 05:15:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Newbie</title>
		<link>http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11789</link>
		<dc:creator>Newbie</dc:creator>
		<pubDate>Thu, 21 Jun 2007 22:21:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11789</guid>
		<description>Thanks for the explanation.</description>
		<content:encoded><![CDATA[<p>Thanks for the explanation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dipin</title>
		<link>http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11787</link>
		<dc:creator>Dipin</dc:creator>
		<pubDate>Thu, 21 Jun 2007 19:03:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11787</guid>
		<description>Expanding on Anonymous' solution, couldn't you do the following?

- fetch the first chunk
select min(name) as min_name, max(name) as max_name from ( SELECT name from table ORDER BY name LIMIT N) temp

- while there are other rows to be fetched
do
last_name = max_name from chunk[N-1]
select min(name) as min_name, max(name) as max_name from ( SELECT name from table WHERE name &#62; last_name
ORDER BY name LIMIT N) temp

I haven't tested this on all versions of MySQL but it seems to work on 5.0 where it leverages the index although it does end up using a derived table to temporarily hold the data from the index.

-Dipin</description>
		<content:encoded><![CDATA[<p>Expanding on Anonymous&#8217; solution, couldn&#8217;t you do the following?</p>
<p>- fetch the first chunk<br />
select min(name) as min_name, max(name) as max_name from ( SELECT name from table ORDER BY name LIMIT N) temp</p>
<p>- while there are other rows to be fetched<br />
do<br />
last_name = max_name from chunk[N-1]<br />
select min(name) as min_name, max(name) as max_name from ( SELECT name from table WHERE name &gt; last_name<br />
ORDER BY name LIMIT N) temp</p>
<p>I haven&#8217;t tested this on all versions of MySQL but it seems to work on 5.0 where it leverages the index although it does end up using a derived table to temporarily hold the data from the index.</p>
<p>-Dipin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11737</link>
		<dc:creator>Xaprb</dc:creator>
		<pubDate>Wed, 20 Jun 2007 01:16:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11737</guid>
		<description>No, no, it's a good question.  It is efficient for several reasons:

1) WHERE foo &gt; bar makes MySQL seek into the index and start the scan there.  It doesn't have to scan the rows before that in the index.

2) The rows are already sorted because I'll use the primary key.

3) LIMIT N makes MySQL stop after it finds enough rows.

By contrast, OFFSET makes MySQL throw away OFFSET number of rows.

That said, I actually realized this won't work in the particular situation I need it to -- because the real query I'm using is grouped implicitly into a single row with MAX(), and LIMIT operates after grouping, not before.  This is why I was thinking it needed to be a BETWEEN clause -- I was thinking so hard about the problem I forgot the context.  

There are other options, but still nothing magical is presenting itself.  I'm going to work on some other things, where I have work lined up for myself, and see if something clever comes to me.  It has happened in the past.</description>
		<content:encoded><![CDATA[<p>No, no, it&#8217;s a good question.  It is efficient for several reasons:</p>
<p>1) WHERE foo > bar makes MySQL seek into the index and start the scan there.  It doesn&#8217;t have to scan the rows before that in the index.</p>
<p>2) The rows are already sorted because I&#8217;ll use the primary key.</p>
<p>3) LIMIT N makes MySQL stop after it finds enough rows.</p>
<p>By contrast, OFFSET makes MySQL throw away OFFSET number of rows.</p>
<p>That said, I actually realized this won&#8217;t work in the particular situation I need it to &#8212; because the real query I&#8217;m using is grouped implicitly into a single row with MAX(), and LIMIT operates after grouping, not before.  This is why I was thinking it needed to be a BETWEEN clause &#8212; I was thinking so hard about the problem I forgot the context.  </p>
<p>There are other options, but still nothing magical is presenting itself.  I&#8217;m going to work on some other things, where I have work lined up for myself, and see if something clever comes to me.  It has happened in the past.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Newbie</title>
		<link>http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11714</link>
		<dc:creator>Newbie</dc:creator>
		<pubDate>Tue, 19 Jun 2007 00:53:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11714</guid>
		<description>Sorry if I am asking a stupid question, but doesn't "SELECT foo FROM table WHERE foo &#62; bar ORDER BY foo LIMIT n" scan through the table, sort the rows and discard part of the results? How is it different from "LIMIT n OFFSET m" in terms of performance?</description>
		<content:encoded><![CDATA[<p>Sorry if I am asking a stupid question, but doesn&#8217;t &#8220;SELECT foo FROM table WHERE foo &gt; bar ORDER BY foo LIMIT n&#8221; scan through the table, sort the rows and discard part of the results? How is it different from &#8220;LIMIT n OFFSET m&#8221; in terms of performance?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11563</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 13 Jun 2007 20:18:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2007/06/11/a-challenge-partition-a-character-set-in-mysql/#comment-11563</guid>
		<description>Hello

I'm glad to see you have liked my solution - yes it works only on 
unique indexes (on a non-unique index the where clause name &#62; last_name
may skip some rows), but it works for any data types.

I've found your articles very useful and instructive, keep up the good work!

C</description>
		<content:encoded><![CDATA[<p>Hello</p>
<p>I&#8217;m glad to see you have liked my solution - yes it works only on<br />
unique indexes (on a non-unique index the where clause name &gt; last_name<br />
may skip some rows), but it works for any data types.</p>
<p>I&#8217;ve found your articles very useful and instructive, keep up the good work!</p>
<p>C</p>
]]></content:encoded>
	</item>
</channel>
</rss>
