delimiter // CREATE PROCEDURE init_salary_static() BEGIN DECLARE year INT; DECLARE schid INT; DECLARE stuid INT; SET year = 2000; WHILE year < 2020 DO START TRANSACTION; SET schid = 1; WHILE schid < 100 DO SET stuid = 1; WHILE stuid < 1000 DO insert into salary_static(school_id,student_id,salary,year) values (schid,stuid,floor(rand()*10000),year); SET stuid = stuid + 1; END WHILE; SET schid = schid + 1; END WHILE; SET year = year + 1; COMMIT; END WHILE; END // delimiter ;
call init_salary_static();
覆盖索引的场景
1 2 3 4 5
select * from salary_static whereyear < 2010limit500000,10;
select s.* from salary_static s join (selectidfrom salary_static whereyear < 2010limit500000,10) as tmp on (tmp.id = s.id);