多语言展示
当前在线:871今日阅读:23今日分享:25

获取SQL语句执行时间(精确到毫秒)

获取SQL语句执行时间(精确到毫秒)需求:检测数据库并发情况下SQL插入速度环境:数据库A(提供测试数据库),数据库B(需测试库)测试步骤:1:在数据库A创建DBLINK2:在数据库A创建临时表zxx_excute_time统计时间3:在数据库B创建多个核心业务表结构4:在在数据库A创建统计SQL执行时间的存储过程5:单独测试核心表单独测试6:同时插入多个核心表数据注意:尽量使用核心表测试,因为核心包含lob字段。SQL插入速度受带宽IO影响,如果带宽中存在大量的lob字段,那么可能严重影响到写性能。
方法/步骤
1

1:在数据库A创建DBLINKcreate public database link to_orcl131  connect to sa identified by oracle using  '(DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.13.132)(PORT = 1521))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = orcl)    )  )';如果在正常业务库,最好不要创建DBLINK。防止异常SCN感染。

2

2:在数据库A创建临时表zxx_excute_time统计时间create table zxx_excute_time (table_name varchar2(30),curr_time  date,excute_time number)PARTITION  BY  LIST (table_name)(PARTITION p_1   VALUES ('CLXSG') ,PARTITION p_2   VALUES ('CLWFX') ,PARTITION p_3   VALUES ('GJX') );alter table zxx_excute_time add  start_time date; --添加起始时间字段alter table zxx_excute_time add  end_time date; --添加结束时间字段alter table zxx_excute_time modify  start_time varchar2(50);--修改字段类型alter table zxx_excute_time modify  end_time varchar2(50);alter table zxx_excute_time drop COLUMN  curr_time;--删除不需要的字段创建list分区,原因是插入数据较多,加快查询时间。

3

3:在数据库B创建多个核心业务表结构创建CLXSG 、CLWFX 两个核心业务表(还有很多,但是不是最主要的),索引也和正常业务一样,当然,如果有主键或者唯一约束键,需要删除,对主键和唯一约束键创建普通索引。原因是测试插入的时候,测试源可能没有足够数据,需要重复插入。

4

4:在在数据库A创建统计SQL执行时间的存储过程create or replace procedure pro_test_insert_clxsgisv_string varchar2(100);v_misecond number;v_second  number;v_minute  number;v_starttime TIMESTAMP;v_endtime TIMESTAMP;v_excute_time number;cursor c_source is select clgjid from clxsg ;begin  for r_source in c_source loop    select systimestamp into v_starttime from dual;    insert into sa.clxsg@to_orcl131 select * from clxsg where clgjid=r_source.clgjid;    commit;    select systimestamp into v_endtime from dual; --zxx_excute_time    v_string := to_char(v_endtime-v_starttime);    v_misecond := to_number(SUBSTR(v_string,INSTR(v_string,' ')+10,3));    v_second := to_number(SUBSTR(v_string,INSTR(v_string,' ')+7,2));    v_minute := to_number(SUBSTR(v_string,INSTR(v_string,' ')+4,2));    v_excute_time := v_minute*60*1000+v_second*1000+v_misecond;    insert into sa.zxx_excute_time     values('CLXSGJ',v_excute_time,to_char(v_starttime,'yyyy-mm-dd hh24:mi:ssxff'),to_char(v_endtime,'yyyy-mm-dd hh24:mi:ssxff'));    commit;  end loop ;end;分别创建CLXSG 、CLWFX、 GJX表的插入存储过程。pro_test_insert_clwfxpro_test_insert_gjx

5

5:单独测试核心表单独测试单独执行 pro_test_insert_clxsg存储过程,经过统计发现每秒钟能够插入85条数据。每条数据插入耗时10毫秒。一天可插入7344000条数据。

6

6:同时插入多个核心表数据同时CLXSG、CLWFX插:CLXSG平均每秒钟插入26条,每条平均耗时38毫秒,一天可插入量2246400条数据;CLWFX平均每秒钟插入15条,每条平均耗时66毫秒,一天可插入量1296000条数据; 根据以上信息,完全符合当前平台数据实时效率

推荐信息