# Limit & offset ,will it be fast ? in combine query. urgent

**URL:** <https://www.ruby-forum.com/t/limit-offset-will-it-be-fast-in-combine-query-urgent/123841>\
**Category:** Rails\
**Created:** [December 21, 2007, 6:40am UTC](https://www.ruby-forum.com/t/limit-offset-will-it-be-fast-in-combine-query-urgent/123841 "2007-12-21T06:40:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 21, 2007, 6:40am UTC](https://www.ruby-forum.com/t/limit-offset-will-it-be-fast-in-combine-query-urgent/123841/1 "2007-12-21T06:40:19Z")

</div>

i have a small doubt.  
if i write combine query in Model.find() WITH limit & offset to get 10  
records per hit .but my friend told that when to get last 10 records  
then the time will be same as to get Model.find() WITHOUT limit &  
offset.

he told like that ,the data base will create a temp table to keep our  
(query result table) then it will get corresponding number of records  
from the new table like records (0…10,10…20,20…30…).then he  
told by this way to get last 10 records ,it will be same time as  
ordinary Model.find() WITHOUT limit & offset

is it correct ?

any idea …

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 21, 2007, 7:36am UTC](https://www.ruby-forum.com/t/limit-offset-will-it-be-fast-in-combine-query-urgent/123841/2 "2007-12-21T07:36:22Z")

</div>

What kind of drugs is your friend on?

There is no temporary table creation for storing records, unless he’s  
talking about Rails 2.0 new “query caching”.

Doing a find with limit and offset will of course be quicker than doing  
it  
without because it’s not fetching as much data from the table.

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 21, 2007, 9:23am UTC](https://www.ruby-forum.com/t/limit-offset-will-it-be-fast-in-combine-query-urgent/123841/3 "2007-12-21T09:23:28Z")

</div>

database drugs?

It’s quite possible for mysql to materialize temporary tables for the  
purpose of evaluating a query. With any if these things you can always  
ask the database (on mysql EXPLAIN SELECT \* from foos limit 100,200)  
what it would do.

If your find clause also has a sort order then you’d better have an  
index on that column or it could be dog slow (since then the database  
has to sort the entire table to find the top 10 records).

Fred

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 21, 2007, 7:04pm UTC](https://www.ruby-forum.com/t/limit-offset-will-it-be-fast-in-combine-query-urgent/123841/4 "2007-12-21T19:04:07Z")

</div>

Frederick C. wrote:

> database drugs?
> 
> It’s quite possible for mysql to materialize temporary tables for the  
> purpose of evaluating a query. With any if these things you can always  
> ask the database (on mysql EXPLAIN SELECT \* from foos limit 100,200)  
> what it would do.
> 
> If your find clause also has a sort order then you’d better have an  
> index on that column or it could be dog slow (since then the database  
> has to sort the entire table to find the top 10 records).
> 
> Fred

so is it it is possible in mysql.  
for other database adapter will it be fast ? is it ?
