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

2025-09-24 16:34:11

1、1:在数据库A创建DBLINK

create 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_clxsg

is

v_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_clwfx

pro_test_insert_gjx

5、5:单独测试核心表单独测试

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

6、6:同时插入多个核心表数据

同时CLXSG、CLWFX插:

CLXSG平均每秒钟插入26条,每条平均耗时38毫秒,一天可插入量2246400条数据;

CLWFX平均每秒钟插入15条,每条平均耗时66毫秒,一天可插入量1296000条数据;

 根据以上信息,完全符合当前平台数据实时效率

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢