Created
April 26, 2012 07:05
-
-
Save hikoma/2497031 to your computer and use it in GitHub Desktop.
Create tables containing random int values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS t; | |
CREATE TABLE t ( | |
id INT NOT NULL AUTO_INCREMENT, | |
x INT NOT NULL, | |
y INT NOT NULL, | |
z INT NOT NULL, | |
PRIMARY KEY (id) | |
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; | |
DELIMITER $$ | |
DROP PROCEDURE IF EXISTS createData$$ | |
CREATE PROCEDURE createData(size INT, count INT) | |
BEGIN | |
SET @s = 'INSERT INTO t(x,y,z) VALUES (FLOOR(RAND()*1000),FLOOR(RAND()*100000),FLOOR(RAND()*10000000))'; | |
SET @i = 1; | |
WHILE @i < size DO | |
SET @s = CONCAT(@s, ',(FLOOR(RAND()*1000),FLOOR(RAND()*100000),FLOOR(RAND()*10000000))'); | |
SET @i = @i + 1; | |
END WHILE; | |
PREPARE stmt FROM @s; | |
SET @i = 0; | |
WHILE @i < count DO | |
EXECUTE stmt; | |
SET @i = @i + 1; | |
END WHILE; | |
END; | |
$$ | |
DELIMITER ; | |
CALL createData(10000, 1000); | |
ALTER TABLE t ADD KEY (x, id), ADD KEY (y, id), ADD KEY (z, id); | |
ANALYZE TABLE t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS x; | |
DROP TABLE IF EXISTS y; | |
DROP TABLE IF EXISTS z; | |
CREATE TABLE x ( | |
id INT NOT NULL AUTO_INCREMENT, | |
v INT NOT NULL, | |
PRIMARY KEY (id) | |
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; | |
CREATE TABLE y ( | |
id INT NOT NULL AUTO_INCREMENT, | |
v INT NOT NULL, | |
PRIMARY KEY (id) | |
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; | |
CREATE TABLE z ( | |
id INT NOT NULL AUTO_INCREMENT, | |
v INT NOT NULL, | |
PRIMARY KEY (id) | |
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; | |
DELIMITER $$ | |
DROP PROCEDURE IF EXISTS createData$$ | |
CREATE PROCEDURE createData(size INT, count INT) | |
BEGIN | |
SET @xs = 'INSERT INTO x(v) VALUES (FLOOR(RAND()*1000))'; | |
SET @ys = 'INSERT INTO y(v) VALUES (FLOOR(RAND()*100000))'; | |
SET @zs = 'INSERT INTO z(v) VALUES (FLOOR(RAND()*10000000))'; | |
SET @i = 1; | |
WHILE @i < size DO | |
SET @xs = CONCAT(@xs, ',(FLOOR(RAND()*1000))'); | |
SET @ys = CONCAT(@ys, ',(FLOOR(RAND()*100000))'); | |
SET @zs = CONCAT(@zs, ',(FLOOR(RAND()*10000000))'); | |
SET @i = @i + 1; | |
END WHILE; | |
PREPARE xstmt FROM @xs; | |
PREPARE ystmt FROM @ys; | |
PREPARE zstmt FROM @zs; | |
SET @i = 0; | |
WHILE @i < count DO | |
EXECUTE xstmt; | |
EXECUTE ystmt; | |
EXECUTE zstmt; | |
SET @i = @i + 1; | |
END WHILE; | |
END; | |
$$ | |
DELIMITER ; | |
CALL createData(10000, 1000); | |
ALTER TABLE x ADD KEY (v, id); | |
ALTER TABLE y ADD KEY (v, id); | |
ALTER TABLE z ADD KEY (v, id); | |
ANALYZE TABLE x; | |
ANALYZE TABLE y; | |
ANALYZE TABLE z; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment