DELIMITER $$ set @stmt = 'select userid,username from myuser where userid between ? and ?'; prepare s1 from @stmt; set @s1 = 2; set @s2 = 100; execute s1 using @s1,@s2; deallocate prepare s1; $$ DELIMITER ;
Set profiling=1; Select * From MyTable where DictID = 100601000004; Select DictID from MyTable limit 1,100; Select DictID from MyTable limit 2,100; /*从limit 1,100 到limit 100,100 此处省略重复代码*/ ...... Select DictID from MyTable limit 100,100; SELECT query_id,seq,STATE,10000*DURATION FROM information_schema.profiling INTO OUTFILE 'd:/NormalResults.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '/n';
第二个sql文件 StmtQuery.sql
复制代码 代码如下:
Set profiling=1; Select * From MyTable where DictID = 100601000004; set @stmt = 'Select DictID from MyTable limit ?,?'; prepare s1 from @stmt; set @s = 100; set @s1 = 101; set @s2 = 102; ...... set @s100 =200; execute s1 using @s1,@s; execute s1 using @s2,@s; ...... execute s1 using @s100,@s; SELECT query_id,seq,STATE,10000*DURATION FROM information_schema.profiling INTO OUTFILE 'd:/StmtResults.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '/n';
做几点小说明: 1. Set profiling=1; 执行此语句之后,可以从information_schema.profiling这张表中读出语句执行的详细信息,其实包含不少内容,包括我需要的时间信息,这是张临时表,每新开一个会话都要重新设置profiling属性才能从这张表中读取数据