View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 07:54 AM
Bill Karwin
 
Posts: n/a
Default Re: Generating interger enumeration using select statement

frebe73@gmail.com wrote:
> I want to create a view that enumerates all integers.


> select digit as value
> from digits
> union ...


You don't need to do unions if your digits table includes zero.

create view all_integers as
select d1.digit + d2.digit*10 + d3.digit*100 + d4.digit*1000
from digits d1, digits d2, digits d3, digits d4;

The above should generate values from 0 to 9999. On my machine (Windows
SP, Pentium 4, 1GB RAM, MySQL 5.0.21) it returned this result in 0.0613
seconds. I added an index to digits.digit, but it made no significant
difference.

I don't think ORDER BY should be included in view definitions.

I then tried "select * from all_integers where `value` between 110 and
115" and it returned in 0.0053 seconds.

Regards,
Bill K.
Reply With Quote