On Fri, Jul 8, 2022 at 9:41 PM ashwin k <ashwin...@gmail.com> wrote:

> Limit fires an extra query when the offset is more than 1. I created a
> temp table and executed the query
> DB[:temp].limit(3,3).all
>
> *First it executed this query*
> START SELECT * FROM (SELECT * FROM "TEMP") "T1" WHERE (ROWNUM <= 1)
> - END ( 0.0060s) SELECT * FROM (SELECT * FROM "TEMP") "T1" WHERE (ROWNUM
> <= 1)
>
> *and then this*
>
> - START SELECT "ID", "NAME" FROM (SELECT "T1".*, ROWNUM
> "X_SEQUEL_ROW_NUMBER_X" FROM (SELECT * FROM "TEMP") "T1") "T1" WHERE
> (("X_SEQUEL_ROW_NUMBER_X" > 3) AND ("X_SEQUEL_ROW_NUMBER_X" <= (3 + 3)))
>
> - END ( 0.0033s) SELECT "ID", "NAME" FROM (SELECT "T1".*, ROWNUM
> "X_SEQUEL_ROW_NUMBER_X" FROM (SELECT * FROM "TEMP") "T1") "T1" WHERE
> (("X_SEQUEL_ROW_NUMBER_X" > 3) AND ("X_SEQUEL_ROW_NUMBER_X" <= (3 + 3))) =>
> [{:id=>0.4e1, :name=>"d"}, {:id=>0.5e1, :name=>"e"}]
>

Not sure what database you are using, but I'm guessing an old version of
Oracle?  In order to run the query with a limit and offset on an old
version of Oracle, the limit and offset need to be emulated using ROWNUM,
and that requires getting the columns.  The first query is run to get the
columns, and the second query to get the data (you can see the second query
uses the columns returned by the first query).

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSScb43%2B3r9M3-coN1G60B%3DuRJV_QuaRfY1XYBSf2SjKLAg%40mail.gmail.com.

Reply via email to