Could you provide some detail as to what/how you plan to use those 9 million (+1) numbers?
If the sole purpose is to send a stream of numbers back to the client, it seems to me that it'd be much more efficient to just have the client application generate the 9m numbers.
There are many ways to generate a sequence of numbers using a single query based on the cartesian product of a handful of smaller tables (see RMH's base-10 example), but all of these solutions require:
- first, the entire cartesian product to be built in tempdb
- then, the entire cartesian product to be sorted (in memory and tempdb)
- and only then are the desired numbers sent back to the client
This overhead is required of the same 'generator' query regardless of whether you want to generate a small set of numbers (1 to 10) or a large set of numbers (1 to 9,000,000).
Obviously a better, more efficient, lightweight method needs to be used to keep from hogging dataserver resources (eg, imaagine several users/applications trying to generate 9,000,000 numbers ... all using large volumes of tempdb space as well as cpu resources ... egad ... expect an angry email/phone-call from the DBA!).
Another idea would be use a looping construct to generate the desired numbers ...
declare @counter bigint, @max bigint
select @counter=0, @max=9000000
while @counter <= @max
begin
select @counter
select @counter=@counter+1
end
... and while this will eliminate the tempdb overhead, you're still going to use up a moderate amount of cpu resources looping 9 million times. An additional performance hit could come from the overhead of generating 9 million 1-row result sets, in particular you'll likely see an excessive number of network packets flowing between the dataserver and the client application.
While we could reduce the volume of network packets by making the final result look like a single result set, this would require turning the above looping construct into a stored procedure, making sure you have a loopback server defined, and then creating a proxy table to reference said proc; you would then query the proxy table to obtain what looks like a single result set containing the desired set of numbers.
'course, at this point we've now had to jump through a few hoops just to have the dataserver generate (in a somewhat efficient method) a series of numbers as a single result set.
There may be some other means by which Sybase/ASE can generate a series of numbers (eg, create/populate a table with an identity column), but all will require either a) a good bit of dataserver resources or b) some convoluted code (eg, application context functions, plug-in java code) ... to do something that is likely more efficiently handled by the client/front-end application.