Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by demerphq (Chancellor)
on Oct 05, 2004 at 17:42 UTC ( [id://396688]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Ranking position in a SQL index
in thread Ranking position in a SQL index

Sybase does it via a variable called 'rowcount'. So you say

set rowcount 100 select * from foo

But there is no way to do the equivelent of the skip feature of limit to the best of my knowledge. You'd have to manage it through ids and a where I think. I agree that 'limit' is one of a small set of things I like more about MySQL than Sybase. At least insofar as the MySQL that PM uses is the comparison I much prefer Sybase. :-)


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi

    Flux8


Replies are listed 'Best First'.
Re^5: Ranking position in a SQL index (vairants of limit:sybase)
by mpeppler (Vicar) on Oct 05, 2004 at 19:35 UTC
    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://396688]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found