1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| drop table if EXISTS test01; create table test01 (seq_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, `index` INT UNSIGNED NOT NULL); drop table if EXISTS new_test01; create table new_test01 (`index` INT UNSIGNED NOT NULL); insert into new_test01 values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),(10), (11), (12), (13), (14), (15), (16), (17), (18), (19); DROP TRIGGER IF EXISTS `trigger_01`; CREATE TRIGGER `trigger_01` BEFORE INSERT ON `test01` FOR EACH ROW BEGIN DECLARE `seq_id` BIGINT UNSIGNED; DECLARE `now_millis` BIGINT UNSIGNED; DECLARE `our_epoch` BIGINT UNSIGNED DEFAULT 1446307200000; SET `now_millis` = (SELECT UNIX_TIMESTAMP(NOW(3)) * 1000); SET `seq_id` = (SELECT AUTO_INCREMENT FROM information_schema.`TABLES` WHERE table_schema = 'testauto_1' AND table_name = 'test01'); SET NEW.seq_id = (SELECT ((`now_millis` - `our_epoch`) << 23) | (MOD(2, 256) << 15) | MOD (`seq_id`, 32768)); END; DROP PROCEDURE IF EXISTS `pro_01`; create PROCEDURE pro_01(in num int unsigned) BEGIN DECLARE i int DEFAULT 0; REPEAT insert into `testauto_1`.test01 (`index`) ( select `index` from testauto_1.new_test01 ); set i = i+1; UNTIL i>num END REPEAT; END; call pro_01(7000); select * from test01 where `index`=1;
|