Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^5: Ranking position in a SQL index (vairants of limit:sybase)

by mpeppler (Vicar)
on Oct 05, 2004 at 19:35 UTC ( [id://396737]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Ranking position in a SQL index (vairants of limit:sybase)
in thread Ranking position in a SQL index

The problem is that to implement "limit" in a truly relational system you really have to internally fetch all the rows before the first row specified in the limit, and then start returning rows. So you're going to do a lot of IOs if you have something like
select ... from big_table limit 1000000, 1000010
And of course you should always include an ORDER BY clause as there is no guarantee that the result set will be int the "right" order.

On the other hand if you use a WHERE clause the server can limit the IO to the correct pages of data...

I have implemented versions of LIMIT by using a temporary table with an identity column, something like:

set rowcount 10010 select pk, id = syb_identity(10) into #tmp from big_table where some_c +ondition select b.* from big_table b, #tmp t where t.pk = b.pk and t.id >= 10000 set rowcount 0
Obviously a lot of IO if you need to find rows located fairly deep into the result set, but acceptable for a pagination system where the user usually only looks at the first few pages...

Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://396737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-18 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found