Subject | RE: [firebird-support] Implementing a scrolling function in a web environment (Re: how much faster does a "real server" do?) |
---|---|
Author | Alan McDonald |
Post date | 2006-05-29T10:09:38Z |
> At 02:42 PM 29/05/2006, you wrote:I've said this before - I'll risk declaring it again.
> >Hi Helen,
> > > Here's what the SELECT FIRST n SKIP m syntax does under the hood:
> > >
> > > 1. Gets the entire set specified by the WHERE clause and creates a
> > > temporary set (in memory on disk, depending on size and resources)
> > >
> > > 2. Physically orders the temporary set according to the
> ORDER BY clause.
> > >
> > > 3. Starts outputting rows from the temporary set, skipping the first
> > > m rows if SKIP is specified, until n rows have been sent
> > >
> > > 4. Ignores the rest of the temporary set
I've tested FIRST/SKIP from a performance point of view and I cannot
determine that this is what it does internally.
1. above is the same as selecting all rows from a view.
2. you can do this from a view too.
3. same again
4. OK
BUT if I do a FIRST/SKIP select from a large table, it returns much faster
than this process would have it do.
Simple Test: Choose any table with several million rows.
SELECT FIRST 100 SKIP 0 FROM TABLE ORDER BY PK
returns so fast that I find it hard to believe that it's done a full table
scan at all - let alone done any temporary set creation before doing
anything sensible. You can force FB to do this temporary set within a SP by
doing a
FOR SELECT pk FROM TABLE order by pk INTO :VALUE DO BEGIN
// do nothing much
END
and that performs quite badly in comparison.
Alan