Comments on: The integers table http://www.xaprb.com/blog/2005/12/07/the-integers-table/ Stay curious! Thu, 02 May 2013 12:36:53 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Robert Eisele http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-19691 Robert Eisele Tue, 11 Oct 2011 23:13:05 +0000 http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-19691 Hi Baron,

I’m currently in a phase where I abuse information_schema tables for optimizations very savage. I had the idea for the first time, when I wanted to generate 10 random numbers from 1 to auto_increment of a table:

SELECT 1 + FLOOR(RAND() * auto_increment) start
FROM information_schema.global_status
JOIN (
SELECT auto_increment
FROM information_schema.tables
WHERE table_schema=DATABASE()
AND table_name=’t1′
)X
LIMIT 10;

Combined with the idea of your cross-join solution, one could use something like this instead of having a temporary integer table:

SELECT @x:= @x + 1
FROM (
SELECT @x:= 0
) TMP
JOIN (
SELECT *
FROM information_schema.global_status
LIMIT 10
) X
CROSS JOIN (
SELECT *
FROM information_schema.global_status
LIMIT 10
) Y
CROSS JOIN (
SELECT *
FROM information_schema.global_status
LIMIT 10
) Z;

I used global_status, because this table has about 300 elements, which allows to change the LIMIT in a very constant and also large range.

Robert

]]>
By: sage http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-15149 sage Mon, 29 Sep 2008 23:36:45 +0000 http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-15149 Jeremy, there isn’t an identity in mysql, is there?

Xaprb, am not seeing how this plus the code in your page on char-dump work together since your integer table ends up being 0-9. There’s no doubt a better way, but I created a larger integer table via a temporary 0-9 table:

create table Uintegers(i int unsigned not null);
create table integers(i int unsigned not null);
insert into Uintegers(i) values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);

(like yours so far)
Then, use this table of 9 as workspace to create the needed collection of integers (0-999):

insert into integers (
select (hundreds.i * 100) + (tens.i * 10) + units.i as iii
from Uintegers as units
cross join Uintegers as tens
cross join Uintegers as hundreds );

Then, to clean up:

drop table Uintegers;

]]>
By: Jeremy West http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-14523 Jeremy West Wed, 07 May 2008 16:59:25 +0000 http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-14523 I came accross this blog trying to learn more about Tally Tables, anyway here something else I found that does what your showing above, but faster if your interested. (Ran in about 1/9th the time for 100,000 numbers) Cool Blog, hope that book is comming well.

DECLARE @StartTime DATETIME –Timer to measure total
SET @StartTime = GETDATE() –Start the timer

SELECT TOP 100000
IDENTITY(INT,1,1) AS N
INTO dbo.Tally
FROM Master.dbo.SysColumns sc1,
Master.dbo.SysColumns sc2

Select * From Tally

Drop table Tally
SELECT STR(DATEDIFF(ms,@StartTime,GETDATE())) ‘ Milliseconds duration’

]]>
By: Xaprb http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-1346 Xaprb Sat, 05 Aug 2006 21:45:58 +0000 http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-1346 Ah yes, I see you have written articles about this topic too! I forget now who I originally got the idea from, but it’s out there in a number of places (no pun intended). Thanks for the compliment!

]]>
By: rudy http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-85 rudy Sat, 04 Feb 2006 19:03:29 +0000 http://www.xaprb.com/blog/2005/12/07/the-integers-table/#comment-85 Thank you for providing the link to “someone else’s idea.” ;o)

[Takes quick look around] hey, fabulous site, and some great contents.

[Bookmarks]

]]>