Subject | Re: FIRST/TOP/LIMIT/ROWNUM - Proposals |
---|---|
Author | ft@cluedup.com |
Post date | 2001-06-07T17:21:34Z |
--- In IBDI@y..., "Syarzhuk Kazachenka" <bamboo7431@h...> wrote:
during development. You want to see quickly if your query returns any
rows at all, or examine the formatting of returned columns.
ROWNUM psuedocolumn becomes available within the scope of compound
queries. The rows of the result set returned by any query would be
numbered from 1 to rowcount and this number can be used in a main
query or a subquery to return a subset of the original result set.
(This extends the current behavious of Oracle ROWNUM).
One could make use of ROWNUM as described above to issue one query to
return the first row of each page that would be returned in chunks.
If I were dividing an alphabetically sorted list of names and
addresses into 20 pages of 20 entries each, the hyperlinks could
display the first name that would appear on each page alongside its
record range.
1-20 Alex 21-40 Bob 41-60 Ed 61-80 Gill ...
development aid. Suppose the main sort key is people's names. The 100
records could be a mix or could contain only names beginning with D
or with Z.
SQL, rather than procedural code, and the LIMIT keyword would help a
lot.
Fred Toussi
> After reading all these threads I think here's what the discussionis coming
> to:care what
> 1. It would be nice if we could add a FIRST n or TOP n (I don't
> it's called) extension to the IB/FB SQL. It should do the following:It seems the only use of FIRST n or TOP n is in interactive queries
during development. You want to see quickly if your query returns any
rows at all, or examine the formatting of returned columns.
> Now to the question about Web users paging thru results:allow to
> 2. It would be nice if we could an extension to SQL that would
> select only rows M to N from an *ordered* list. Again, I don't carehow it's
> called - LIMIT M TO N or WHERE ROWNUM BETWEEN M AND N.sort the
>
> 2a. If the SQL query contains a predicate that forces the engine to
> result set (ORDER BY or GROUP BY) then the engine should run aquery, sort
> the result set and only return rows M to N from the result set.set, I
>
> 2b. If the SQL query doesn't force the engine to sort the result
> could agree with either of the two approaches:result set;
>
> 2bE - returning an Error that the result set is not sortable;
>
> or
>
> 2bR - returning only Records M to N from the original unsorted
> generally speaking, such behavior will cause unpredictable returnresults
> and will be of little to no use.Both options are fine. But in addition, it has been propesed that a
ROWNUM psuedocolumn becomes available within the scope of compound
queries. The rows of the result set returned by any query would be
numbered from 1 to rowcount and this number can be used in a main
query or a subquery to return a subset of the original result set.
(This extends the current behavious of Oracle ROWNUM).
One could make use of ROWNUM as described above to issue one query to
return the first row of each page that would be returned in chunks.
If I were dividing an alphabetically sorted list of names and
addresses into 20 pages of 20 entries each, the hyperlinks could
display the first name that would appear on each page alongside its
record range.
1-20 Alex 21-40 Bob 41-60 Ed 61-80 Gill ...
> As far as I understand, proposal 1 is easy to implement right now(but do we
> all agree that limiting resultset to the first N records should behappening
> AFTER the sort? I know Oracle would assign ROWNUMs first, limit theresult
> set (to, say, first 100 rows if you used ROWNUM<=100) and only*then*
> applying the sort) I know sorting the whole set is expensive, butthere is
> no free lunch.I can't see what use the Oracle behavious has apart from being a
development aid. Suppose the main sort key is people's names. The 100
records could be a mix or could contain only names beginning with D
or with Z.
> If proposal 1 is implemented, I think proposal 2a will the nextlogical
> step, after all LIMIT M TO N == FIRST N - FIRST M.is not
> I think we could stop at 2bE (returning an error if a LIMIT query
> sorted), and 98% of the developers will be happy.I would certainly prefer to do selection, filtering and sorting in
SQL, rather than procedural code, and the LIMIT keyword would help a
lot.
Fred Toussi