Comments on: MySQL challenge: LIMIT rows accessed, not rows returned http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/ Stay curious! Thu, 02 May 2013 12:36:53 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Diseño Web Peru http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-15225 Diseño Web Peru Sun, 12 Oct 2008 20:40:53 +0000 http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-15225 the corect code is

SELECT * FROM pregunta order by idpre desc limit 0,10

]]>
By: Sheeri Cabral http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14846 Sheeri Cabral Tue, 01 Jul 2008 17:05:28 +0000 http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14846 Rob — in fact, I was aware. That’s why I said MySQL doesn’t have it “yet”, because indexes on functions and other similar features that stem from materializing data is something I think people will request/demand/pay for in MySQL sooner rather than later.

]]>
By: Rob Wultsch http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14845 Rob Wultsch Tue, 01 Jul 2008 12:03:17 +0000 http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14845 Sheeri:
Your probably aware, but I think it is worth note just in case you are not that Postgres supports indexs on a function of a column.
http://www.postgresql.org/docs/8.3/interactive/indexes-expressional.html
IIRC Oracle supports something similar as well.

]]>
By: Sheeri Cabral http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14844 Sheeri Cabral Tue, 01 Jul 2008 10:32:04 +0000 http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14844 The biggest problem is that even though you’re looking at an index on a column, what you really want is an index on a function of a column — in this case, you want an index on (actor_id % 5).

As this is for an external tool I do not know how much schema changing you can do, nor do I know how much performance you want to sacrifice by having a copy of a table where you can index what you *really* want to index.

Subqueries won’t help because MySQL doesn’t support LIMIT in subqueries; what you’d really like is something like

explain select actor_id
from actor
where actor_id in (select actor_id from actor limit 20)
and actor_id % 5 = 0;

but that’s not possible with MySQL just yet.

Another way to look at it is using relational calculus. What you want is the intersection of 2 tables:

SELECT tbl1.actor_id FROM actor as tbl1 WHERE actor_id % 5 = 0 limit 5;
SELECT tbl2.actor_id FROM actor as tbl2 LIMIT 20;

And you can’t really have 2 LIMITs in one query.

Hacks like the max_concat trick might work. Another way to look at it is to see the query as “the top x values in a group” except it’s not the “top” x values.

If this were a client I’d recommend having a separate column that’s actor_id % 5 and put an index on that; although given the generic nature of your issue, that may not be the rightest solution.

]]>
By: Xaprb http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14842 Xaprb Tue, 01 Jul 2008 04:55:48 +0000 http://www.xaprb.com/blog/2008/06/28/mysql-challenge-limit-rows-accessed-not-rows-returned/#comment-14842 That’s an excellent point. I had a TODO note to build some code that could figure out when HANDLER is appropriate to use. It has some limitations of course.

]]>