Created
April 19, 2016 11:02
-
-
Save tairov/c356db5a5d48c3b9bb335beeaf0d2229 to your computer and use it in GitHub Desktop.
mysql, table generation
This file contains hidden or 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
| CREATE TABLE filler ( | |
| id INT NOT NULL PRIMARY KEY AUTO_INCREMENT | |
| ) ENGINE=Memory; | |
| CREATE TABLE t_left ( | |
| id INT NOT NULL PRIMARY KEY, | |
| value INT NOT NULL, | |
| stuffing VARCHAR(200) NOT NULL | |
| ) ENGINE=InnoDB DEFAULT CHARSET=UTF8; | |
| CREATE TABLE t_right ( | |
| id INT NOT NULL PRIMARY KEY, | |
| value INT NOT NULL, | |
| stuffing VARCHAR(200) NOT NULL | |
| ) ENGINE=InnoDB DEFAULT CHARSET=UTF8; | |
| CREATE INDEX ix_left_value ON t_left (value); | |
| CREATE INDEX ix_right_value ON t_right (value); | |
| DELIMITER $$ | |
| CREATE PROCEDURE prc_filler(cnt INT) | |
| BEGIN | |
| DECLARE _cnt INT; | |
| SET _cnt = 1; | |
| WHILE _cnt <= cnt DO | |
| INSERT | |
| INTO filler | |
| SELECT _cnt; | |
| SET _cnt = _cnt + 1; | |
| END WHILE; | |
| END | |
| $$ | |
| DELIMITER ; | |
| START TRANSACTION; | |
| CALL prc_filler(100000); | |
| COMMIT; | |
| INSERT | |
| INTO t_left | |
| SELECT id, id % 10000, | |
| RPAD(CONCAT('Value ', id, ' '), 200, '*') | |
| FROM filler; | |
| INSERT | |
| INTO t_right | |
| SELECT (l.id - 1) * 10 + f.id, | |
| l.value + 1, | |
| RPAD(CONCAT('Value ', (l.id - 1) * 10 + f.id, ' '), 200, '*') | |
| FROM ( | |
| SELECT id | |
| FROM filler | |
| ORDER BY | |
| id | |
| LIMIT 10 | |
| ) f | |
| CROSS JOIN | |
| t_left l; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment