dblink ora-00600 ora-02072 ora-02063

某汽车集团数据库环境为linux5.8,oracle 11g rac 11.2.0.4。dblink所连接的数据库环境未知,业务系统在通过dblink进行数据更新时在出现如下错误:

ORA-00600: internal error code, arguments: [ORA-00600: internal error code, arguments: [kghstack_underflow_internal_1], [0x1103965E0], [], [], [], [], [], []ORA-02072: distributed database network protocol mismatch], [], [], [], [], [], [], [], [], [], [========= Dump for incident 264681 (ORA 600 [ORA-00600: internal error code, arguments: [kghstack_underflow_internal_1], [0x1103965E0], [], [], [], [], [], []ORA-]) ========

检查相关的错误信息跟踪文件tsp1_ora_23612_i264681.trc有如下信息:

Dump continued from file: /u01/app/oracle/diag/rdbms/tsp/tsp1/trace/tsp1_ora_23612.trcORA-00600: internal error code, arguments: [ORA-00600: internal error code, arguments: [kghstack_underflow_internal_1], [0x1103965E0], [], [], [], [], [], []ORA-02072: distributed database network protocol mismatch], [], [], [], [], [], [], [], [], [], [========= Dump for incident 264681 (ORA 600 [ORA-00600: internal error code, arguments: [kghstack_underflow_internal_1], [0x1103965E0], [], [], [], [], [], []ORA-]) ========

*** 2015-01-18 17:55:15.413dbkedDefDump(): Starting incident default dumps (flags=0x2, level=3, mask=0x0)----- Current SQL Statement for this session (sql_id=43ws7jmatt2yf) -----
MERGE INTO xxx@DBLINK1 R USING (SELECT DISTINCT SUBSTR(A.VIN,LENGTH(VIN)-7,LENGTH(A.VIN)) AS VIN,A.OFFSET_LON,A.OFFSET_LAT,A.UTC,A.ADDRESS,A.MILEAGE, B.ORDERNO,C.STATUSNAME,C.STATUSFLAG FROM aaa@dblink2 A,b B,c C,d@dblink3 D WHERE LENGTH(VIN)>7 AND SUBSTR(A.VIN,LENGTH(VIN)-7,8)= B.CHASSISNUMBER AND B.CARSTATUS = C.STATUSFLAG AND A.VIN =D.LICENSEPLATE AND D.ISLOGOUT = 0 AND SUBSTR(B.ORDERNO,0,2) IN ('31','37','40') AND C.STATUSFLAG < 6 AND A.ADDRESS IS NOT NULL) D ON (R.ROW_ID='ssi'||D.VIN) WHEN MATCHED THEN UPDATE SET LONGITUDE=D.OFFSET_LON,DIMENSION=D.OFFSET_LAT,GPS_TIME = D.UTC,GPS_LOCATION=D.ADDRESS,GPS_LOCATION_SPLIT=D.ADDRESS,STATUS=D.STATUSNAME,GPS_MILEAGE=D.MILEAGE,GAUGE_MILEAGE='',CREATED_BY = 'ssi',LAST_UPD_BY='ssi',ORDER_NO=D.ORDERNO WHEN NOT MATCHED THEN INSERT (ROW_ID,CHASSIS_NO,LONGITUDE,DIMENSION,GPS_TIME,GPS_LOCATION,GPS_LOCATION_SPLIT,STATUS,GPS_MILEAGE,GAUGE_MILEAGE,CREATED_BY,LAST_UPD_BY,ORDER_NO) VALUES('ssi'||D.VIN,D.VIN,D.OFFSET_LON,D.OFFSET_LAT,D.UTC,D.ADDRESS,D.ADDRESS,D.STATUSNAME,D.MILEAGE,'','ssi','ssi',D.ORDERNO)----- PL/SQL Stack -----
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name0x2d3112bc0        33  package body DFCP.DFVL_DBLINK10x2d92769c8         1  anonymous block

----- Call Stack Trace -----
calling              call     entry                argument values in hexlocation             type     point                (? means dubious value)-------------------- -------- -------------------- ----------------------------
skdstdst()+41        call     kgdsdst()            000000000 ? 000000000 ?
                                                   7FFFD889F8E0 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
ksedst1()+103        call     skdstdst()           000000000 ? 000000000 ?
                                                   7FFFD889F8E0 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
ksedst()+39          call     ksedst1()            000000000 ? 000000001 ?
                                                   7FFFD889F8E0 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
dbkedDefDump()+2746  call     ksedst()             000000000 ? 000000001 ?
                                                   7FFFD889F8E0 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
ksedmp()+41          call     dbkedDefDump()       000000003 ? 000000002 ?
                                                   7FFFD889F8E0 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
ksfdmp()+69          call     ksedmp()             000000003 ? 000000002 ?
                                                   7FFFD889F8E0 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
dbgexPhaseII()+1764  call     ksfdmp()             000000003 ? 000000002 ?
                                                   7FFFD889F8E0 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
dbgexProcessError()  call     dbgexPhaseII()       2B585AE35730 ? 2B585AE3E7F0 ?
+2680                                              7FFFD88A8F38 ? 7FFFD889F9B8 ?
                                                   7FFFD88A4460 ? 000000002 ?
dbgeExecuteForError  call     dbgexProcessError()  2B585AE35730 ? 2B585AE3E7F0 ?
()+88                                              000000001 ? 000000000 ?
                                                   7FFFD88A4460 ? 000000002 ?
dbgePostErrorKGE()+  call     dbgeExecuteForError  2B585AE35730 ? 2B585AE3E7F0 ?
2136                          ()                   000000001 ? 000000001 ?
                                                   000000000 ? 000000002 ?
dbkePostKGE_kgsf()+  call     dbgePostErrorKGE()   00C0CC9E0 ? 2B585B260040 ?
71                                                 000000258 ? 000000001 ?
                                                   000000000 ? 000000002 ?
kgesev()+280         call     dbkePostKGE_kgsf()   00C0CC9E0 ? 2B585B260040 ?
                                                   000000258 ? 000000001 ?
                                                   000000000 ? 000000002 ?
ksesec1()+170        call     kgesev()             00C0CC9E0 ? 2B585B260040 ?
                                                   000000258 ? 000000001 ?
                                                   7FFFD88A9AE0 ? 000000002 ?
npierr()+878         call     ksesec1()            00C0CC9E0 ? 000000001 ?
                                                   0000000AC ? 2B585B49DDE0 ?
                                                   7FFFD88A9040 ? 00000000A ?
kpnerr()+240         call     npierr()             2B585B49C570 ? 000000258 ?
                                                   000000000 ? 00000005E ?
                                                   7FFFD88A9040 ? 2B585B49EE90 ?
kpnpst()+276         call     kpnerr()             2B585B49C570 ? 000000258 ?
                                                   000000000 ? 00000005E ?
                                                   7FFFD88ACA68 ? 2B585B49EE90 ?
upirtrc()+1919       call     kpnpst()             7FFFD88ACBE0 ? 000000258 ?
                                                   000000023 ? 000000000 ?
                                                   7FFFD88ACA68 ? 2B585B49EE90 ?
kpurcsc()+98         call     upirtrc()            7FFFD88ACBE0 ? 000000258 ?
                                                   000000023 ? 000000000 ?
                                                   7FFFD88ACA68 ? 2B585B4F4B10 ?
kpuexec()+10790      call     kpurcsc()            7FFFD88ACBE0 ? 000000258 ?
                                                   000000023 ? 000000000 ?
                                                   7FFFD88ACA68 ? 2B585B4F4B10 ?
kpnexe()+1517        call     kpuexec()            7FFFD88ACBE0 ? 000000258 ?
                                                   7FFFD88ACA60 ? 000000000 ?
                                                   7FFFD88ACA68 ? 7FFFD88B07B8 ?
opiexe()+32658       call     kpnexe()             2B585B2AF000 ? 2B585B4F4B10 ?
                                                   2B585B507EB8 ? 2B585B19A950 ?
                                                   000000001 ? 1000000000 ?
opipls()+2164        call     opiexe()             000000004 ? 000000005 ?
                                                   2B585B507EB8 ? 2B585B19A950 ?
                                                   000000001 ? 1000000000 ?
opiodr()+917         call     opipls()             000000066 ? 000000005 ?
                                                   2B585B507EB8 ? 2B585B19A950 ?
                                                   000000001 ? 1000000000 ?
rpidrus()+211        call     opiodr()             000000066 ? 000000007 ?
                                                   7FFFD88B3960 ? 2B585B19A950 ?
                                                   000000001 ? 1000000000 ?
skgmstack()+148      call     rpidrus()            7FFFD88B3338 ? 000000007 ?
                                                   7FFFD88B3960 ? 2B585B19A950 ?
                                                   000000001 ? 1000000000 ?
rpiswu2()+690        call     skgmstack()          7FFFD88B3310 ? 00C0CC600 ?
                                                   00000F618 ? 009698A9C ?
                                                   7FFFD88B3338 ? 1000000000 ?
rpidrv()+1327        call     rpiswu2()            2C511BF60 ? 00000006D ?
                                                   2C511BFE4 ? 000000002 ?
                                                   7FFFD88B3338 ? 1000000000 ?
psddr0()+473         call     rpidrv()             00000000B ? 000000066 ?
                                                   7FFFD88B3960 ? 000000038 ?
                                                   7FFFD88B3338 ? 1000000000 ?
psdnal()+457         call     psddr0()             00000000B ? 000000066 ?
                                                   7FFFD88B3960 ? 000000030 ?
                                                   7FFFD88B3338 ? 1000000000 ?
pevm_EXECC()+314     call     psdnal()             7FFFD88B50E0 ? 7FFFD88B52F0 ?
                                                   7FFFD88B3960 ? 2B585B2A2AE8 ?
                                                   22EC69508 ? 1000000000 ?
pfrinstr_EXECC()+80  call     pevm_EXECC()         2B585B1D5CA0 ? 2B585B409640 ?
                                                   000000020 ? 2B585B2A2AE8 ?
                                                   22EC69508 ? 1000000000 ?
pfrrun_no_tool()+63  call     pfrinstr_EXECC()     2B585B2A7258 ? 21D5E8DB4 ?
                                                   2B585B2A72C8 ? 2B585B2A2AE8 ?
                                                   22EC69508 ? 2B5800000020 ?
pfrrun()+627         call     pfrrun_no_tool()     2B585B2A7258 ? 21D5E8DB4 ?
                                                   2B585B2A72C8 ? 2B585B2A2AE8 ?
                                                   22EC69508 ? 2B5800000020 ?
plsql_run()+649      call     pfrrun()             2B585B2A7258 ? 21D5E8DB4 ?
                                                   2B585B2A72C8 ? 7FFFD88B50E0 ?
                                                   22EC69508 ? 2B5800000020 ?
peicnt()+302         call     plsql_run()          2B585B2A7258 ? 21D5E8DB4 ?
                                                   2B585B2A72C8 ? 7FFFD88B50E0 ?
                                                   22EC69508 ? 2B5800000020 ?
kkxexe()+525         call     peicnt()             7FFFD88B50E0 ? 2B585B2A7258 ?
                                                   2B585B2A72C8 ? 7FFFD88B50E0 ?
                                                   22EC69508 ? 000000000 ?
opiexe()+18001       call     kkxexe()             2B585B2ABF80 ? 2B585B2A7258 ?
                                                   2B585B2A72C8 ? 7FFFD88B50E0 ?
                                                   22EC69508 ? 000000000 ?
kpoal8()+2118        call     opiexe()             000000049 ? 000000003 ?
                                                   2B585B2A72C8 ? 7FFFD88B50E0 ?
                                                   22EC69508 ? 000000000 ?
opiodr()+917         call     kpoal8()             00000005E ? 000000003 ?
                                                   2B585B2A72C8 ? 7FFFD88B50E0 ?
                                                   22EC69508 ? 000000000 ?
ttcpip()+2183        call     opiodr()             00000005E ? 00000001C ?
                                                   7FFFD88B9910 ? 7FFFD88B50E0 ?
                                                   22EC69508 ? 000000000 ?
opitsk()+1710        call     ttcpip()             00C0EA630 ? 00999BA90 ?
                                                   7FFFD88B9910 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
opiino()+969         call     opitsk()             00C0EA638 ? 000000000 ?
                                                   7FFFD88B9910 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
opiodr()+917         call     opiino()             00000003C ? 000000004 ?
                                                   7FFFD88BB108 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
opidrv()+570         call     opiodr()             00000003C ? 000000004 ?
                                                   7FFFD88BB108 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
sou2o()+103          call     opidrv()             00000003C ? 000000004 ?
                                                   7FFFD88BB108 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
opimai_real()+133    call     sou2o()              7FFFD88BB0E0 ? 00000003C ?
                                                   000000004 ? 7FFFD88BB108 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
ssthrdmain()+265     call     opimai_real()        000000002 ? 7FFFD88BB2D0 ?
                                                   000000004 ? 7FFFD88BB108 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
main()+201           call     ssthrdmain()         000000002 ? 7FFFD88BB2D0 ?
                                                   000000001 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
__libc_start_main()  call     main()               000000002 ? 7FFFD88BB478 ?
+244                                               000000001 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?
_start()+41          call     __libc_start_main()  000A29108 ? 000000002 ?
                                                   7FFFD88BB468 ? 000000000 ?
                                                   7FFFD88B9368 ? 7FFFD88B990C ?


--------------------- Binary Stack Dump ---------------------

在执行如下语句时报错:

merge into xxx@dblink1 r

using (select distinct substr(a.vin, length(vin) - 7, length(a.vin)) as vin,

                       a.offset_lon,

                       a.offset_lat,

                       a.utc,

                       a.address,

                       a.mileage,

                       b.orderno,

                       c.statusname,

                       c.statusflag

         from aaaa@dblink2 a,

              b                 b,

              c          c,

              dddd@dblink3    d

        where length(vin) > 7

          and substr(a.vin, length(vin) - 7, 8) = b.chassisnumber

          and b.carstatus = c.statusflag

          and a.vin = d.licenseplate

          and d.islogout = 0

          and substr(b.orderno, 0, 2) in ('31', '37', '40')

          and c.statusflag < 6

          and a.address is not null) d

on (r.row_id = 'ssi' || d.VIN)

when MATCHED then

  update

     set LONGITUDE          = d.offset_lon,

         DIMENSION          = d.offset_lat,

         gps_time           = d.utc,

         GPS_LOCATION       = d.address,

         GPS_LOCATION_SPLIT = d.address,

         STATUS             = d.statusname,

         GPS_MILEAGE        = d.mileage,

         GAUGE_MILEAGE      = '',

         created_by         = 'ssi',

         last_upd_by        = 'ssi',

         order_no           = d.orderno

when NOT MATCHED then

  insert

    (row_id,

     chassis_no,

     LONGITUDE,

     DIMENSION,

     GPS_TIME,

     GPS_LOCATION,

     GPS_LOCATION_SPLIT,

     STATUS,

     GPS_MILEAGE,

     GAUGE_MILEAGE,

     created_by,

     last_upd_by,

     order_no)

  VALUES

    ('ssi' || d.vin,

     d.vin,

     d.offset_lon,

     d.offset_lat,

     d.utc,

     d.address,

     d.address,

     d.statusname,

     d.mileage,

     '',

     'ssi',

     'ssi',

     d.orderno)

后面经询问了解到通过dblink所连接的远端数据库版本要低,而生产数据库升级前的版本为11.2.0.1,通过dblink进行数据更新是没有问题。这种通过dblink,且数据库版本不同的情况下经常遇到这种问题。在这种情况下,一般的处理方法就是通过dblink执行最简单的select,insert,update,delete语句看是否报错,如果没有出现故障,我们就可以将使用merge语法的SQL修改成最简单的select,insert,update,delete语句来达到相同的目的。也就像有多条路到达一个目的地,其中一条路因为某些原因不能通行,就改走另一路。

创建合理的索引避免order by操作提升SQL性能的案例一

某医保系统的查询一年内一个中心所有医疗费登账记录的汇总情况执行3000多秒才能出结果,下面TOP SQL中执行时间最长的SQL语句它的功能是查询一年内一个中心所有医疗费登账记录的汇总情况,执行时间3286秒,则且这条SQL就是我们要找的SQL语句。

Elapsed Time (s)      CPU Time (s)	Executions	Elap per Exec (s)	% Total DB Time	 SQL Id          SQL Module	        SQL Text
3,286	              2,015	        1	        3,286		        18.59	         8aw9tm6w83usm	 JDBC Thin Client	select t1.account_id, ...
622	              316	        17	        36.60	                3.52	         ggrctzgtcg14s	 JDBC Thin Client	select t.pay_type as pay_...
222	              4	                1	        221.64	                1.25	         fvy1hnauapb8s	 JDBC Thin Client	select (select center_name fro...
204	              5	                1	        203.60	                1.15	         fcm5wrxny5b2u	 JDBC Thin Client	select count(1) cs from bs_ho...
198	              125	        31	        6.38	                1.12	         cfuhdxk446uzv	 JDBC Thin Client	select * from ( select a.hosp...
177	              20	        1	        177.00	                1.00	         42zd8jamnw4b4	 PL/SQL Developer	begin dbms_sqltune.execute_tu...
158	              88	        1	        158.21	                0.89	         17t35rynaz40v	 JDBC Thin Client	select u.center_name, x.hospit...
142	              89	        97	        1.46	                0.80	         a7dkwg8uhrwkj	 JDBC Thin Client	select * from ( select a.hosp...
135	              48	        1,417	        0.10	                0.76	         aay99a855zv3u	 JDBC Thin Client	SELECT distinct c.NAME, ...
116	              73	        303	        0.38	                0.66	         31tf0tfn8nv6f	 JDBC Thin Client	select a.pay_batch_no, a.pay_b...

其SQL如下所示:

select  t1.account_id,
       t1.hospital_id,
       (select hosp_level
          from bs_hospital a
         where t1.hospital_id = a.hospital_id
           and a.valid_flag = '1') as hosp_level,
       t1.serial_no,
       t1.icd,
       (select t4.disease
          from bs_disease t4
         where t1.icd = t4.icd(+)
           and t4.center_id = nvl(center.catalog_center, center.center_id)) as disease,
       t1.biz_type,
       t1.treatment_type,
       t1.disease_type,
       t1.reimburse_flag,
       t1.corp_id,
       t1.corp_type_code,
       t2.corp_name,
       t1.indi_id,
       t1.pers_type,
       t2.center_id,
       t2.district_code,
       decode(t2.center_id, t2.district_code, 0, 1) as out_type,
       t1.biz_flag,
       t1.biz_flag_old,
       t2.name,
       t2.idcard,
       t2.sex,
       t2.begin_date,
       t2.end_date,
       t1.fin_date,
       t2.reg_date,
       t1.disease_fee,
       t1.violate_flag,
       t1.patient_id,
       t1.in_days,
       decode(t1.allow_treat, '0', 0, 1) As allow_treat,
       Decode(T1.Treatment_Type_Last,
              '',
              T1.Treatment_Type,
              Decode(T1.Treatment_Type,
                     '120',
                     '120',
                     Decode(T1.Biz_Type,
                            '41',
                            '扣减已记帐金额',
                            '42',
                            '扣减已记帐金额',
                            T1.Treatment_Type_Last))) As Treatment_Type_Last,
       t1.violate,
       t1.pay_money,
       t1.pay_fund,
       t1.audit_money,
       '0' as finish_flag,
       t1.MONTH_DECL_SN,
       t1.deal_flag,
       t1.audit_deal_flag,
       t1.declare_icd_guide,
       t1.declare_audit_fee,
       t1.declare_audit_fee_cl,
       t1.first_icd_guide,
       t1.first_audit_fee,
       t1.first_audit_fee_cl,
       t1.second_icd_guide,
       t1.second_audit_fee,
       t1.second_audit_fee_cl,
       t1.PAY_otherfee,
       t1.PAY_FUND003,
       t1.PAY_FUND001,
       t1.PAY_FUND201,
       t1.PAY_FUND301,
       t1.PAY_FUND999,
       t1.PAY_FUND996,
       t1.PAY_begin
  from (select a.account_id,
               a.hospital_id,
               a.serial_no,
               a.center_id,
               a.icd,
               a.biz_type,
               a.treatment_type,
               a.reimburse_flag,
               a.corp_id,
               a.corp_type_code,
               a.indi_id,
               a.pers_type,
               a.biz_flag,
               a.biz_flag_old,
               a.fin_date,
               a.violate_flag,
               (select mbf.disease_type
                  from mt_biz_fin mbf
                 where mbf.valid_flag = '1'
                   and mbf.hospital_id = a.hospital_id
                   and mbf.serial_no = a.serial_no) disease_type,
               (Select aa1.allow_treat
                  From pm_account_scene aa1
                 where aa1.hospital_id = a.hospital_id
                   and aa1.serial_no = a.serial_no
                   and aa1.valid_flag = '1') as allow_treat,
               (select distinct bb1.patient_id
                  from mt_biz_fin bb1
                 where bb1.hospital_id = a.hospital_id
                   and bb1.serial_no = a.serial_no
                   and bb1.valid_flag = '1') as patient_id,
               (select distinct bb1.in_days
                  from mt_biz_fin bb1
                 where bb1.hospital_id = a.hospital_id
                   and bb1.serial_no = a.serial_no
                   and bb1.valid_flag = '1') as in_days,
               (select Max(audit_treat_value)
                  from pm_treat_audit aa
                 where aa.account_id = a.account_id
                   and aa.audit_staff_id = '2208'
                   and aa.audit_phase = '1'
                   and aa.valid_flag = '1') as treatment_type_last,
               a.violate,
               nvl((SELECT sum(pm_account_fund.pay_money)
                     FROM pm_account_fund
                    WHERE a.account_id = pm_account_fund.account_id
                      AND pm_account_fund.valid_flag = '1'),
                   0) as pay_money,
               nvl((SELECT sum(pm_account_fund.pay_money)
                     FROM pm_account_fund
                    WHERE a.account_id = pm_account_fund.account_id
                      AND pm_account_fund.valid_flag = '1'
                      AND pm_account_fund.fund_id not in
                          ('003', '999', '996', '997')),
                   0) as pay_fund,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '003'),
                   0) AS PAY_FUND003,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID in ('801', '001')),
                   0) AS PAY_FUND001,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '201'),
                   0) AS PAY_FUND201,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '301'),
                   0) AS PAY_FUND301,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '999'),
                   0) AS PAY_FUND999,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '996'),
                   0) AS PAY_FUND996,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID not in
                          ('801', '001', '003', '201', '999')),
                   0) AS PAY_otherfee,
               NVL((SELECT SUM(mprf.real_pay)
                     FROM mt_pay_record_fin mprf
                    WHERE A.hospital_id = mprf.hospital_id
                      AND A.serial_no = mprf.serial_no
                      AND mprf.policy_item_code = 'S01'),
                   0) AS PAY_begin,
               (select nvl(sum(b.AUDIT_MONEY), 0)
                  from pm_fee_audit b
                 where a.account_id = b.account_id
                   and b.audit_staff_id = '2208'
                   and b.AUDIT_TYPE = '1'
                   and b.AUDIT_PHASE = '1'
                   and b.valid_flag = '1') as audit_money,
               a.MONTH_DECL_SN,
               a.deal_flag,
               decode(nvl(a.disease_fee, 0),
                      0,
                      nvl((select nvl(max(ration), 0)
                            from pm_ration pr
                           where pr.center_id = a.center_id
                             and pr.hospital_id = a.hospital_id
                             and pr.treatment_type = a.treatment_type
                             and pr.year = to_char(a.fin_date, 'yyyy')
                             and (decode(a.pers_type,
                                         '21',
                                         '21',
                                         '22',
                                         '21',
                                         '23',
                                         '21',
                                         '24',
                                         '21',
                                         '41',
                                         '21',
                                         '3',
                                         '12',
                                         '4',
                                         '12',
                                         '5',
                                         '12',
                                         '7',
                                         '12',
                                         '2') = pr.insr_no or
                                 pr.insr_no = '0')
                             and rownum < 2
                             and pr.biz_flag = a.biz_flag),
                          0),
                      a.disease_fee) as disease_fee,
               a.audit_flag as audit_deal_flag,
               a.declare_icd_guide as declare_icd_guide,
               a.declare_audit_fee as declare_audit_fee,
               a.declare_audit_fee_cl as declare_audit_fee_cl,
               a.first_icd_guide as first_icd_guide,
               a.first_audit_fee as first_audit_fee,
               a.first_audit_fee_cl as first_audit_fee_cl,
               decode(a.biz_type,
                      '12',
                      decode(a.biz_flag_old, 5, '4304001', a.second_icd_guide),
                      a.second_icd_guide) second_icd_guide,
               a.second_audit_fee as second_audit_fee,
               a.second_audit_fee_cl as second_audit_fee_cl
          from pm_account_biz a
         where 1 = 1
           and ('0' = 'A' or a.reimburse_flag ='0')
           and ('00' = '00' or a.biz_type ='00')
           and a.center_id in ('430722')
           and (a.fin_date between to_date('2014-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
               to_date('2014-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'))
           and a.valid_flag = '1'
           and a.deal_flag in ('0', '1', '2')
           and (nvl(a.staff1_finish_flag, '0') ='0' and
               nvl(a.staff2_finish_flag, '0') = '0' and
               nvl(a.staff3_finish_flag, '0') = '0')
         group by a.account_id,
                  a.hospital_id,
                  a.serial_no,
                  a.center_id,
                  a.icd,
                  a.biz_type,
                  a.treatment_type,
                  a.reimburse_flag,
                  a.corp_id,
                  a.corp_type_code,
                  a.indi_id,
                  a.pers_type,
                  a.biz_flag,
                  a.biz_flag_old,
                  a.disease_fee,
                  a.fin_date,
                  a.violate_flag,
                  a.violate,
                  a.MONTH_DECL_SN,
                  a.deal_flag,
                  a.audit_flag,
                  a.declare_icd_guide,
                  a.declare_audit_fee,
                  a.declare_audit_fee_cl,
                  a.first_icd_guide,
                  a.first_audit_fee,
                  a.first_audit_fee_cl,
                  a.second_icd_guide,
                  a.second_audit_fee,
                  a.second_audit_fee_cl) t1,
       mt_biz_fin t2,
       bs_center center
 where t1.serial_no = t2.serial_no
   AND t1.hospital_id = t2.hospital_id
   AND t2.valid_flag = '1'
   and t1.center_id = center.center_id(+)
 order by t1.hospital_id, t1.serial_no

上面SQL的执行计划如下:

----------------------------------------------------------------------------------------------------------------------------
| Id  | Order | Operation                         | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------------------------------------
|   0 |    67 | SELECT STATEMENT                  |                                |       |       | 56871 (100)|          |
|   1 |     2 |  TABLE ACCESS BY INDEX ROWID      | BS_HOSPITAL                    |     1 |    16 |     1   (0)| 00:00:01 |
|   2 |     1 |   INDEX UNIQUE SCAN               | PK_BS_HOSPITAL                 |     1 |       |     1   (0)| 00:00:01 |
|   3 |     4 |  TABLE ACCESS BY INDEX ROWID      | BS_DISEASE                     |     1 |    33 |     1   (0)| 00:00:01 |
|   4 |     3 |   INDEX RANGE SCAN                | INX_BS_DISEASE_01              |     1 |       |     1   (0)| 00:00:01 |
|   5 |     6 |  TABLE ACCESS BY INDEX ROWID      | MT_BIZ_FIN                     |     1 |    26 |     1   (0)| 00:00:01 |
|   6 |     5 |   INDEX RANGE SCAN                | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
|   7 |    10 |  SORT AGGREGATE                   |                                |     1 |    33 |            |          |
|   8 |     9 |   COUNT STOPKEY                   |                                |       |       |            |          |
|   9 |     8 |    TABLE ACCESS BY INDEX ROWID    | PM_RATION                      |     1 |    33 |     1   (0)| 00:00:01 |
|  10 |     7 |     INDEX RANGE SCAN              | IDX_PM_RATION_1                |     1 |       |     1   (0)| 00:00:01 |
|  11 |    13 |  HASH UNIQUE                      |                                |     1 |    26 |     2  (50)| 00:00:01 |
|  12 |    12 |   TABLE ACCESS BY INDEX ROWID     | MT_BIZ_FIN                     |     1 |    26 |     1   (0)| 00:00:01 |
|  13 |    11 |    INDEX RANGE SCAN               | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
|  14 |    16 |  HASH UNIQUE                      |                                |     1 |    26 |     2  (50)| 00:00:01 |
|  15 |    15 |   TABLE ACCESS BY INDEX ROWID     | MT_BIZ_FIN                     |     1 |    26 |     1   (0)| 00:00:01 |
|  16 |    14 |    INDEX RANGE SCAN               | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
|  17 |    18 |  TABLE ACCESS BY INDEX ROWID      | PM_ACCOUNT_SCENE               |     1 |    28 |     1   (0)| 00:00:01 |
|  18 |    17 |   INDEX RANGE SCAN                | IDX_PM_ACCOUNT_SCENE_1         |     1 |       |     1   (0)| 00:00:01 |
|  19 |    21 |  SORT AGGREGATE                   |                                |     1 |    37 |            |          |
|  20 |    20 |   TABLE ACCESS BY INDEX ROWID     | PM_TREAT_AUDIT                 |     1 |    37 |     1   (0)| 00:00:01 |
|  21 |    19 |    INDEX RANGE SCAN               | PK_PM_TREAT_AUDIT              |     1 |       |     1   (0)| 00:00:01 |
|  22 |    24 |  SORT AGGREGATE                   |                                |     1 |    12 |            |          |
|  23 |    23 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    12 |     1   (0)| 00:00:01 |
|  24 |    22 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  25 |    27 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  26 |    26 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  27 |    25 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  28 |    30 |  SORT AGGREGATE                   |                                |     1 |    21 |            |          |
|  29 |    29 |   TABLE ACCESS BY INDEX ROWID     | PM_FEE_AUDIT                   |     1 |    21 |     1   (0)| 00:00:01 |
|  30 |    28 |    INDEX RANGE SCAN               | PK_PM_FEE_AUDIT                |     1 |       |     1   (0)| 00:00:01 |
|  31 |    33 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  32 |    32 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  33 |    31 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  34 |    36 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  35 |    35 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  36 |    34 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  37 |    40 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  38 |    39 |   INLIST ITERATOR                 |                                |       |       |            |          |
|  39 |    38 |    TABLE ACCESS BY INDEX ROWID    | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  40 |    37 |     INDEX RANGE SCAN              | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  41 |    43 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  42 |    42 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  43 |    41 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  44 |    46 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  45 |    45 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  46 |    44 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  47 |    49 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  48 |    48 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  49 |    47 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  50 |    52 |  SORT AGGREGATE                   |                                |     1 |    16 |            |          |
|  51 |    51 |   TABLE ACCESS BY INDEX ROWID     | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|  52 |    50 |    INDEX RANGE SCAN               | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  53 |    55 |  SORT AGGREGATE                   |                                |     1 |    39 |            |          |
|  54 |    54 |   TABLE ACCESS BY INDEX ROWID     | MT_PAY_RECORD_FIN              |     1 |    39 |     1   (0)| 00:00:01 |
|  55 |    53 |    INDEX RANGE SCAN               | IDX_MT_PAY_RECORD_FIN_2        |     1 |       |     1   (0)| 00:00:01 |
|  56 |    66 |  FILTER                           |                                |       |       |            |          |
|  57 |    65 |   SORT GROUP BY                   |                                |     1 |   309 | 56871   (1)| 00:11:23 |
|  58 |    64 |    TABLE ACCESS BY INDEX ROWID    | MT_BIZ_FIN                     |     1 |   119 |     1   (0)| 00:00:01 |
|  59 |    63 |     NESTED LOOPS                  |                                |     1 |   309 | 56869   (1)| 00:11:23 |
|  60 |    61 |      MERGE JOIN OUTER             |                                |     1 |   190 | 56868   (1)| 00:11:23 |
|  61 |    57 |       TABLE ACCESS BY INDEX ROWID | PM_ACCOUNT_BIZ                 |     1 |   164 | 56867   (1)| 00:11:23 |
|  62 |    56 |        INDEX RANGE SCAN           | IDX_PM_ACCOUNT_BIZ_SERIAL_DATE |   285K|       |   209   (1)| 00:00:03 |
|  63 |    60 |       BUFFER SORT                 |                                |     1 |    26 |     1   (0)| 00:00:01 |
|  64 |    59 |        TABLE ACCESS BY INDEX ROWID| BS_CENTER                      |     1 |    26 |     1   (0)| 00:00:01 |
|  65 |    58 |         INDEX UNIQUE SCAN         | PK_BS_CENTER                   |     1 |       |     1   (0)| 00:00:01 |
|  66 |    62 |      INDEX RANGE SCAN             | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------------------------------

从其执行计划中可以看到最消耗成本的操作就是对IDX_PM_ACCOUNT_BIZ_SERIAL_DATE索引执行索引范围扫描返回285K条记录再回表查询记录的成本是56867,而整个SQL语句的成本是56871。再与BS_CENTER表执行排序合并连接,再与MT_BIZ_FIN执行嵌套循环连接,再执行group by操作。因为表BS_CENTER表只有10几条记录,且表中的center_id是主键,表PM_ACCOUNT_BIZ中center_id与其它列存在复合索引,理想的执行计划应该是先访问表BS_CENTER再与PM_ACCOUNT_BIZ表执行嵌套循环连接,再与MT_BIZ_FIN连接。而且上述SQL中的group by子句是可以去掉了,这里group by真正的作用只起到了去掉重复记录的作用,而PM_ACCOUNT_BIZ表的主键是account_id,在查询列中,所以可以去掉这个group by 子句。

上面的SQL语句简化如下形式:

select ...省略
from pm_account_biz a
         where 1 = 1
           and ('0' = 'A' or a.reimburse_flag ='0')
           and ('00' = '00' or a.biz_type ='00')
           and a.center_id in ('430722')
           and (a.fin_date between to_date('2014-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
               to_date('2014-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'))
           and a.valid_flag = '1'
           and a.deal_flag in ('0', '1', '2')
           and (nvl(a.staff1_finish_flag, '0') ='0' and
               nvl(a.staff2_finish_flag, '0') = '0' and
               nvl(a.staff3_finish_flag, '0') = '0')
         group by a.account_id,
                  a.hospital_id,
                  a.serial_no,
                  a.center_id,
                  a.icd,
                  a.biz_type,
                  a.treatment_type,
                  a.reimburse_flag,
                  a.corp_id,
                  a.corp_type_code,
                  a.indi_id,
                  a.pers_type,
                  a.biz_flag,
                  a.biz_flag_old,
                  a.disease_fee,
                  a.fin_date,
                  a.violate_flag,
                  a.violate,
                  a.MONTH_DECL_SN,
                  a.deal_flag,
                  a.audit_flag,
                  a.declare_icd_guide,
                  a.declare_audit_fee,
                  a.declare_audit_fee_cl,
                  a.first_icd_guide,
                  a.first_audit_fee,
                  a.first_audit_fee_cl,
                  a.second_icd_guide,
                  a.second_audit_fee,
                  a.second_audit_fee_cl) t1,
       mt_biz_fin t2,
       bs_center center
 where t1.serial_no = t2.serial_no
   AND t1.hospital_id = t2.hospital_id
   AND t2.valid_flag = '1'
   and t1.center_id = center.center_id(+)
 order by t1.hospital_id, t1.serial_no

可以看到表mt_biz_fin,与bs_center可以合并到内嵌视图t1中直接与表pm_account_biz进行表连接,前面已经说过了可以去掉group by子句,进行改写后的SQL如下:

select  t1.account_id,
       t1.hospital_id,
       (select hosp_level
          from bs_hospital a
         where t1.hospital_id = a.hospital_id
           and a.valid_flag = '1') as hosp_level,
       t1.serial_no,
       t1.icd,
       (select t4.disease
          from bs_disease t4
         where t1.icd = t4.icd(+)
           and t4.center_id = nvl(t1.catalog_center, t1.center_id)) as disease,
       t1.biz_type,
       t1.treatment_type,
       t1.disease_type,
       t1.reimburse_flag,
       t1.corp_id,
       t1.corp_type_code,
       t1.corp_name,
       t1.indi_id,
       t1.pers_type,
       t1.center_id,
       t1.district_code,
       t1.out_type,
       t1.biz_flag,
       t1.biz_flag_old,
       t1.name,
       t1.idcard,
       t1.sex,
       t1.begin_date,
       t1.end_date,
       t1.fin_date,
       t1.reg_date,
       t1.disease_fee,
       t1.violate_flag,
       t1.patient_id,
       t1.in_days,
       decode(t1.allow_treat, '0', 0, 1) As allow_treat,
       Decode(T1.Treatment_Type_Last,
              '',
              T1.Treatment_Type,
              Decode(T1.Treatment_Type,
                     '120',
                     '120',
                     Decode(T1.Biz_Type,
                            '41',
                            '扣减已记帐金额',
                            '42',
                            '扣减已记帐金额',
                            T1.Treatment_Type_Last))) As Treatment_Type_Last,
       t1.violate,
       t1.pay_money,
       t1.pay_fund,
       t1.audit_money,
       '0' as finish_flag,
       t1.MONTH_DECL_SN,
       t1.deal_flag,
       t1.audit_deal_flag,
       t1.declare_icd_guide,
       t1.declare_audit_fee,
       t1.declare_audit_fee_cl,
       t1.first_icd_guide,
       t1.first_audit_fee,
       t1.first_audit_fee_cl,
       t1.second_icd_guide,
       t1.second_audit_fee,
       t1.second_audit_fee_cl,
       t1.PAY_otherfee,
       t1.PAY_FUND003,
       t1.PAY_FUND001,
       t1.PAY_FUND201,
       t1.PAY_FUND301,
       t1.PAY_FUND999,
       t1.PAY_FUND996,
       t1.PAY_begin
  from (select a.account_id,
               a.hospital_id,
               a.serial_no,
               a.center_id,
               a.icd,
               a.biz_type,
               a.treatment_type,
               a.reimburse_flag,
               a.corp_id,
               a.corp_type_code,
               t2.corp_name,
               a.indi_id,
               a.pers_type,
               center.catalog_center,
               t2.district_code,
               decode(t2.center_id, t2.district_code, 0, 1) as out_type,
               a.biz_flag,
               a.biz_flag_old,
               t2.name,
               t2.idcard,
               t2.sex,
               t2.begin_date,
               t2.end_date,
               a.fin_date,
               t2.reg_date,
               a.violate_flag,
               (select mbf.disease_type
                  from mt_biz_fin mbf
                 where mbf.valid_flag = '1'
                   and mbf.hospital_id = a.hospital_id
                   and mbf.serial_no = a.serial_no) disease_type,
               (Select aa1.allow_treat
                  From pm_account_scene aa1
                 where aa1.hospital_id = a.hospital_id
                   and aa1.serial_no = a.serial_no
                   and aa1.valid_flag = '1') as allow_treat,
               (select distinct bb1.patient_id
                  from mt_biz_fin bb1
                 where bb1.hospital_id = a.hospital_id
                   and bb1.serial_no = a.serial_no
                   and bb1.valid_flag = '1') as patient_id,
               (select distinct bb1.in_days
                  from mt_biz_fin bb1
                 where bb1.hospital_id = a.hospital_id
                   and bb1.serial_no = a.serial_no
                   and bb1.valid_flag = '1') as in_days,
               (select Max(audit_treat_value)
                  from pm_treat_audit aa
                 where aa.account_id = a.account_id
                   and aa.audit_staff_id = '2208'
                   and aa.audit_phase = '1'
                   and aa.valid_flag = '1') as treatment_type_last,
               a.violate,
               nvl((SELECT sum(pm_account_fund.pay_money)
                     FROM pm_account_fund
                    WHERE a.account_id = pm_account_fund.account_id
                      AND pm_account_fund.valid_flag = '1'),
                   0) as pay_money,
               nvl((SELECT sum(pm_account_fund.pay_money)
                     FROM pm_account_fund
                    WHERE a.account_id = pm_account_fund.account_id
                      AND pm_account_fund.valid_flag = '1'
                      AND pm_account_fund.fund_id not in
                          ('003', '999', '996', '997')),
                   0) as pay_fund,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '003'),
                   0) AS PAY_FUND003,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID in ('801', '001')),
                   0) AS PAY_FUND001,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '201'),
                   0) AS PAY_FUND201,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '301'),
                   0) AS PAY_FUND301,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '999'),
                   0) AS PAY_FUND999,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID = '996'),
                   0) AS PAY_FUND996,
               NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
                     FROM PM_ACCOUNT_FUND
                    WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
                      AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
                      AND PM_ACCOUNT_FUND.FUND_ID not in
                          ('801', '001', '003', '201', '999')),
                   0) AS PAY_otherfee,
               NVL((SELECT SUM(mprf.real_pay)
                     FROM mt_pay_record_fin mprf
                    WHERE A.hospital_id = mprf.hospital_id
                      AND A.serial_no = mprf.serial_no
                      AND mprf.policy_item_code = 'S01'),
                   0) AS PAY_begin,
               (select nvl(sum(b.AUDIT_MONEY), 0)
                  from pm_fee_audit b
                 where a.account_id = b.account_id
                   and b.audit_staff_id = '2208'
                   and b.AUDIT_TYPE = '1'
                   and b.AUDIT_PHASE = '1'
                   and b.valid_flag = '1') as audit_money,
               a.MONTH_DECL_SN,
               a.deal_flag,
               decode(nvl(a.disease_fee, 0),
                      0,
                      nvl((select nvl(max(ration), 0)
                            from pm_ration pr
                           where pr.center_id = a.center_id
                             and pr.hospital_id = a.hospital_id
                             and pr.treatment_type = a.treatment_type
                             and pr.year = to_char(a.fin_date, 'yyyy')
                             and (decode(a.pers_type,
                                         '21',
                                         '21',
                                         '22',
                                         '21',
                                         '23',
                                         '21',
                                         '24',
                                         '21',
                                         '41',
                                         '21',
                                         '3',
                                         '12',
                                         '4',
                                         '12',
                                         '5',
                                         '12',
                                         '7',
                                         '12',
                                         '2') = pr.insr_no or
                                 pr.insr_no = '0')
                             and rownum < 2
                             and pr.biz_flag = a.biz_flag),
                          0),
                      a.disease_fee) as disease_fee,
               a.audit_flag as audit_deal_flag,
               a.declare_icd_guide as declare_icd_guide,
               a.declare_audit_fee as declare_audit_fee,
               a.declare_audit_fee_cl as declare_audit_fee_cl,
               a.first_icd_guide as first_icd_guide,
               a.first_audit_fee as first_audit_fee,
               a.first_audit_fee_cl as first_audit_fee_cl,
               decode(a.biz_type,
                      '12',
                      decode(a.biz_flag_old, 5, '4304001', a.second_icd_guide),
                      a.second_icd_guide) second_icd_guide,
               a.second_audit_fee as second_audit_fee,
               a.second_audit_fee_cl as second_audit_fee_cl
          from bs_center center,pm_account_biz a,mt_biz_fin t2
         where 1 = 1
           and ('0' = 'A' or a.reimburse_flag ='0')
           and ('00' = '00' or a.biz_type ='00')
           and a.center_id in ('430701')
           and (a.fin_date between to_date('2014-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
               to_date('2014-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'))
           and a.valid_flag = '1'
           and a.deal_flag in ('0', '1', '2')
           and (nvl(a.staff1_finish_flag, '0') ='0' and
               nvl(a.staff2_finish_flag, '0') = '0' and
               nvl(a.staff3_finish_flag, '0') = '0')
           and a.serial_no = t2.serial_no
           AND a.hospital_id = t2.hospital_id
           AND t2.valid_flag = '1'
           and a.center_id = center.center_id(+)
           and center.center_id in ('430701')          
           order by a.hospital_id, a.serial_no
           )t1

来测试执行一次,但是执行了10分钟还是没有执行完,其执行计划如下:

------------------------------------------------------------------------------------------------------------------
| Id  | Operation                       | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |                                |     3 |   855 | 24453   (1)| 00:04:54 |
|*  1 |  TABLE ACCESS BY INDEX ROWID    | BS_HOSPITAL                    |     1 |    16 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN             | PK_BS_HOSPITAL                 |     1 |       |     1   (0)| 00:00:01 |
|   3 |  TABLE ACCESS BY INDEX ROWID    | BS_DISEASE                     |     1 |    33 |     1   (0)| 00:00:01 |
|*  4 |   INDEX RANGE SCAN              | INX_BS_DISEASE_01              |     1 |       |     1   (0)| 00:00:01 |
|*  5 |  TABLE ACCESS BY INDEX ROWID    | MT_BIZ_FIN                     |     1 |    26 |     1   (0)| 00:00:01 |
|*  6 |   INDEX RANGE SCAN              | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
|   7 |  SORT AGGREGATE                 |                                |     1 |    34 |            |          |
|*  8 |   COUNT STOPKEY                 |                                |       |       |            |          |
|*  9 |    TABLE ACCESS BY INDEX ROWID  | PM_RATION                      |     1 |    34 |     1   (0)| 00:00:01 |
|* 10 |     INDEX RANGE SCAN            | IDX_PM_RATION_1                |     1 |       |     1   (0)| 00:00:01 |
|  11 |  HASH UNIQUE                    |                                |     1 |    26 |     2  (50)| 00:00:01 |
|* 12 |   TABLE ACCESS BY INDEX ROWID   | MT_BIZ_FIN                     |     1 |    26 |     1   (0)| 00:00:01 |
|* 13 |    INDEX RANGE SCAN             | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
|  14 |  HASH UNIQUE                    |                                |     1 |    26 |     2  (50)| 00:00:01 |
|* 15 |   TABLE ACCESS BY INDEX ROWID   | MT_BIZ_FIN                     |     1 |    26 |     1   (0)| 00:00:01 |
|* 16 |    INDEX RANGE SCAN             | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
|* 17 |  TABLE ACCESS BY INDEX ROWID    | PM_ACCOUNT_SCENE               |     1 |    28 |     1   (0)| 00:00:01 |
|* 18 |   INDEX RANGE SCAN              | IDX_PM_ACCOUNT_SCENE_1         |     1 |       |     1   (0)| 00:00:01 |
|  19 |  SORT AGGREGATE                 |                                |     1 |    37 |            |          |
|* 20 |   TABLE ACCESS BY INDEX ROWID   | PM_TREAT_AUDIT                 |     1 |    37 |     1   (0)| 00:00:01 |
|* 21 |    INDEX RANGE SCAN             | PK_PM_TREAT_AUDIT              |     1 |       |     1   (0)| 00:00:01 |
|  22 |    SORT AGGREGATE               |                                |     1 |    37 |            |          |
|* 23 |     TABLE ACCESS BY INDEX ROWID | PM_TREAT_AUDIT                 |     1 |    37 |     1   (0)| 00:00:01 |
|* 24 |      INDEX RANGE SCAN           | PK_PM_TREAT_AUDIT              |     1 |       |     1   (0)| 00:00:01 |
|  25 |  SORT AGGREGATE                 |                                |     1 |    12 |            |          |
|* 26 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    12 |     1   (0)| 00:00:01 |
|* 27 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND1            |     1 |       |     1   (0)| 00:00:01 |
|  28 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|* 29 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 30 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  31 |  SORT AGGREGATE                 |                                |     1 |    21 |            |          |
|* 32 |   TABLE ACCESS BY INDEX ROWID   | PM_FEE_AUDIT                   |     1 |    21 |     1   (0)| 00:00:01 |
|* 33 |    INDEX RANGE SCAN             | PK_PM_FEE_AUDIT                |     1 |       |     1   (0)| 00:00:01 |
|  34 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|* 35 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 36 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  37 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|* 38 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 39 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  40 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|  41 |   INLIST ITERATOR               |                                |       |       |            |          |
|* 42 |    TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 43 |     INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  44 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|* 45 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 46 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  47 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|* 48 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 49 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  50 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|* 51 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 52 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  53 |  SORT AGGREGATE                 |                                |     1 |    16 |            |          |
|* 54 |   TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_FUND                |     1 |    16 |     1   (0)| 00:00:01 |
|* 55 |    INDEX RANGE SCAN             | PK_PM_ACCOUNT_FUND             |     1 |       |     1   (0)| 00:00:01 |
|  56 |  SORT AGGREGATE                 |                                |     1 |    39 |            |          |
|  57 |   TABLE ACCESS BY INDEX ROWID   | MT_PAY_RECORD_FIN              |     1 |    39 |     1   (0)| 00:00:01 |
|* 58 |    INDEX RANGE SCAN             | IDX_MT_PAY_RECORD_FIN_2        |     1 |       |     1   (0)| 00:00:01 |
|  59 |  SORT ORDER BY                  |                                |     3 |   855 | 24453   (1)| 00:04:54 |
|* 60 |   TABLE ACCESS BY INDEX ROWID   | MT_BIZ_FIN                     |     1 |   107 |     1   (0)| 00:00:01 |
|  61 |    NESTED LOOPS                 |                                |     3 |   855 | 24452   (1)| 00:04:54 |
|  62 |     NESTED LOOPS                |                                |     3 |   534 | 24451   (1)| 00:04:54 |
|  63 |      TABLE ACCESS BY INDEX ROWID| BS_CENTER                      |     1 |    14 |     1   (0)| 00:00:01 |
|* 64 |       INDEX UNIQUE SCAN         | PK_BS_CENTER                   |     1 |       |     1   (0)| 00:00:01 |
|* 65 |      TABLE ACCESS BY INDEX ROWID| PM_ACCOUNT_BIZ                 |     3 |   492 | 24450   (1)| 00:04:54 |
|* 66 |       INDEX RANGE SCAN          | IDX_PM_ACCOUNT_BIZ_SERIAL_DATE |   118K|       |    29   (7)| 00:00:01 |
|* 67 |     INDEX RANGE SCAN            | PK_MT_BIZ_FIN                  |     1 |       |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------------

其执行计划中现在是选访问表BS_CENTER后再与PM_ACCOUNT_BIZ执行嵌套循环连接,与我们设想的一样,这里慢的主要原因是因为要对表连接之后的记录执行order by a.hospital_id, a.serial_no操作。PM_ACCOUNT_BIZ表的查询条件中有and a.center_id in (‘430701’) and (a.fin_date between to_date(‘2014-01-01 00:00:00’, ‘yyyy-mm-dd hh24:mi:ss’) and
to_date(‘2014-12-31 23:59:59’, ‘yyyy-mm-dd hh24:mi:ss’)),而在CENTER_ID与FIN_DATE列上有存在复合索引。索引信息如下所示,在创建索引时,索引列的记录默认是按升序来存储的,而查询中要进行升序操作的列就是hospital_id,serial_no,而这两列已经存在复合索引IDX_PM_ACCOUNT_BIZ_SERIAL_NO中,而该索引中首列是CENTER_ID,我们只要把fin_date列加入这个复合索引中就可以让CBO在执行查询时使用该索引且能避免排序操作,而在IDX_PM_ACCOUNT_BIZ_SERIAL_DATE索引的有两列分别是CENTER_ID与FIN_DATE所以可以将这两个索引合并成一个新的索引(create index idx_pm_account_biz_center_id on pm_account_biz(center_id,hospital_id,serial_no,fin_date),并删除原先的这两个索引。

SQL> select a.index_name,a.column_name,a.column_position
  2   from user_ind_columns a  where a.table_name='PM_ACCOUNT_BIZ' and a.index_name='IDX_PM_ACCOUNT_BIZ_SERIAL_NO';
 
INDEX_NAME                     COLUMN_NAME                                                                      COLUMN_POSITION
------------------------------ -------------------------------------------------------------------------------- ---------------
IDX_PM_ACCOUNT_BIZ_SERIAL_NO   CENTER_ID                                                                                      1
IDX_PM_ACCOUNT_BIZ_SERIAL_NO   HOSPITAL_ID                                                                                    2
IDX_PM_ACCOUNT_BIZ_SERIAL_NO   SERIAL_NO                                                                                      3
SQL>  select a.index_name,a.column_name,a.column_position
  2   from user_ind_columns a  where a.table_name='PM_ACCOUNT_BIZ' and a.index_name='IDX_PM_ACCOUNT_BIZ_SERIAL_DATE';
 
INDEX_NAME                     COLUMN_NAME                                                                      COLUMN_POSITION
------------------------------ -------------------------------------------------------------------------------- ---------------
IDX_PM_ACCOUNT_BIZ_SERIAL_DATE CENTER_ID                                                                                      1
IDX_PM_ACCOUNT_BIZ_SERIAL_DATE FIN_DATE      

我们在创建新索引后,执行修改后的SQL语句:

SQL> set timing on
SQL> set autotrace traceonly  
SQL> select  t1.account_id,
  2         t1.hospital_id,
  3         (select hosp_level
  4            from bs_hospital a
  5           where t1.hospital_id = a.hospital_id
  6             and a.valid_flag = '1') as hosp_level,
  7         t1.serial_no,
  8         t1.icd,
  9         (select t4.disease
 10            from bs_disease t4
 11           where t1.icd = t4.icd(+)
 12             and t4.center_id = nvl(t1.catalog_center, t1.center_id)) as disease,
 13         t1.biz_type,
 14         t1.treatment_type,
 15         t1.disease_type,
 16         t1.reimburse_flag,
 17         t1.corp_id,
 18         t1.corp_type_code,
 19         t1.corp_name,
 20         t1.indi_id,
 21         t1.pers_type,
 22         t1.center_id,
 23         t1.district_code,
 24         t1.out_type,
 25         t1.biz_flag,
 26         t1.biz_flag_old,
 27         t1.name,
 28         t1.idcard,
 29         t1.sex,
 30         t1.begin_date,
 31         t1.end_date,
 32         t1.fin_date,
 33         t1.reg_date,
 34         t1.disease_fee,
 35         t1.violate_flag,
 36         t1.patient_id,
 37         t1.in_days,
 38         decode(t1.allow_treat, '0', 0, 1) As allow_treat,
 39         Decode(T1.Treatment_Type_Last,
 40                '',
 41                T1.Treatment_Type,
 42                Decode(T1.Treatment_Type,
 43                       '120',
 44                       '120',
 45                       Decode(T1.Biz_Type,
 46                              '41',
 47                              '扣减已记帐金额',
 48                              '42',
 49                              '扣减已记帐金额',
 50                              T1.Treatment_Type_Last))) As Treatment_Type_Last,
 51         t1.violate,
 52         t1.pay_money,
 53         t1.pay_fund,
 54         t1.audit_money,
 55         '0' as finish_flag,
 56         t1.MONTH_DECL_SN,
 57         t1.deal_flag,
 58         t1.audit_deal_flag,
 59         t1.declare_icd_guide,
 60         t1.declare_audit_fee,
 61         t1.declare_audit_fee_cl,
 62         t1.first_icd_guide,
 63         t1.first_audit_fee,
 64         t1.first_audit_fee_cl,
 65         t1.second_icd_guide,
 66         t1.second_audit_fee,
 67         t1.second_audit_fee_cl,
 68         t1.PAY_otherfee,
 69         t1.PAY_FUND003,
 70         t1.PAY_FUND001,
 71         t1.PAY_FUND201,
 72         t1.PAY_FUND301,
 73         t1.PAY_FUND999,
 74         t1.PAY_FUND996,
 75         t1.PAY_begin
 76    from (select a.account_id,
 77                 a.hospital_id,
 78                 a.serial_no,
 79                 a.center_id,
 80                 a.icd,
 81                 a.biz_type,
 82                 a.treatment_type,
 83                 a.reimburse_flag,
 84                 a.corp_id,
 85                 a.corp_type_code,
 86                 t2.corp_name,
 87                 a.indi_id,
 88                 a.pers_type,
 89                 center.catalog_center,
 90                 t2.district_code,
 91                 decode(t2.center_id, t2.district_code, 0, 1) as out_type,
 92                 a.biz_flag,
 93                 a.biz_flag_old,
 94                 t2.name,
 95                 t2.idcard,
 96                 t2.sex,
 97                 t2.begin_date,
 98                 t2.end_date,
 99                 a.fin_date,
100                 t2.reg_date,
101                 a.violate_flag,
102                 (select mbf.disease_type
103                    from mt_biz_fin mbf
104                   where mbf.valid_flag = '1'
105                     and mbf.hospital_id = a.hospital_id
106                     and mbf.serial_no = a.serial_no) disease_type,
107                 (Select aa1.allow_treat
108                    From pm_account_scene aa1
109                   where aa1.hospital_id = a.hospital_id
110                     and aa1.serial_no = a.serial_no
111                     and aa1.valid_flag = '1') as allow_treat,
112                 (select distinct bb1.patient_id
113                    from mt_biz_fin bb1
114                   where bb1.hospital_id = a.hospital_id
115                     and bb1.serial_no = a.serial_no
116                     and bb1.valid_flag = '1') as patient_id,
117                 (select distinct bb1.in_days
118                    from mt_biz_fin bb1
119                   where bb1.hospital_id = a.hospital_id
120                     and bb1.serial_no = a.serial_no
121                     and bb1.valid_flag = '1') as in_days,
122                 (select Max(audit_treat_value)
123                    from pm_treat_audit aa
124                   where aa.account_id = a.account_id
125                     and aa.audit_staff_id = '2208'
126                     and aa.audit_phase = '1'
127                     and aa.valid_flag = '1') as treatment_type_last,
128                 a.violate,
129                 nvl((SELECT sum(pm_account_fund.pay_money)
130                       FROM pm_account_fund
131                      WHERE a.account_id = pm_account_fund.account_id
132                        AND pm_account_fund.valid_flag = '1'),
133                     0) as pay_money,
134                 nvl((SELECT sum(pm_account_fund.pay_money)
135                       FROM pm_account_fund
136                      WHERE a.account_id = pm_account_fund.account_id
137                        AND pm_account_fund.valid_flag = '1'
138                        AND pm_account_fund.fund_id not in
139                            ('003', '999', '996', '997')),
140                     0) as pay_fund,
141                 NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
142                       FROM PM_ACCOUNT_FUND
143                      WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
144                        AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
145                        AND PM_ACCOUNT_FUND.FUND_ID = '003'),
146                     0) AS PAY_FUND003,
147                 NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
148                       FROM PM_ACCOUNT_FUND
149                      WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
150                        AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
151                        AND PM_ACCOUNT_FUND.FUND_ID in ('801', '001')),
152                     0) AS PAY_FUND001,
153                 NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
154                       FROM PM_ACCOUNT_FUND
155                      WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
156                        AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
157                        AND PM_ACCOUNT_FUND.FUND_ID = '201'),
158                     0) AS PAY_FUND201,
159                 NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
160                       FROM PM_ACCOUNT_FUND
161                      WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
162                        AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
163                        AND PM_ACCOUNT_FUND.FUND_ID = '301'),
164                     0) AS PAY_FUND301,
165                 NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
166                       FROM PM_ACCOUNT_FUND
167                      WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
168                        AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
169                        AND PM_ACCOUNT_FUND.FUND_ID = '999'),
170                     0) AS PAY_FUND999,
171                 NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
172                       FROM PM_ACCOUNT_FUND
173                      WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
174                        AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
175                        AND PM_ACCOUNT_FUND.FUND_ID = '996'),
176                     0) AS PAY_FUND996,
177                 NVL((SELECT SUM(PM_ACCOUNT_FUND.PAY_MONEY)
178                       FROM PM_ACCOUNT_FUND
179                      WHERE A.ACCOUNT_ID = PM_ACCOUNT_FUND.ACCOUNT_ID
180                        AND PM_ACCOUNT_FUND.VALID_FLAG = '1'
181                        AND PM_ACCOUNT_FUND.FUND_ID not in
182                            ('801', '001', '003', '201', '999')),
183                     0) AS PAY_otherfee,
184                 NVL((SELECT SUM(mprf.real_pay)
185                       FROM mt_pay_record_fin mprf
186                      WHERE A.hospital_id = mprf.hospital_id
187                        AND A.serial_no = mprf.serial_no
188                        AND mprf.policy_item_code = 'S01'),
189                     0) AS PAY_begin,
190                 (select nvl(sum(b.AUDIT_MONEY), 0)
191                    from pm_fee_audit b
192                   where a.account_id = b.account_id
193                     and b.audit_staff_id = '2208'
194                     and b.AUDIT_TYPE = '1'
195                     and b.AUDIT_PHASE = '1'
196                     and b.valid_flag = '1') as audit_money,
197                 a.MONTH_DECL_SN,
198                 a.deal_flag,
199                 decode(nvl(a.disease_fee, 0),
200                        0,
201                        nvl((select nvl(max(ration), 0)
202                              from pm_ration pr
203                             where pr.center_id = a.center_id
204                               and pr.hospital_id = a.hospital_id
205                               and pr.treatment_type = a.treatment_type
206                               and pr.year = to_char(a.fin_date, 'yyyy')
207                               and (decode(a.pers_type,
208                                           '21',
209                                           '21',
210                                           '22',
211                                           '21',
212                                           '23',
213                                           '21',
214                                           '24',
215                                           '21',
216                                           '41',
217                                           '21',
218                                           '3',
219                                           '12',
220                                           '4',
221                                           '12',
222                                           '5',
223                                           '12',
224                                           '7',
225                                           '12',
226                                           '2') = pr.insr_no or
227                                   pr.insr_no = '0')
228                               and rownum < 2
229                               and pr.biz_flag = a.biz_flag),
230                            0),
231                        a.disease_fee) as disease_fee,
232                 a.audit_flag as audit_deal_flag,
233                 a.declare_icd_guide as declare_icd_guide,
234                 a.declare_audit_fee as declare_audit_fee,
235                 a.declare_audit_fee_cl as declare_audit_fee_cl,
236                 a.first_icd_guide as first_icd_guide,
237                 a.first_audit_fee as first_audit_fee,
238                 a.first_audit_fee_cl as first_audit_fee_cl,
239                 decode(a.biz_type,
240                        '12',
241                        decode(a.biz_flag_old, 5, '4304001', a.second_icd_guide),
242                        a.second_icd_guide) second_icd_guide,
243                 a.second_audit_fee as second_audit_fee,
244                 a.second_audit_fee_cl as second_audit_fee_cl
245            from bs_center center,pm_account_biz a,mt_biz_fin t2
246           where 1 = 1
247             and ('0' = 'A' or a.reimburse_flag ='0')
248             and ('00' = '00' or a.biz_type ='00')
249             and a.center_id in ('430701')
250             and (a.fin_date between to_date('2014-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and
251                 to_date('2014-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'))
252             and a.valid_flag = '1'
253             and a.deal_flag in ('0', '1', '2')
254             and (nvl(a.staff1_finish_flag, '0') ='0' and
255                 nvl(a.staff2_finish_flag, '0') = '0' and
256                 nvl(a.staff3_finish_flag, '0') = '0')
257             and a.serial_no = t2.serial_no
258             AND a.hospital_id = t2.hospital_id
259             AND t2.valid_flag = '1'
260             and a.center_id = center.center_id(+)
261             and center.center_id in ('430701')          
262             order by a.hospital_id, a.serial_no
263             )t1
264  ;

189998 rows selected.

Elapsed: 00:01:37.15

Execution Plan
----------------------------------------------------------
Plan hash value: 1778792342

---------------------------------------------------------------------------------------------------------------
| Id  | Operation                      | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |                              |     3 |   855 | 20157   (1)| 00:04:02 |
|*  1 |  TABLE ACCESS BY INDEX ROWID   | BS_HOSPITAL                  |     1 |    16 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN            | PK_BS_HOSPITAL               |     1 |       |     1   (0)| 00:00:01 |
|   3 |  TABLE ACCESS BY INDEX ROWID   | BS_DISEASE                   |     1 |    33 |     1   (0)| 00:00:01 |
|*  4 |   INDEX RANGE SCAN             | INX_BS_DISEASE_01            |     1 |       |     1   (0)| 00:00:01 |
|*  5 |  TABLE ACCESS BY INDEX ROWID   | MT_BIZ_FIN                   |     1 |    26 |     1   (0)| 00:00:01 |
|*  6 |   INDEX RANGE SCAN             | PK_MT_BIZ_FIN                |     1 |       |     1   (0)| 00:00:01 |
|   7 |  SORT AGGREGATE                |                              |     1 |    34 |            |          |
|*  8 |   COUNT STOPKEY                |                              |       |       |            |          |
|*  9 |    TABLE ACCESS BY INDEX ROWID | PM_RATION                    |     1 |    34 |     1   (0)| 00:00:01 |
|* 10 |     INDEX RANGE SCAN           | IDX_PM_RATION_1              |     1 |       |     1   (0)| 00:00:01 |
|  11 |  HASH UNIQUE                   |                              |     1 |    26 |     2  (50)| 00:00:01 |
|* 12 |   TABLE ACCESS BY INDEX ROWID  | MT_BIZ_FIN                   |     1 |    26 |     1   (0)| 00:00:01 |
|* 13 |    INDEX RANGE SCAN            | PK_MT_BIZ_FIN                |     1 |       |     1   (0)| 00:00:01 |
|  14 |  HASH UNIQUE                   |                              |     1 |    26 |     2  (50)| 00:00:01 |
|* 15 |   TABLE ACCESS BY INDEX ROWID  | MT_BIZ_FIN                   |     1 |    26 |     1   (0)| 00:00:01 |
|* 16 |    INDEX RANGE SCAN            | PK_MT_BIZ_FIN                |     1 |       |     1   (0)| 00:00:01 |
|* 17 |  TABLE ACCESS BY INDEX ROWID   | PM_ACCOUNT_SCENE             |     1 |    28 |     1   (0)| 00:00:01 |
|* 18 |   INDEX RANGE SCAN             | IDX_PM_ACCOUNT_SCENE_1       |     1 |       |     1   (0)| 00:00:01 |
|  19 |  SORT AGGREGATE                |                              |     1 |    37 |            |          |
|* 20 |   TABLE ACCESS BY INDEX ROWID  | PM_TREAT_AUDIT               |     1 |    37 |     1   (0)| 00:00:01 |
|* 21 |    INDEX RANGE SCAN            | PK_PM_TREAT_AUDIT            |     1 |       |     1   (0)| 00:00:01 |
|  22 |    SORT AGGREGATE              |                              |     1 |    37 |            |          |
|* 23 |     TABLE ACCESS BY INDEX ROWID| PM_TREAT_AUDIT               |     1 |    37 |     1   (0)| 00:00:01 |
|* 24 |      INDEX RANGE SCAN          | PK_PM_TREAT_AUDIT            |     1 |       |     1   (0)| 00:00:01 |
|  25 |  SORT AGGREGATE                |                              |     1 |    12 |            |          |
|* 26 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    12 |     1   (0)| 00:00:01 |
|* 27 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND1          |     1 |       |     1   (0)| 00:00:01 |
|  28 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|* 29 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 30 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  31 |  SORT AGGREGATE                |                              |     1 |    21 |            |          |
|* 32 |   TABLE ACCESS BY INDEX ROWID  | PM_FEE_AUDIT                 |     1 |    21 |     1   (0)| 00:00:01 |
|* 33 |    INDEX RANGE SCAN            | PK_PM_FEE_AUDIT              |     1 |       |     1   (0)| 00:00:01 |
|  34 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|* 35 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 36 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  37 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|* 38 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 39 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  40 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|  41 |   INLIST ITERATOR              |                              |       |       |            |          |
|* 42 |    TABLE ACCESS BY INDEX ROWID | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 43 |     INDEX RANGE SCAN           | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  44 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|* 45 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 46 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  47 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|* 48 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 49 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  50 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|* 51 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 52 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  53 |  SORT AGGREGATE                |                              |     1 |    16 |            |          |
|* 54 |   TABLE ACCESS BY INDEX ROWID  | PM_ACCOUNT_FUND              |     1 |    16 |     1   (0)| 00:00:01 |
|* 55 |    INDEX RANGE SCAN            | PK_PM_ACCOUNT_FUND           |     1 |       |     1   (0)| 00:00:01 |
|  56 |  SORT AGGREGATE                |                              |     1 |    39 |            |          |
|  57 |   TABLE ACCESS BY INDEX ROWID  | MT_PAY_RECORD_FIN            |     1 |    39 |     1   (0)| 00:00:01 |
|* 58 |    INDEX RANGE SCAN            | IDX_MT_PAY_RECORD_FIN_2      |     1 |       |     1   (0)| 00:00:01 |
|* 59 |  TABLE ACCESS BY INDEX ROWID   | MT_BIZ_FIN                   |     1 |   107 |     1   (0)| 00:00:01 |
|  60 |   NESTED LOOPS                 |                              |     3 |   855 | 20157   (1)| 00:04:02 |
|  61 |    NESTED LOOPS                |                              |     3 |   534 | 20156   (1)| 00:04:02 |
|  62 |     TABLE ACCESS BY INDEX ROWID| BS_CENTER                    |     1 |    14 |     1   (0)| 00:00:01 |
|* 63 |      INDEX UNIQUE SCAN         | PK_BS_CENTER                 |     1 |       |     1   (0)| 00:00:01 |
|* 64 |     TABLE ACCESS BY INDEX ROWID| PM_ACCOUNT_BIZ               |     3 |   492 | 20155   (1)| 00:04:02 |
|* 65 |      INDEX RANGE SCAN          | IDX_PM_ACCOUNT_BIZ_CENTER_ID |   118K|       |   178   (4)| 00:00:03 |
|* 66 |    INDEX RANGE SCAN            | PK_MT_BIZ_FIN                |     1 |       |     1   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("A"."VALID_FLAG"='1')
   2 - access("A"."HOSPITAL_ID"=:B1)
   4 - access("T4"."CENTER_ID"=NVL(:B1,:B2) AND "T4"."ICD"=:B3)
   5 - filter("MBF"."VALID_FLAG"='1')
   6 - access("MBF"."HOSPITAL_ID"=:B1 AND "MBF"."SERIAL_NO"=:B2)
   8 - filter(ROWNUM<2)
   9 - filter(("PR"."INSR_NO"=TO_NUMBER(DECODE(:B1,'21','21','22','21','23','21','24','21','41','21','3
              ','12','4','12','5','12','7','12','2')) OR "PR"."INSR_NO"=0) AND TO_NUMBER("PR"."BIZ_FLAG")=:B2)
  10 - access("PR"."YEAR"=TO_NUMBER(TO_CHAR(:B1,'yyyy')) AND "PR"."HOSPITAL_ID"=:B2 AND
              "PR"."TREATMENT_TYPE"=:B3 AND "PR"."CENTER_ID"=:B4)
       filter("PR"."TREATMENT_TYPE"=:B1 AND "PR"."CENTER_ID"=:B2)
  12 - filter("BB1"."VALID_FLAG"='1')
  13 - access("BB1"."HOSPITAL_ID"=:B1 AND "BB1"."SERIAL_NO"=:B2)
  15 - filter("BB1"."VALID_FLAG"='1')
  16 - access("BB1"."HOSPITAL_ID"=:B1 AND "BB1"."SERIAL_NO"=:B2)
  17 - filter("AA1"."VALID_FLAG"='1')
  18 - access("AA1"."HOSPITAL_ID"=:B1 AND "AA1"."SERIAL_NO"=:B2)
  20 - filter("AA"."VALID_FLAG"='1')
  21 - access("AA"."ACCOUNT_ID"=:B1 AND "AA"."AUDIT_PHASE"='1' AND "AA"."AUDIT_STAFF_ID"='2208')
       filter("AA"."AUDIT_STAFF_ID"='2208' AND "AA"."AUDIT_PHASE"='1')
  23 - filter("AA"."VALID_FLAG"='1')
  24 - access("AA"."ACCOUNT_ID"=:B1 AND "AA"."AUDIT_PHASE"='1' AND "AA"."AUDIT_STAFF_ID"='2208')
       filter("AA"."AUDIT_STAFF_ID"='2208' AND "AA"."AUDIT_PHASE"='1')
  26 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  27 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1)
  29 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  30 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1)
       filter("PM_ACCOUNT_FUND"."FUND_ID"<>'003' AND "PM_ACCOUNT_FUND"."FUND_ID"<>'999' AND
              "PM_ACCOUNT_FUND"."FUND_ID"<>'996' AND "PM_ACCOUNT_FUND"."FUND_ID"<>'997')
  32 - filter("B"."VALID_FLAG"='1')
  33 - access("B"."ACCOUNT_ID"=:B1 AND "B"."AUDIT_TYPE"='1' AND "B"."AUDIT_PHASE"='1' AND
              "B"."AUDIT_STAFF_ID"='2208')
       filter("B"."AUDIT_STAFF_ID"='2208')
  35 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  36 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1)
       filter("PM_ACCOUNT_FUND"."FUND_ID"<>'003' AND "PM_ACCOUNT_FUND"."FUND_ID"<>'999' AND
              "PM_ACCOUNT_FUND"."FUND_ID"<>'001' AND "PM_ACCOUNT_FUND"."FUND_ID"<>'801' AND
              "PM_ACCOUNT_FUND"."FUND_ID"<>'201')
  38 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  39 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1 AND "PM_ACCOUNT_FUND"."FUND_ID"='003')
  42 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  43 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1 AND ("PM_ACCOUNT_FUND"."FUND_ID"='001' OR
              "PM_ACCOUNT_FUND"."FUND_ID"='801'))
  45 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  46 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1 AND "PM_ACCOUNT_FUND"."FUND_ID"='201')
  48 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  49 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1 AND "PM_ACCOUNT_FUND"."FUND_ID"='301')
  51 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  52 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1 AND "PM_ACCOUNT_FUND"."FUND_ID"='999')
  54 - filter("PM_ACCOUNT_FUND"."VALID_FLAG"='1')
  55 - access("PM_ACCOUNT_FUND"."ACCOUNT_ID"=:B1 AND "PM_ACCOUNT_FUND"."FUND_ID"='996')
  58 - access("MPRF"."HOSPITAL_ID"=:B1 AND "MPRF"."SERIAL_NO"=:B2 AND "MPRF"."POLICY_ITEM_CODE"='S01')
  59 - filter("T2"."VALID_FLAG"='1')
  63 - access("CENTER"."CENTER_ID"='430701')
  64 - filter(NVL("A"."STAFF2_FINISH_FLAG",'0')='0' AND NVL("A"."STAFF1_FINISH_FLAG",'0')='0' AND
              NVL("A"."STAFF3_FINISH_FLAG",'0')='0' AND "A"."REIMBURSE_FLAG"='0' AND "A"."VALID_FLAG"='1' AND
              ("A"."DEAL_FLAG"='0' OR "A"."DEAL_FLAG"='1' OR "A"."DEAL_FLAG"='2'))
  65 - access("A"."CENTER_ID"="CENTER"."CENTER_ID" AND "A"."FIN_DATE">=TO_DATE(' 2014-01-01 00:00:00',
              'syyyy-mm-dd hh24:mi:ss') AND "A"."FIN_DATE"< =TO_DATE(' 2014-12-31 23:59:59', 'syyyy-mm-dd               hh24:mi:ss'))        filter("A"."FIN_DATE">=TO_DATE(' 2014-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
              "A"."CENTER_ID"='430701' AND "A"."FIN_DATE"< =TO_DATE(' 2014-12-31 23:59:59', 'syyyy-mm-dd hh24:mi:ss'))
  66 - access("A"."HOSPITAL_ID"="T2"."HOSPITAL_ID" AND "A"."SERIAL_NO"="T2"."SERIAL_NO")


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
    2319157  consistent gets
       8301  physical reads
        576  redo size
    2809640  bytes sent via SQL*Net to client
      24709  bytes received via SQL*Net from client
       1335  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
      189998  rows processed

从上面的实际执行情况可以看到返回了接近19万条记录花费的时间是1分37秒,也就是97秒与3286秒,已经是几十倍的提升了。

小结:这里优化的方法是通过修改SQL语句,改变表连接的方法,去掉不必要的分组(group by)操作,创建来合理的复合索引来避免排序(order by)来达到性能的提升。

乱用Hint造成性能问题案例一

某系统上午9点到11点的AWR报告中TOP SQL,其中消耗时间最长的花了9770秒,该SQL_ID为36cbabzyq13gy
这条SQL语句与SQL_ID为0frcad5600xdu,g1a0qu2b42j83所对应的SQL语句除了文本值不一样外,其它部分是相同的,这里没有使用绑定变量

SQL ordered by Elapsed Time
Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code.
% Total DB Time is the Elapsed Time of the SQL statement divided into the Total Database Time multiplied by 100
Elapsed Time (s)	CPU Time (s)	Executions	Elap per Exec (s)	% Total DB Time	          SQL Id	         SQL Module	        SQL Text
9,770	            6,418	        1	          9769.94	            16.02	           36cbabzyq13gy	 w3wp.exe	        SELECT /*+ index(lt, PK_LV_U...
5,831	            3,851	        2	          2915.28	             9.56	           0frcad5600xdu	 w3wp.exe	        SELECT /*+ index(lt, PK_LV_U...
2,495	            1,643	        1	          2495.48	             4.09	           g1a0qu2b42j83	 w3wp.exe	        SELECT /*+ index(lt, PK_LV_U...
2,348	            1,482	        62	            37.86	             3.85	           a7dkwg8uhrwkj	 JDBC Thin  Client	select * from ( select a.hosp...
772	              341	        22	            35.10	             1.27	           2vpny9ut5dcm6	 JDBC Thin  Client	select t.pay_type as pay_...
670	              438	        29	            23.10	             1.10	           acj1640jvr3u5	 JDBC Thin  Client	select t.biz_flag, t1.name, t1...
618	              317	        60	            10.30	             1.01	           ggrctzgtcg14s	 JDBC Thin  Client	select t.pay_type as pay_...
617	              39	        2	           308.52	             1.01	           c5m1092x9vg2y	 JDBC Thin  Client	select w.hospital_id, t.hospit...
605	              398	        1	           604.51	             0.99	           3yy1wbuvsxm93	 w3wp.exe	        SELECT /*+ index(lt, PK_LV_U...
381	              55	        1	           380.52	             0.62	           6q1xuznmvsu5d	 w3wp.exe	        SELECT t_center.center_name, ...

从awrsqrpt报告中可以看到,该SQL的逻辑读为3亿多次

Stat Name                   Statement Total  Per Execution  % Snap Total
Elapsed Time (ms)           9,769,937        9,769,936.85    16.02
CPU Time (ms)               6,417,920        6,417,920.27    20.69
Executions                  1      
Buffer Gets                 361,831,845      361,831,845.00  15.35
Disk Reads                  23,989  23,      989.00          0.05
Parse Calls                 1                1.00            0.00
Rows                        0                0.00   
User I/O Wait Time (ms)     27,723      
Cluster Wait Time (ms)      0      
Application Wait Time (ms)  0      
Concurrency Wait Time (ms)  460      
Invalidations               0      
Version Count               2      
Sharable Mem(KB)            275     

SQL_ID为36cbabzyq13gy的SQL语句如下:

SELECT /*+ index(lt,PK_LV_URBAN_TOPAY_TMP) */
 bi.indi_id,
 bi.name,
 pt.pers_name,
 bs.sex_name,
 lt.pay_money,
 bi.idcard,
 bi.birthday,
 bf.headed_name,
 lt.fac_pay_date,
 lbb.audit_man,
 tab_hosp.hospital_name as hospital_name,
 to_char(lbb.make_bill_tm, 'yyyy-mm-dd') as make_bill_tm,
 bf.telephone,
 nvl((decode(lt.intensive_disability_flag,
             1,
             decode(lt.lowflag, 1, '重症伤残,', '重症伤残'),
             '') ||
     decode(lt.lowflag, 1, decode(lt.nothing_flag, 1, '低保,', '低保'), '') ||
     decode(lt.nothing_flag, 1, '三无', '')),
     '标准') as subsidykide
  FROM lv_urban_topay_tmp lt,
       bs_insured bi,
       bs_sex bs,
       bs_person_type pt,
       bs_pres_insur bpi,
       bs_family bf,
       lv_busi_bill lbb,
       lv_busi_record lbr,
       lv_busi_assign lba,
       (select bh.hospital_name, bph.indi_id
          from bs_pers_hosp bph, bs_hospital bh
         where bph.hospital_id = bh.hospital_id
           and bph.first_flag = 1
           and bph.end_year = '2015') tab_hosp
 WHERE nvl(lt.busi_asg_no, 0) <> 0
   AND nvl(lt.busi_asg_no, 0) not in (-999, -998, -997, -981, -980)
   AND lt.fac_pay_date is not null
   AND bi.indi_id = lt.indi_id
   AND bs.sex = bi.sex
   AND bi.indi_id = tab_hosp.indi_id(+)
   AND lbr.busi_reco_no = lba.busi_reco_no
   AND lbr.busi_bill_sn = lbb.busi_bill_sn
   AND lt.center_id = lbb.center_id
   AND lt.busi_asg_no = lba.busi_asg_no
   AND lt.indi_id = bi.indi_id
   AND pt.pers_type = bi.pers_type
   AND bpi.indi_id = bi.indi_id
   AND lt.center_id = pt.center_id
   AND bf.family_id = bi.family_id
   AND bf.family_sta = 1
   AND bi.indi_sta = 1
   AND bpi.indi_join_sta = 1
   AND bf.center_id = lt.center_id
   AND bf.corp_id = lt.corp_id
   AND lt.policy_item_code like '%INDI_TOPAY'
   AND lt.corp_id = '19159'
   AND bpi.insr_detail_code = 21
   AND lt.center_id = '430726'
   AND lt.curr_year = '2015'
   AND lt.fac_pay_date >= to_date('2014-12-01 00:00:00',
                                  'yyyy-MM-dd hh24:mi:ss')
   AND lt.fac_pay_date < =
       to_date('2015-01-05 23:59:59', 'yyyy-MM-dd hh24:mi:ss')
   and exists (select 'X'
          FROM lv_busi_bill       lbb,
               lv_busi_record     lbr,
               lv_busi_assign     lba,
               lv_urban_topay_tmp lutt
         WHERE lbr.busi_reco_no = lba.busi_reco_no
           AND lbr.busi_bill_sn = lbb.busi_bill_sn
           AND lbb.center_id = '430726'
           AND lutt.corp_id = '19159'
           AND lutt.center_id = lbb.center_id
           AND lutt.busi_asg_no = lba.busi_asg_no
           and lba.busi_asg_no = lt.busi_asg_no
           and lutt.indi_id = bi.indi_id)
 order by lt.fac_pay_date, bi.indi_id, bi.name

通过执地xplan脚本来获得SQL_ID为36cbabzyq13gy的执行计划,其执行计划如下

-----------------------------------------------------------------------------------------------------------------------------------
| Id  | Order | Operation                               | Name                           | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |
-----------------------------------------------------------------------------------------------------------------------------------
|   0 |    45 | SELECT STATEMENT                        |                                |        |       | 20484 (100)|          |
|   1 |    44 |  SORT ORDER BY                          |                                |      1 |   290 | 20484   (3)| 00:04:06 |
|   2 |    43 |   NESTED LOOPS                          |                                |      1 |   290 | 20483   (3)| 00:04:06 |
|   3 |    40 |    NESTED LOOPS                         |                                |      1 |   265 | 20482   (3)| 00:04:06 |
|   4 |    37 |     NESTED LOOPS                        |                                |      1 |   254 | 20481   (3)| 00:04:06 |
|   5 |    34 |      NESTED LOOPS                       |                                |      1 |   242 | 20480   (3)| 00:04:06 |
|   6 |    32 |       NESTED LOOPS                      |                                |      1 |   230 | 20479   (3)| 00:04:06 |
|   7 |    29 |        HASH JOIN                        |                                |    168 | 27720 | 17063   (3)| 00:03:25 |
|   8 |    13 |         VIEW                            | VW_SQ_1                        |    168 |  2016 |  2441   (1)| 00:00:30 |
|   9 |    12 |          HASH UNIQUE                    |                                |    168 |  9408 |            |          |
|  10 |    11 |           NESTED LOOPS                  |                                |    168 |  9408 |  2441   (1)| 00:00:30 |
|  11 |     8 |            NESTED LOOPS                 |                                |   1718 | 75592 |  2097   (1)| 00:00:26 |
|  12 |     5 |             NESTED LOOPS                |                                |   1758 | 58014 |  1745   (1)| 00:00:21 |
|  13 |     2 |              TABLE ACCESS BY INDEX ROWID| LV_URBAN_TOPAY_TMP             |   1742 | 36582 |  1397   (1)| 00:00:17 |
|  14 |     1 |               INDEX RANGE SCAN          | IDX_LV_URBAN_TOPAY_TMP_CORP_ID |  18770 |       |    14   (0)| 00:00:01 |
|  15 |     4 |              TABLE ACCESS BY INDEX ROWID| LV_BUSI_ASSIGN                 |      1 |    12 |     1   (0)| 00:00:01 |
|  16 |     3 |               INDEX UNIQUE SCAN         | PK_LV_BUSI_ASSIGN              |      1 |       |     1   (0)| 00:00:01 |
|  17 |     7 |             TABLE ACCESS BY INDEX ROWID | LV_BUSI_RECORD                 |      1 |    11 |     1   (0)| 00:00:01 |
|  18 |     6 |              INDEX UNIQUE SCAN          | PK_LV_BUSI_RECORD              |      1 |       |     1   (0)| 00:00:01 |
|  19 |    10 |            TABLE ACCESS BY INDEX ROWID  | LV_BUSI_BILL                   |      1 |    12 |     1   (0)| 00:00:01 |
|  20 |     9 |             INDEX UNIQUE SCAN           | PK_LV_BUSI_BILL                |      1 |       |     1   (0)| 00:00:01 |
|  21 |    28 |         NESTED LOOPS OUTER              |                                |    123 | 18819 | 14622   (3)| 00:02:56 |
|  22 |    21 |          HASH JOIN                      |                                |    123 | 13776 | 14375   (3)| 00:02:53 |
|  23 |    15 |           TABLE ACCESS BY INDEX ROWID   | BS_FAMILY                      |    102 |  3264 |    93   (0)| 00:00:02 |
|  24 |    14 |            INDEX RANGE SCAN             | IDX_BS_FAMILY_CORP_ID          |   1203 |       |     1   (0)| 00:00:01 |
|  25 |    20 |           HASH JOIN                     |                                |   1081K|    82M| 14272   (3)| 00:02:52 |
|  26 |    16 |            TABLE ACCESS FULL            | BS_PERSON_TYPE                 |     11 |   198 |     3   (0)| 00:00:01 |
|  27 |    19 |            HASH JOIN                    |                                |   1080K|    63M| 14258   (3)| 00:02:52 |
|  28 |    17 |             TABLE ACCESS FULL           | BS_SEX                         |      4 |    24 |     3   (0)| 00:00:01 |
|  29 |    18 |             TABLE ACCESS FULL           | BS_INSURED                     |   1080K|    57M| 14244   (3)| 00:02:51 |
|  30 |    27 |          VIEW PUSHED PREDICATE          |                                |      1 |    41 |     2   (0)| 00:00:01 |
|  31 |    26 |           NESTED LOOPS                  |                                |      1 |    57 |     2   (0)| 00:00:01 |
|  32 |    23 |            TABLE ACCESS BY INDEX ROWID  | BS_PERS_HOSP                   |      1 |    25 |     1   (0)| 00:00:01 |
|  33 |    22 |             INDEX RANGE SCAN            | PK_BS_PERS_HOSP                |      2 |       |     1   (0)| 00:00:01 |
|  34 |    25 |            TABLE ACCESS BY INDEX ROWID  | BS_HOSPITAL                    |      1 |    32 |     1   (0)| 00:00:01 |
|  35 |    24 |             INDEX UNIQUE SCAN           | PK_BS_HOSPITAL                 |      1 |       |     1   (0)| 00:00:01 |
|  36 |    31 |        TABLE ACCESS BY INDEX ROWID      | LV_URBAN_TOPAY_TMP             |      1 |    65 |  3416   (4)| 00:00:41 |
|  37 |    30 |         INDEX FULL SCAN                 | PK_LV_URBAN_TOPAY_TMP          |      1 |       |  3416   (4)| 00:00:41 |
|  38 |    33 |       INDEX UNIQUE SCAN                 | INDEX_BS_PRES_INSUR_UNIQUE     |      1 |    12 |     1   (0)| 00:00:01 |
|  39 |    36 |      TABLE ACCESS BY INDEX ROWID        | LV_BUSI_ASSIGN                 |      1 |    12 |     1   (0)| 00:00:01 |
|  40 |    35 |       INDEX UNIQUE SCAN                 | PK_LV_BUSI_ASSIGN              |      1 |       |     1   (0)| 00:00:01 |
|  41 |    39 |     TABLE ACCESS BY INDEX ROWID         | LV_BUSI_RECORD                 |      1 |    11 |     1   (0)| 00:00:01 |
|  42 |    38 |      INDEX UNIQUE SCAN                  | PK_LV_BUSI_RECORD              |      1 |       |     1   (0)| 00:00:01 |
|  43 |    42 |    TABLE ACCESS BY INDEX ROWID          | LV_BUSI_BILL                   |      1 |    25 |     1   (0)| 00:00:01 |
|  44 |    41 |     INDEX UNIQUE SCAN                   | PK_LV_BUSI_BILL                |      1 |       |     1   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------------------------------


***********
Table Level
***********


Table                   Number                 Empty Average    Chain Average Global User           Sample Date
Name                   of Rows   Blocks       Blocks   Space    Count Row Len Stats  Stats            Size MM-DD-YYYY
--------------- -------------- -------- ------------ ------- -------- ------- ------ ------ -------------- ----------
LV_URBAN_TOPAY_     22,991,252  580,702        8,018     904        5     175 YES    NO          5,747,813 12-08-2014
TMP


Column                    Column                       Distinct          Number     Number Global User           Sample Date
Name                      Details                        Values Density Buckets      Nulls Stats  Stats            Size MM-DD-YYYY
------------------------- ------------------------ ------------ ------- ------- ---------- ------ ------ -------------- ----------
URBAN_TOPAY_SN            NUMBER(12,0) NOT NULL      17,882,394       0     254          0 YES    NO          5,747,813 12-08-2014
CORP_ID                   NUMBER(12,0) NOT NULL             848       0     254          0 YES    NO              5,935 12-08-2014
INDI_ID                   NUMBER(12,0) NOT NULL       1,934,475       0     254          0 YES    NO          5,747,813 12-08-2014
NAME                      VARCHAR2(20)                  380,042       0     254          0 YES    NO            580,870 12-08-2014
IDCARD                    VARCHAR2(20)                  857,905       0       1  4,611,866 YES    NO            464,507 12-08-2014
PERS_TYPE                 NUMBER(2,0)                         4       0       4          0 YES    NO              5,935 12-08-2014
POLICY_ITEM_CODE          VARCHAR2(50) NOT NULL               9       0       9          0 YES    NO              5,935 12-08-2014
POLICY_ITEM_NAME          VARCHAR2(50)                        9       0       9          0 YES    NO              5,935 12-08-2014
INTENSIVE_DISABILITY_FLAG NUMBER(1,0)                         2       1       1          0 YES    NO              5,935 12-08-2014
VETERAN_BENEFIT_FLAG      NUMBER(1,0)                         1       1       1          0 YES    NO              5,935 12-08-2014
STIPEND_FLAG              NUMBER(1,0)                         1       1       1          0 YES    NO              5,935 12-08-2014
LOANS_FLAG                NUMBER(1,0)                         2       1       1          0 YES    NO              5,935 12-08-2014
REGISTERED_NUMBER         VARCHAR2(20)                        0       0       0 ########## YES    NO                    12-08-2014
PAY_INFO_NO               NUMBER(12,0)                6,086,462       0       1          0 YES    NO          5,747,813 12-08-2014
MONEY_NO                  NUMBER(12,0)               17,398,621       0       1          0 YES    NO          5,747,813 12-08-2014
INDIPAYSER                NUMBER(12,0)               22,991,252       0       1          0 YES    NO            580,870 12-08-2014
CALC_PRD                  VARCHAR2(6)                        28       0      28          0 YES    NO              5,935 12-08-2014
SRC_TYPE                  NUMBER(2,0)                         4       0       4          0 YES    NO              5,935 12-08-2014
MONEY_ID                  NUMBER(3,0)                         8       0       8          0 YES    NO              5,935 12-08-2014
PAY_MONEY                 NUMBER(12,2)                       16       0      16          0 YES    NO              5,935 12-08-2014
DO_FLAG                   NUMBER(1,0)                         1       0       1          0 YES    NO              5,935 12-08-2014
CENTER_ID                 VARCHAR2(10)                       10       0      10          0 YES    NO              5,935 12-08-2014
LOWFLAG                   NUMBER(1,0)                         2       1       1          0 YES    NO              5,935 12-08-2014
NOTHING_FLAG              NUMBER(1,0)                         2       1       1          0 YES    NO              5,935 12-08-2014
FAMILY_ID                 NUMBER(12,0)                  660,682       0       1    714,868 YES    NO            562,833 12-08-2014
URBAN_TYPE                NUMBER(2,0)                         4       0       4          0 YES    NO              5,935 12-08-2014
URBAN_TYPE_NAME           VARCHAR2(50)                        4       0       1          0 YES    NO              5,935 12-08-2014
BUSI_ASG_NO               NUMBER(12,0)                    2,223       0     254  3,836,517 YES    NO              4,967 12-08-2014
FAC_PAY_DATE              DATE                              907       0     254  3,836,517 YES    NO              4,967 12-08-2014
CURR_YEAR                 VARCHAR2(4) NOT NULL                8       0       8          0 YES    NO              5,935 12-08-2014
MOD_TIMESTAMP             TIMESTAMP(6)(11)                    0       0       0 ########## YES    NO                    12-08-2014
IS_PRINT                  NUMBER(1,0)                         1       1       1          0 YES    NO              5,935 12-08-2014
CURR_YEAR_BEG_PRD         VARCHAR2(6)                         8       0       1          0 YES    NO              5,935 12-08-2014
CURR_YEAR_END_PRD         VARCHAR2(6)                         8       0       1          0 YES    NO              5,935 12-08-2014

                              B                                        Average     Average
Index                      Tree Leaf       Distinct         Number Leaf Blocks Data Blocks      Cluster Global User           Sample Date
Name            Unique    Level Blks           Keys        of Rows     Per Key     Per Key       Factor Stats  Stats            Size MM-DD-YYYY
--------------- --------- ----- ---- -------------- -------------- ----------- ----------- ------------ ------ ------ -------------- ----------
PK_LV_URBAN_TOP UNIQUE        2 ####     21,623,824     21,623,824           1           1    2,737,193 YES    NO            137,855 12-08-2014
AY_TMP

DX_LV_URBAN_TOP NONUNIQUE     2 ####      6,086,462     22,613,945           1           1   10,946,874 YES    NO            429,108 12-08-2014
AY_TMP_PAY

IDX_LV_URBAN_TO NONUNIQUE     2 ####          2,223     18,979,800          17         708    1,574,170 YES    NO            530,075 12-08-2014
PAY_TMP_BUS

IDX_LV_URBAN_TO NONUNIQUE     3 ####            223     22,474,402         393      25,642    5,718,207 YES    NO            284,917 12-08-2014
PAY_TMP_CENTER

IDX_LV_URBAN_TO NONUNIQUE     2 ####        660,682     21,796,771           1          17   11,256,787 YES    NO            407,563 12-08-2014
PAY_TMP_FAM

IDX_LV_URBAN_TO NONUNIQUE     2 ####      1,934,475     21,768,753           1           7   15,125,646 YES    NO            381,994 12-08-2014
PAY_TMP_INDI

IDX_LV_URBAN_TO NONUNIQUE     2 ####     17,398,621     21,880,953           1           1   11,499,589 YES    NO            423,560 12-08-2014
PAY_TMP_NO

IDX_LV_URBAN_TO NONUNIQUE     2 ####     22,485,115     22,485,115           1           1    2,820,116 YES    NO            121,303 12-08-2014
PAY_TMP_SOME

IDX_LV_URBAN_TO NONUNIQUE     3 ####            996     22,727,163          80       8,493    8,459,953 YES    NO            311,063 12-08-2014
PAY_TMP_CORP_ID

IDX_LV_URBAN_TO NONUNIQUE     2 ####              8     23,228,508       7,131     #######      828,346 YES    NO            465,750 12-08-2014
PAY_TMP_YEAR


Index           Column                     Col Column
Name            Name                       Pos Details
--------------- ------------------------- ---- ------------------------
DX_LV_URBAN_TOP PAY_INFO_NO                  1 NUMBER(12,0)
AY_TMP_PAY

                PAY_INFO_NO                  1 NUMBER(12,0)
IDX_LV_URBAN_TO BUSI_ASG_NO                  1 NUMBER(12,0)
PAY_TMP_BUS

                BUSI_ASG_NO                  1 NUMBER(12,0)
IDX_LV_URBAN_TO CENTER_ID                    1 VARCHAR2(10)
PAY_TMP_CENTER

                CENTER_ID                    1 VARCHAR2(10)
                CURR_YEAR                    2 VARCHAR2(4) NOT NULL
                CURR_YEAR                    2 VARCHAR2(4) NOT NULL
                PERS_TYPE                    3 NUMBER(2,0)
                PERS_TYPE                    3 NUMBER(2,0)
IDX_LV_URBAN_TO CORP_ID                      1 NUMBER(12,0) NOT NULL
PAY_TMP_CORP_ID

                CORP_ID                      1 NUMBER(12,0) NOT NULL
                CURR_YEAR                    2 VARCHAR2(4) NOT NULL
                CURR_YEAR                    2 VARCHAR2(4) NOT NULL
                PERS_TYPE                    3 NUMBER(2,0)
                PERS_TYPE                    3 NUMBER(2,0)
IDX_LV_URBAN_TO FAMILY_ID                    1 NUMBER(12,0)
PAY_TMP_FAM

                FAMILY_ID                    1 NUMBER(12,0)
IDX_LV_URBAN_TO INDI_ID                      1 NUMBER(12,0) NOT NULL
PAY_TMP_INDI

                INDI_ID                      1 NUMBER(12,0) NOT NULL
IDX_LV_URBAN_TO MONEY_NO                     1 NUMBER(12,0)
PAY_TMP_NO

                MONEY_NO                     1 NUMBER(12,0)
IDX_LV_URBAN_TO URBAN_TOPAY_SN               1 NUMBER(12,0) NOT NULL
PAY_TMP_SOME

                URBAN_TOPAY_SN               1 NUMBER(12,0) NOT NULL
                INDI_ID                      2 NUMBER(12,0) NOT NULL
                INDI_ID                      2 NUMBER(12,0) NOT NULL
                POLICY_ITEM_CODE             3 VARCHAR2(50) NOT NULL
                POLICY_ITEM_CODE             3 VARCHAR2(50) NOT NULL
                CORP_ID                      4 NUMBER(12,0) NOT NULL
                CORP_ID                      4 NUMBER(12,0) NOT NULL
                BUSI_ASG_NO                  5 NUMBER(12,0)
                BUSI_ASG_NO                  5 NUMBER(12,0)
                CURR_YEAR                    6 VARCHAR2(4) NOT NULL
                CURR_YEAR                    6 VARCHAR2(4) NOT NULL
IDX_LV_URBAN_TO CURR_YEAR                    1 VARCHAR2(4) NOT NULL
PAY_TMP_YEAR

                CURR_YEAR                    1 VARCHAR2(4) NOT NULL

PK_LV_URBAN_TOP URBAN_TOPAY_SN               1 NUMBER(12,0) NOT NULLAY_TMP
                INDI_ID                      2 NUMBER(12,0) NOT NULL
                POLICY_ITEM_CODE             3 VARCHAR2(50) NOT NULL
                CORP_ID                      4 NUMBER(12,0) NOT NULL
                CURR_YEAR                    5 VARCHAR2(4) NOT NULL


从上面的显示结果可以看到执行计划的第一步执行的是对索引IDX_LV_URBAN_TOPAY_TMP_CORP_ID执行索引范围扫描并没有使用Hint所指定的PK_LV_URBAN_TOPAY_TMP,而且从上面的显示的索引信息部分可以看到索引PK_LV_URBAN_TOPAY_TMP是由列URBAN_TOPAY_SN, INDI_ID, POLICY_ITEM_CODE, CORP_ID, CURR_YEAR组成的复合索引而查询条件没有URBAN_TOPAY_SN字段使用不了这个索引从上面的执行计划可以看到这一结果。上面执行计划中步骤28与步骤29执行哈希连接,都是全表扫描,其中步骤Id=29是对BS_INSURED执行100多万条记录执行全表扫并且将它们的结果与表BS_PERSON_TYPE执行哈希连接最后与BS_FAMILY执行哈希连接返回记录123条数据,其成本是14375,其中对表BS_INSURED执行全表扫描的成本就是14244。而执行计划执行的第一步就是访问LV_URBAN_TOPAY_TMP,而where条件中有 bi.indi_id = lt.indi_id AND bs.sex = bi.sex and pt.pers_type = bi.pers_type,且这条连接条件都存在索引,那么就不应该那对BS_INSURED,BS_SEX,BS_PERSON_TYPE,BS_FAMILY 这四个表之间进行哈希连接后再与这四个表(LV_URBAN_TOPAY_TMP,LV_BUSI_ASSIGN,LV_BUSI_RECORD,LV_BUSI_BILL)连接后的结果集之间执行哈希连接。而是应该
在这四个表(LV_URBAN_TOPAY_TMP,LV_BUSI_ASSIGN,LV_BUSI_RECORD,LV_BUSI_BILL)连接后与BS_INSURED执行嵌套循环连接,因为有where条件bi.indi_id = lt.indi_id 而且indi_id在表BS_INSURED中是主键,从上面的索引信息中可以看到IDX_LV_URBAN_TOPAY_TMP_CORP_ID索引的distinct key是996,而where条件能使用CBO选择使用该索引从执行计划的Order列为1的步骤可知首先执行的就是对索引IDX_LV_URBAN_TOPAY_TMP_CORP_ID的索引范围扫描。当LV_URBAN_TOPAY_TMP与BS_INSURED执行完嵌套循环连接后因为有where条件bs.sex = bi.sex and pt.pers_type = bi.pers_type所以对BS_SEX,BS_PERSON_TYPE,BS_FAMILY表都应该执行嵌套循环连接。

这里优化步骤是首先删除原来SQL语句中所使用的Hint”/*+ index(lt,PK_LV_URBAN_TOPAY_TMP) */”后并执行SQL语句:

SQL>SELECT 
 bi.indi_id,
 bi.name,
 pt.pers_name,
 bs.sex_name,
 lt.pay_money,
 bi.idcard,
 bi.birthday,
 bf.headed_name,
 lt.fac_pay_date,
 lbb.audit_man,
 tab_hosp.hospital_name as hospital_name,
 to_char(lbb.make_bill_tm, 'yyyy-mm-dd') as make_bill_tm,
 bf.telephone,
 nvl((decode(lt.intensive_disability_flag,
             1,
             decode(lt.lowflag, 1, '重症伤残,', '重症伤残'),
             '') ||
     decode(lt.lowflag, 1, decode(lt.nothing_flag, 1, '低保,', '低保'), '') ||
     decode(lt.nothing_flag, 1, '三无', '')),
     '标准') as subsidykide
  FROM lv_urban_topay_tmp lt,
       bs_insured bi,
       bs_sex bs,
       bs_person_type pt,
       bs_pres_insur bpi,
       bs_family bf,
       lv_busi_bill lbb,
       lv_busi_record lbr,
       lv_busi_assign lba,
       (select bh.hospital_name, bph.indi_id
          from bs_pers_hosp bph, bs_hospital bh
         where bph.hospital_id = bh.hospital_id
           and bph.first_flag = 1
           and bph.end_year = '2015') tab_hosp
 WHERE nvl(lt.busi_asg_no, 0) <> 0
   AND nvl(lt.busi_asg_no, 0) not in (-999, -998, -997, -981, -980)
   AND lt.fac_pay_date is not null
   AND bi.indi_id = lt.indi_id
   AND bs.sex = bi.sex
   AND bi.indi_id = tab_hosp.indi_id(+)
   AND lbr.busi_reco_no = lba.busi_reco_no
   AND lbr.busi_bill_sn = lbb.busi_bill_sn
   AND lt.center_id = lbb.center_id
   AND lt.busi_asg_no = lba.busi_asg_no
   AND lt.indi_id = bi.indi_id
   AND pt.pers_type = bi.pers_type
   AND bpi.indi_id = bi.indi_id
   AND lt.center_id = pt.center_id
   AND bf.family_id = bi.family_id
   AND bf.family_sta = 1
   AND bi.indi_sta = 1
   AND bpi.indi_join_sta = 1
   AND bf.center_id = lt.center_id
   AND bf.corp_id = lt.corp_id
   AND lt.policy_item_code like '%INDI_TOPAY'
   AND lt.corp_id = '19159'
   AND bpi.insr_detail_code = 21
   AND lt.center_id = '430726'
   AND lt.curr_year = '2015'
   AND lt.fac_pay_date >= to_date('2014-12-01 00:00:00',
                                  'yyyy-MM-dd hh24:mi:ss')
   AND lt.fac_pay_date < =
       to_date('2015-01-05 23:59:59', 'yyyy-MM-dd hh24:mi:ss')
   and exists (select 'X'
          FROM lv_busi_bill       lbb,
               lv_busi_record     lbr,
               lv_busi_assign     lba,
               lv_urban_topay_tmp lutt
         WHERE lbr.busi_reco_no = lba.busi_reco_no
           AND lbr.busi_bill_sn = lbb.busi_bill_sn
           AND lbb.center_id = '430726'
           AND lutt.corp_id = '19159'
           AND lutt.center_id = lbb.center_id
           AND lutt.busi_asg_no = lba.busi_asg_no
           and lba.busi_asg_no = lt.busi_asg_no
           and lutt.indi_id = bi.indi_id)
 order by lt.fac_pay_date, bi.indi_id, bi.name
;
....省略输出结果
2304 rows selected.

Elapsed: 00:00:08.83

一共返回了2304条记录,使用时间是8.83秒,其执行计划如下,现在消除了对BS_INSURED的全表扫描,选择最优的执行计划

--------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                               | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                        |                                |     1 |   278 |    88   (2)| 00:00:02 |
|   1 |  SORT ORDER BY                          |                                |     1 |   278 |    88   (2)| 00:00:02 |
|   2 |   NESTED LOOPS                          |                                |     1 |   278 |    82   (0)| 00:00:01 |
|   3 |    NESTED LOOPS OUTER                   |                                |     1 |   272 |    81   (0)| 00:00:01 |
|   4 |     NESTED LOOPS                        |                                |     1 |   231 |    79   (0)| 00:00:01 |
|   5 |      NESTED LOOPS                       |                                |     1 |   219 |    78   (0)| 00:00:01 |
|   6 |       NESTED LOOPS                      |                                |     1 |   201 |    77   (0)| 00:00:01 |
|   7 |        NESTED LOOPS                     |                                |     1 |   169 |    76   (0)| 00:00:01 |
|   8 |         NESTED LOOPS                    |                                |     1 |   113 |    75   (0)| 00:00:01 |
|   9 |          NESTED LOOPS                   |                                |     1 |    88 |    74   (0)| 00:00:01 |
|  10 |           NESTED LOOPS                  |                                |     1 |    77 |    73   (0)| 00:00:01 |
|* 11 |            TABLE ACCESS BY INDEX ROWID  | LV_URBAN_TOPAY_TMP             |     1 |    65 |    72   (0)| 00:00:01 |
|* 12 |             INDEX RANGE SCAN            | IDX_LV_URBAN_TOPAY_TMP_CORP_ID |   954 |       |     1   (0)| 00:00:01 |
|  13 |            TABLE ACCESS BY INDEX ROWID  | LV_BUSI_ASSIGN                 |     1 |    12 |     1   (0)| 00:00:01 |
|* 14 |             INDEX UNIQUE SCAN           | PK_LV_BUSI_ASSIGN              |     1 |       |     1   (0)| 00:00:01 |
|  15 |           TABLE ACCESS BY INDEX ROWID   | LV_BUSI_RECORD                 |     1 |    11 |     1   (0)| 00:00:01 |
|* 16 |            INDEX UNIQUE SCAN            | PK_LV_BUSI_RECORD              |     1 |       |     1   (0)| 00:00:01 |
|* 17 |          TABLE ACCESS BY INDEX ROWID    | LV_BUSI_BILL                   |     1 |    25 |     1   (0)| 00:00:01 |
|* 18 |           INDEX UNIQUE SCAN             | PK_LV_BUSI_BILL                |     1 |       |     1   (0)| 00:00:01 |
|* 19 |         TABLE ACCESS BY INDEX ROWID     | BS_INSURED                     |     1 |    56 |     1   (0)| 00:00:01 |
|* 20 |          INDEX UNIQUE SCAN              | PK_BS_INSURED                  |     1 |       |     1   (0)| 00:00:01 |
|  21 |           NESTED LOOPS                  |                                |     1 |    56 |     5   (0)| 00:00:01 |
|  22 |            NESTED LOOPS                 |                                |     1 |    35 |     3   (0)| 00:00:01 |
|  23 |             NESTED LOOPS                |                                |     1 |    23 |     2   (0)| 00:00:01 |
|  24 |              TABLE ACCESS BY INDEX ROWID| LV_BUSI_ASSIGN                 |     1 |    12 |     1   (0)| 00:00:01 |
|* 25 |               INDEX UNIQUE SCAN         | PK_LV_BUSI_ASSIGN              |     1 |       |     1   (0)| 00:00:01 |
|  26 |              TABLE ACCESS BY INDEX ROWID| LV_BUSI_RECORD                 |  1679K|    17M|     1   (0)| 00:00:01 |
|* 27 |               INDEX UNIQUE SCAN         | PK_LV_BUSI_RECORD              |     1 |       |     1   (0)| 00:00:01 |
|* 28 |             TABLE ACCESS BY INDEX ROWID | LV_BUSI_BILL                   | 83405 |   977K|     1   (0)| 00:00:01 |
|* 29 |              INDEX UNIQUE SCAN          | PK_LV_BUSI_BILL                |     1 |       |     1   (0)| 00:00:01 |
|* 30 |            TABLE ACCESS BY INDEX ROWID  | LV_URBAN_TOPAY_TMP             |     1 |    21 |     2   (0)| 00:00:01 |
|* 31 |             INDEX RANGE SCAN            | IDX_LV_URBAN_TOPAY_TMP_INDI    |    12 |       |     1   (0)| 00:00:01 |
|* 32 |        TABLE ACCESS BY INDEX ROWID      | BS_FAMILY                      |     1 |    32 |     1   (0)| 00:00:01 |
|* 33 |         INDEX UNIQUE SCAN               | PK_BS_FAMILY                   |     1 |       |     1   (0)| 00:00:01 |
|  34 |       TABLE ACCESS BY INDEX ROWID       | BS_PERSON_TYPE                 |     1 |    18 |     1   (0)| 00:00:01 |
|* 35 |        INDEX UNIQUE SCAN                | PK_BS_PERSON_TYPE              |     1 |       |     1   (0)| 00:00:01 |
|* 36 |      INDEX UNIQUE SCAN                  | INDEX_BS_PRES_INSUR_UNIQUE     |     1 |    12 |     1   (0)| 00:00:01 |
|  37 |     VIEW PUSHED PREDICATE               |                                |     1 |    41 |     2   (0)| 00:00:01 |
|  38 |      NESTED LOOPS                       |                                |     1 |    57 |     2   (0)| 00:00:01 |
|* 39 |       TABLE ACCESS BY INDEX ROWID       | BS_PERS_HOSP                   |     1 |    25 |     1   (0)| 00:00:01 |
|* 40 |        INDEX RANGE SCAN                 | PK_BS_PERS_HOSP                |     2 |       |     1   (0)| 00:00:01 |
|  41 |       TABLE ACCESS BY INDEX ROWID       | BS_HOSPITAL                    |     1 |    32 |     1   (0)| 00:00:01 |
|* 42 |        INDEX UNIQUE SCAN                | PK_BS_HOSPITAL                 |     1 |       |     1   (0)| 00:00:01 |
|  43 |    TABLE ACCESS BY INDEX ROWID          | BS_SEX                         |     1 |     6 |     1   (0)| 00:00:01 |
|* 44 |     INDEX UNIQUE SCAN                   | PK_BS_SEX                      |     1 |       |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------------------------

从上面的执行计划可以看到,当去掉Hint”/*+ index(lt, PK_LV_URBAN_TOPAY_TMP) */”后,CBO选择的执行计划果然是先访问IDX_LV_URBAN_TOPAY_TMP_CORP_ID
来访问表LV_URBAN_TOPAY_TMP,然后因为“lbr.busi_reco_no = lba.busi_reco_no AND lbr.busi_bill_sn = lbb.busi_bill_sn AND lt.center_id = lbb.center_id
AND lt.busi_asg_no = lba.busi_asg_no ”,表LV_BUSI_ASSIGN,LV_BUSI_RECORD,LV_BUSI_BILL与LV_URBAN_TOPAY_TMP连接的列都是各个表的主键,所以会分别与这三个执行嵌套循环连接。且存在where条件bi.indi_id = lt.indi_id ,而indi_id是表BS_INSURED表的主键所以也执行嵌套循环连接。而又因为与表BS_INSURED进行表连接的列也存在相关索引因此,依次类推整个执行计划都是执行嵌套循环连接。而且从下面的执行计划信息中可以看到,整个语句的逻辑读只有96762,而原来的逻辑读为3亿多次。这可是数据量级的减少。

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Order | Operation                               | Name                           | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
|   1 |    44 |  SORT ORDER BY                          |                                |      1 |      1 |   2304 |00:00:00.39 |   96762 |   407K|   407K|  361K (0)|
|   2 |    43 |   NESTED LOOPS                          |                                |      1 |      1 |   2304 |00:00:00.39 |   96762 |       |       |          |
|   3 |    40 |    NESTED LOOPS OUTER                   |                                |      1 |      1 |   2304 |00:00:00.37 |   94456 |       |       |          |
|   4 |    33 |     NESTED LOOPS                        |                                |      1 |      1 |   2304 |00:00:00.30 |   80900 |       |       |          |
|   5 |    31 |      NESTED LOOPS                       |                                |      1 |      1 |   2304 |00:00:00.29 |   76290 |       |       |          |
|   6 |    28 |       NESTED LOOPS                      |                                |      1 |      1 |   2304 |00:00:00.27 |   73984 |       |       |          |
|   7 |    25 |        NESTED LOOPS                     |                                |      1 |      1 |   2304 |00:00:00.25 |   67070 |       |       |          |
|   8 |    11 |         NESTED LOOPS                    |                                |      1 |      1 |   2304 |00:00:00.09 |   21695 |       |       |          |
|   9 |     8 |          NESTED LOOPS                   |                                |      1 |      1 |   2304 |00:00:00.07 |   14781 |       |       |          |
|  10 |     5 |           NESTED LOOPS                  |                                |      1 |      1 |   2304 |00:00:00.05 |    7867 |       |       |          |
|* 11 |     2 |            TABLE ACCESS BY INDEX ROWID  | LV_URBAN_TOPAY_TMP             |      1 |      1 |   2304 |00:00:00.02 |     953 |       |       |          |
|* 12 |     1 |             INDEX RANGE SCAN            | IDX_LV_URBAN_TOPAY_TMP_CORP_ID |      1 |    954 |   6986 |00:00:00.01 |      33 |       |       |          |
|  13 |     4 |            TABLE ACCESS BY INDEX ROWID  | LV_BUSI_ASSIGN                 |   2304 |      1 |   2304 |00:00:00.02 |    6914 |       |       |          |
|* 14 |     3 |             INDEX UNIQUE SCAN           | PK_LV_BUSI_ASSIGN              |   2304 |      1 |   2304 |00:00:00.01 |    4610 |       |       |          |
|  15 |     7 |           TABLE ACCESS BY INDEX ROWID   | LV_BUSI_RECORD                 |   2304 |      1 |   2304 |00:00:00.02 |    6914 |       |       |          |
|* 16 |     6 |            INDEX UNIQUE SCAN            | PK_LV_BUSI_RECORD              |   2304 |      1 |   2304 |00:00:00.01 |    4610 |       |       |          |
|* 17 |    10 |          TABLE ACCESS BY INDEX ROWID    | LV_BUSI_BILL                   |   2304 |      1 |   2304 |00:00:00.02 |    6914 |       |       |          |
|* 18 |     9 |           INDEX UNIQUE SCAN             | PK_LV_BUSI_BILL                |   2304 |      1 |   2304 |00:00:00.01 |    4610 |       |       |          |
|* 19 |    24 |         TABLE ACCESS BY INDEX ROWID     | BS_INSURED                     |   2304 |      1 |   2304 |00:00:00.15 |   45375 |       |       |          |
|* 20 |    23 |          INDEX UNIQUE SCAN              | PK_BS_INSURED                  |   2304 |      1 |   2304 |00:00:00.13 |   43071 |       |       |          |
|  21 |    22 |           NESTED LOOPS                  |                                |   2304 |      1 |   2304 |00:00:00.11 |   38461 |       |       |          |
|  22 |    19 |            NESTED LOOPS                 |                                |   2304 |      1 |   2304 |00:00:00.06 |   27648 |       |       |          |
|  23 |    16 |             NESTED LOOPS                |                                |   2304 |      1 |   2304 |00:00:00.04 |   18432 |       |       |          |
|  24 |    13 |              TABLE ACCESS BY INDEX ROWID| LV_BUSI_ASSIGN                 |   2304 |      1 |   2304 |00:00:00.02 |    9216 |       |       |          |
|* 25 |    12 |               INDEX UNIQUE SCAN         | PK_LV_BUSI_ASSIGN              |   2304 |      1 |   2304 |00:00:00.01 |    6912 |       |       |          |
|  26 |    15 |              TABLE ACCESS BY INDEX ROWID| LV_BUSI_RECORD                 |   2304 |   1679K|   2304 |00:00:00.02 |    9216 |       |       |          |
|* 27 |    14 |               INDEX UNIQUE SCAN         | PK_LV_BUSI_RECORD              |   2304 |      1 |   2304 |00:00:00.01 |    6912 |       |       |          |
|* 28 |    18 |             TABLE ACCESS BY INDEX ROWID | LV_BUSI_BILL                   |   2304 |  83405 |   2304 |00:00:00.02 |    9216 |       |       |          |
|* 29 |    17 |              INDEX UNIQUE SCAN          | PK_LV_BUSI_BILL                |   2304 |      1 |   2304 |00:00:00.01 |    6912 |       |       |          |
|* 30 |    21 |            TABLE ACCESS BY INDEX ROWID  | LV_URBAN_TOPAY_TMP             |   2304 |      1 |   2304 |00:00:00.04 |   10813 |       |       |          |
|* 31 |    20 |             INDEX RANGE SCAN            | IDX_LV_URBAN_TOPAY_TMP_INDI    |   2304 |     12 |   7564 |00:00:00.02 |    6920 |       |       |          |
|* 32 |    27 |        TABLE ACCESS BY INDEX ROWID      | BS_FAMILY                      |   2304 |      1 |   2304 |00:00:00.02 |    6914 |       |       |          |
|* 33 |    26 |         INDEX UNIQUE SCAN               | PK_BS_FAMILY                   |   2304 |      1 |   2304 |00:00:00.01 |    4610 |       |       |          |
|  34 |    30 |       TABLE ACCESS BY INDEX ROWID       | BS_PERSON_TYPE                 |   2304 |      1 |   2304 |00:00:00.01 |    2306 |       |       |          |
|* 35 |    29 |        INDEX UNIQUE SCAN                | PK_BS_PERSON_TYPE              |   2304 |      1 |   2304 |00:00:00.01 |       2 |       |       |          |
|* 36 |    32 |      INDEX UNIQUE SCAN                  | INDEX_BS_PRES_INSUR_UNIQUE     |   2304 |      1 |   2304 |00:00:00.01 |    4610 |       |       |          |
|  37 |    39 |     VIEW PUSHED PREDICATE               |                                |   2304 |      1 |   2297 |00:00:00.06 |   13556 |       |       |          |
|  38 |    38 |      NESTED LOOPS                       |                                |   2304 |      1 |   2297 |00:00:00.05 |   13556 |       |       |          |
|* 39 |    35 |       TABLE ACCESS BY INDEX ROWID       | BS_PERS_HOSP                   |   2304 |      1 |   2297 |00:00:00.04 |    8960 |       |       |          |
|* 40 |    34 |        INDEX RANGE SCAN                 | PK_BS_PERS_HOSP                |   2304 |      2 |   4327 |00:00:00.02 |    4633 |       |       |          |
|  41 |    37 |       TABLE ACCESS BY INDEX ROWID       | BS_HOSPITAL                    |   2297 |      1 |   2297 |00:00:00.01 |    4596 |       |       |          |
|* 42 |    36 |        INDEX UNIQUE SCAN                | PK_BS_HOSPITAL                 |   2297 |      1 |   2297 |00:00:00.01 |    2299 |       |       |          |
|  43 |    42 |    TABLE ACCESS BY INDEX ROWID          | BS_SEX                         |   2304 |      1 |   2304 |00:00:00.01 |    2306 |       |       |          |
|* 44 |    41 |     INDEX UNIQUE SCAN                   | PK_BS_SEX                      |   2304 |      1 |   2304 |00:00:00.01 |       2 |       |       |          |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
-----------------------------------------------------------

  11 - filter(("LT"."FAC_PAY_DATE">=TO_DATE(' 2014-12-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "LT"."CENTER_ID"='430726' AND
              "LT"."POLICY_ITEM_CODE" LIKE '%INDI_TOPAY' AND "LT"."FAC_PAY_DATE" IS NOT NULL AND "LT"."BUSI_ASG_NO" IS NOT NULL AND NVL("LT"."BUSI_ASG_NO",0)<>0 AND
              NVL("LT"."BUSI_ASG_NO",0)<>(-980) AND NVL("LT"."BUSI_ASG_NO",0)<>(-981) AND NVL("LT"."BUSI_ASG_NO",0)<>(-997) AND NVL("LT"."BUSI_ASG_NO",0)<>(-998)
              AND NVL("LT"."BUSI_ASG_NO",0)<>(-999) AND "LT"."FAC_PAY_DATE"< =TO_DATE(' 2015-01-05 23:59:59', 'syyyy-mm-dd hh24:mi:ss')))
  12 - access("LT"."CORP_ID"=19159 AND "LT"."CURR_YEAR"='2015')
  14 - access("LT"."BUSI_ASG_NO"="LBA"."BUSI_ASG_NO")
  16 - access("LBR"."BUSI_RECO_NO"="LBA"."BUSI_RECO_NO")
  17 - filter("LBB"."CENTER_ID"='430726')
  18 - access("LBR"."BUSI_BILL_SN"="LBB"."BUSI_BILL_SN")
  19 - filter(("BI"."FAMILY_ID" IS NOT NULL AND "BI"."INDI_STA"=1))
  20 - access("BI"."INDI_ID"="LT"."INDI_ID")
       filter( IS NOT NULL)
  25 - access("LBA"."BUSI_ASG_NO"=:B1)
  27 - access("LBR"."BUSI_RECO_NO"="LBA"."BUSI_RECO_NO")
  28 - filter("LBB"."CENTER_ID"='430726')
  29 - access("LBR"."BUSI_BILL_SN"="LBB"."BUSI_BILL_SN")
  30 - filter(("LUTT"."BUSI_ASG_NO"=:B1 AND "LUTT"."CORP_ID"=19159 AND "LUTT"."CENTER_ID"='430726'))
  31 - access("LUTT"."INDI_ID"=:B1)
  32 - filter(("BF"."CORP_ID"=19159 AND "BF"."CENTER_ID"='430726' AND "BF"."FAMILY_STA"=1))
  33 - access("BF"."FAMILY_ID"="BI"."FAMILY_ID")
  35 - access("PT"."PERS_TYPE"="BI"."PERS_TYPE" AND "PT"."CENTER_ID"='430726')
  36 - access("BPI"."INDI_ID"="BI"."INDI_ID" AND "BPI"."INSR_DETAIL_CODE"=21 AND "BPI"."INDI_JOIN_STA"=1)
  39 - filter("BPH"."END_YEAR"='2015')
  40 - access("BPH"."INDI_ID"="BI"."INDI_ID" AND "BPH"."FIRST_FLAG"=1)
       filter("BPH"."FIRST_FLAG"=1)
  42 - access("BPH"."HOSPITAL_ID"="BH"."HOSPITAL_ID")
  44 - access("BS"."SEX"=TO_NUMBER("BI"."SEX"))

现在由于没有办法修改代码,所以选择使用SQL Profile来固定该SQL的执行计划。生成SQL Profile有两种方法,这里使用手工生成SQL Profile。使用coe_xfr_sql_profile.sql脚本先对原SQL语句生成SQL Profile文件。

SQL> @/oracle/sqlt/utl/coe_xfr_sql_profile.sql

Parameter 1:
SQL_ID (required)

Enter value for 1: 36cbabzyq13gy


PLAN_HASH_VALUE AVG_ET_SECS
--------------- -----------
     1849931106    6280.149

Parameter 2:
PLAN_HASH_VALUE (required)

Enter value for 2: 1849931106

Values passed to coe_xfr_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID         : "36cbabzyq13gy"
PLAN_HASH_VALUE: "1849931106"

SQL>BEGIN
  2    IF :sql_text IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;
SQL>BEGIN
  2    IF :other_xml IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;

Execute coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql
on TARGET system in order to create a custom SQL Profile
with plan 1849931106 linked to adjusted sql_text.


对去掉Hint后的SQL生成SQL Profile

SQL>@E:\scripts\ch\coe_xfr_sql_profile.sql

Parameter 1:
SQL_ID (required)

输入 1 的值:  46fc6316z15mh


PLAN_HASH_VALUE AVG_ET_SECS
--------------- -----------
     3748535674        1.24

Parameter 2:
PLAN_HASH_VALUE (required)

输入 2 的值:  3748535674

Values passed to coe_xfr_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID         : "46fc6316z15mh"
PLAN_HASH_VALUE: "3748535674"

SQL>BEGIN
  2    IF :sql_text IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not
found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;
SQL>BEGIN
  2    IF :other_xml IS NULL THEN
  3      RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&pl
an_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).
');
  4    END IF;
  5  END;
  6  /
SQL>SET TERM OFF;

Execute coe_xfr_sql_profile_46fc6316z15mh_3748535674.sql
on TARGET system in order to create a custom SQL Profile
with plan 3748535674 linked to adjusted sql_text.

原SQL的SQL Profile文件coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql中有如下记录:

h := SYS.SQLPROF_ATTR(
q'[BEGIN_OUTLINE_DATA]',
q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
q'[OPTIMIZER_FEATURES_ENABLE('10.2.0.4')]',
q'[OPT_PARAM('optimizer_index_cost_adj' 20)]',
q'[OPT_PARAM('optimizer_index_caching' 90)]',
q'[ALL_ROWS]',
q'[OUTLINE_LEAF(@"SEL$3")]',
q'[OUTLINE_LEAF(@"SEL$639F1A6F")]',
q'[PUSH_PRED(@"SEL$1" "TAB_HOSP"@"SEL$1" 12)]',
q'[OUTLINE_LEAF(@"SEL$1")]',
q'[OUTLINE(@"SEL$3")]',
q'[OUTLINE(@"SEL$2")]',
q'[OUTLINE(@"SEL$1")]',
q'[INDEX_RS_ASC(@"SEL$1" "LT"@"SEL$1" ("LV_URBAN_TOPAY_TMP"."CORP_ID" "LV_URBAN_TOPAY_TMP"."CURR_YEAR" "LV_URBAN_TOPAY_TMP"."PERS_TYPE"))]',
q'[INDEX_RS_ASC(@"SEL$1" "LBA"@"SEL$1" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))]',
q'[INDEX_RS_ASC(@"SEL$1" "LBR"@"SEL$1" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))]',
q'[INDEX_RS_ASC(@"SEL$1" "LBB"@"SEL$1" ("LV_BUSI_BILL"."BUSI_BILL_SN"))]',
q'[INDEX_RS_ASC(@"SEL$1" "BI"@"SEL$1" ("BS_INSURED"."INDI_ID"))]',
q'[INDEX_RS_ASC(@"SEL$1" "BF"@"SEL$1" ("BS_FAMILY"."FAMILY_ID"))]',
q'[INDEX_RS_ASC(@"SEL$1" "PT"@"SEL$1" ("BS_PERSON_TYPE"."PERS_TYPE" "BS_PERSON_TYPE"."CENTER_ID"))]',
q'[INDEX(@"SEL$1" "BPI"@"SEL$1" ("BS_PRES_INSUR"."INDI_ID" "BS_PRES_INSUR"."INSR_DETAIL_CODE" "BS_PRES_INSUR"."INDI_JOIN_STA"))]',
q'[NO_ACCESS(@"SEL$1" "TAB_HOSP"@"SEL$1")]',
q'[INDEX_RS_ASC(@"SEL$1" "BS"@"SEL$1" ("BS_SEX"."SEX"))]',
q'[LEADING(@"SEL$1" "LT"@"SEL$1" "LBA"@"SEL$1" "LBR"@"SEL$1" "LBB"@"SEL$1" "BI"@"SEL$1" "BF"@"SEL$1" "PT"@"SEL$1" "BPI"@"SEL$1" "TAB_HOSP"@"SEL$1" "BS"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "LBA"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "LBR"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "LBB"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BI"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BF"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "PT"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BPI"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "TAB_HOSP"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BS"@"SEL$1")]',
q'[INDEX_RS_ASC(@"SEL$639F1A6F" "BPH"@"SEL$2" ("BS_PERS_HOSP"."INDI_ID" "BS_PERS_HOSP"."HOSPITAL_ID" "BS_PERS_HOSP"."FIRST_FLAG" "BS_PERS_HOSP"."BEG_YEAR" "BS_PERS_HOSP"."BIZ_TYPE"))]',
q'[INDEX_RS_ASC(@"SEL$639F1A6F" "BH"@"SEL$2" ("BS_HOSPITAL"."HOSPITAL_ID"))]',
q'[LEADING(@"SEL$639F1A6F" "BPH"@"SEL$2" "BH"@"SEL$2")]',
q'[USE_NL(@"SEL$639F1A6F" "BH"@"SEL$2")]',
q'[INDEX_RS_ASC(@"SEL$3" "LBA"@"SEL$3" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))]',
q'[INDEX_RS_ASC(@"SEL$3" "LBR"@"SEL$3" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))]',
q'[INDEX_RS_ASC(@"SEL$3" "LBB"@"SEL$3" ("LV_BUSI_BILL"."BUSI_BILL_SN"))]',
q'[INDEX_RS_ASC(@"SEL$3" "LUTT"@"SEL$3" ("LV_URBAN_TOPAY_TMP"."INDI_ID"))]',
q'[LEADING(@"SEL$3" "LBA"@"SEL$3" "LBR"@"SEL$3" "LBB"@"SEL$3" "LUTT"@"SEL$3")]',
q'[USE_NL(@"SEL$3" "LBR"@"SEL$3")]',
q'[USE_NL(@"SEL$3" "LBB"@"SEL$3")]',
q'[USE_NL(@"SEL$3" "LUTT"@"SEL$3")]',
q'[END_OUTLINE_DATA]');

用去掉Hint后SQL语句所对应的SQL Profile文件coe_xfr_sql_profile_46fc6316z15mh_3748535674.sql中的如下记录替换coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql文件中上述内容:

h := SYS.SQLPROF_ATTR(
q'[BEGIN_OUTLINE_DATA]',
q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
q'[OPTIMIZER_FEATURES_ENABLE('10.2.0.4')]',
q'[OPT_PARAM('optimizer_index_cost_adj' 20)]',
q'[OPT_PARAM('optimizer_index_caching' 90)]',
q'[ALL_ROWS]',
q'[OUTLINE_LEAF(@"SEL$3")]',
q'[OUTLINE_LEAF(@"SEL$639F1A6F")]',
q'[PUSH_PRED(@"SEL$1" "TAB_HOSP"@"SEL$1" 12)]',
q'[OUTLINE_LEAF(@"SEL$1")]',
q'[OUTLINE(@"SEL$3")]',
q'[OUTLINE(@"SEL$2")]',
q'[OUTLINE(@"SEL$1")]',
q'[INDEX_RS_ASC(@"SEL$1" "LT"@"SEL$1" ("LV_URBAN_TOPAY_TMP"."CORP_ID" "LV_URBAN_TOPAY_TMP"."CURR_YEAR" "LV_URBAN_TOPAY_TMP"."PERS_TYPE"))]',
q'[INDEX_RS_ASC(@"SEL$1" "LBA"@"SEL$1" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))]',
q'[INDEX_RS_ASC(@"SEL$1" "LBR"@"SEL$1" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))]',
q'[INDEX_RS_ASC(@"SEL$1" "LBB"@"SEL$1" ("LV_BUSI_BILL"."BUSI_BILL_SN"))]',
q'[INDEX_RS_ASC(@"SEL$1" "BI"@"SEL$1" ("BS_INSURED"."INDI_ID"))]',
q'[INDEX_RS_ASC(@"SEL$1" "BF"@"SEL$1" ("BS_FAMILY"."FAMILY_ID"))]',
q'[INDEX_RS_ASC(@"SEL$1" "PT"@"SEL$1" ("BS_PERSON_TYPE"."PERS_TYPE" "BS_PERSON_TYPE"."CENTER_ID"))]',
q'[INDEX(@"SEL$1" "BPI"@"SEL$1" ("BS_PRES_INSUR"."INDI_ID" "BS_PRES_INSUR"."INSR_DETAIL_CODE" "BS_PRES_INSUR"."INDI_JOIN_STA"))]',
q'[NO_ACCESS(@"SEL$1" "TAB_HOSP"@"SEL$1")]',
q'[INDEX_RS_ASC(@"SEL$1" "BS"@"SEL$1" ("BS_SEX"."SEX"))]',
q'[LEADING(@"SEL$1" "LT"@"SEL$1" "LBA"@"SEL$1" "LBR"@"SEL$1" "LBB"@"SEL$1" "BI"@"SEL$1" "BF"@"SEL$1" "PT"@"SEL$1" "BPI"@"SEL$1" "TAB_HOSP"@"SEL$1" "BS"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "LBA"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "LBR"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "LBB"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BI"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BF"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "PT"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BPI"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "TAB_HOSP"@"SEL$1")]',
q'[USE_NL(@"SEL$1" "BS"@"SEL$1")]',
q'[INDEX_RS_ASC(@"SEL$639F1A6F" "BPH"@"SEL$2" ("BS_PERS_HOSP"."INDI_ID" "BS_PERS_HOSP"."HOSPITAL_ID" "BS_PERS_HOSP"."FIRST_FLAG" "BS_PERS_HOSP"."BEG_YEAR" "BS_PERS_HOSP"."BIZ_TYPE"))]',
q'[INDEX_RS_ASC(@"SEL$639F1A6F" "BH"@"SEL$2" ("BS_HOSPITAL"."HOSPITAL_ID"))]',
q'[LEADING(@"SEL$639F1A6F" "BPH"@"SEL$2" "BH"@"SEL$2")]',
q'[USE_NL(@"SEL$639F1A6F" "BH"@"SEL$2")]',
q'[INDEX_RS_ASC(@"SEL$3" "LBA"@"SEL$3" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))]',
q'[INDEX_RS_ASC(@"SEL$3" "LBR"@"SEL$3" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))]',
q'[INDEX_RS_ASC(@"SEL$3" "LBB"@"SEL$3" ("LV_BUSI_BILL"."BUSI_BILL_SN"))]',
q'[INDEX_RS_ASC(@"SEL$3" "LUTT"@"SEL$3" ("LV_URBAN_TOPAY_TMP"."INDI_ID"))]',
q'[LEADING(@"SEL$3" "LBA"@"SEL$3" "LBR"@"SEL$3" "LBB"@"SEL$3" "LUTT"@"SEL$3")]',
q'[USE_NL(@"SEL$3" "LBR"@"SEL$3")]',
q'[USE_NL(@"SEL$3" "LBB"@"SEL$3")]',
q'[USE_NL(@"SEL$3" "LUTT"@"SEL$3")]',
q'[END_OUTLINE_DATA]');

替换后保存coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql文件,并执行该文件:

SQL>@C:\Users\Administrator\coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql
SQL>REM
SQL>REM $Header: 215187.1 coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql 11.4.
3.5 2015/01/05 carlos.sierra $
SQL>REM
SQL>REM Copyright (c) 2000-2011, Oracle Corporation. All rights reserved.
SQL>REM
SQL>REM AUTHOR
SQL>REM   carlos.sierra@oracle.com
SQL>REM
SQL>REM SCRIPT
SQL>REM   coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql
SQL>REM
SQL>REM DESCRIPTION
SQL>REM   This script is generated by coe_xfr_sql_profile.sql
SQL>REM   It contains the SQL*Plus commands to create a custom
SQL>REM   SQL Profile for SQL_ID 36cbabzyq13gy based on plan hash
SQL>REM   value 1849931106.
SQL>REM   The custom SQL Profile to be created by this script
SQL>REM   will affect plans for SQL commands with signature
SQL>REM   matching the one for SQL Text below.
SQL>REM   Review SQL Text and adjust accordingly.
SQL>REM
SQL>REM PARAMETERS
SQL>REM   None.
SQL>REM
SQL>REM EXAMPLE
SQL>REM   SQL> START coe_xfr_sql_profile_36cbabzyq13gy_1849931106.sql;
SQL>REM
SQL>REM NOTES
SQL>REM   1. Should be run as SYSTEM or SYSDBA.
SQL>REM   2. User must have CREATE ANY SQL PROFILE privilege.
SQL>REM   3. SOURCE and TARGET systems can be the same or similar.
SQL>REM   4. To drop this custom SQL Profile after it has been created:
SQL>REM  EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_36cbabzyq13gy_1849931106');
SQL>REM   5. Be aware that using DBMS_SQLTUNE requires a license
SQL>REM  for the Oracle Tuning Pack.
SQL>REM
SQL>WHENEVER SQLERROR EXIT SQL.SQLCODE;
SQL>REM
SQL>VAR signature NUMBER;
SQL>REM
SQL>DECLARE
  2  sql_txt CLOB;
  3  h       SYS.SQLPROF_ATTR;
  4  BEGIN
  5  sql_txt := q'[
  6  SELECT /*+ index(lt,
  7  PK_LV_URBAN_TOPAY_TMP)
  8  */                 bi.indi_id,
  9  bi.name,
 10  pt.pers_name,
 11  bs.sex_name,
 12  lt.pay_money,
 13  bi.idcard,
 14  bi.birthday,
 15  bf.headed_name,
 16  lt.fac_pay_date,
 17  lbb.audit_man,
 18  tab_hosp.hospital_name as hospital_name,
 19  to_char(lbb.make_bill_tm,
 20  'yyyy-mm-dd')
 21  as make_bill_tm,
 22  bf.telephone,
 23  nvl((decode(lt.intensive_disability_flag,
 24  1,
 25  decode(lt.lowflag,
 26  1,
 27  '重症伤残,
 28  ',
 29  '重症伤残')
 30  ,
 31  '')
 32  ||                 decode(lt.lowflag,
 33  1,
 34  decode(lt.nothing_flag,
 35  1,
 36  '低保,
 37  ',
 38  '低保')
 39  ,
 40  '')
 41  ||                 decode(lt.nothing_flag,
 42  1,
 43  '三无',
 44  '')
 45  )
 46  ,
 47  '标准')
 48  as subsidykide           FROM lv_urban_topay_tmp lt,
 49  bs_insured         bi,
 50  bs_sex             bs,
 51  bs_person_type     pt,
 52  bs_pres_insur      bpi,
 53  bs_family          bf,
 54  lv_busi_bill       lbb,
 55  lv_busi_record     lbr,
 56  lv_busi_assign     lba,
 57  (select bh.hospital_name,
 58  bph.indi_id        from bs_pers_hosp bph,
 59  bs_hospital bh        where bph.hospital_id = bh.hospital_id        and bph
.first_flag = 1       and bph.end_year = '2015')
 60  tab_hosp           WHERE nvl(lt.busi_asg_no,
 61  0)
 62  <> 0             AND nvl(lt.busi_asg_no,
 63  0)
 64  not in (-999,
 65  -998,
 66  -997,
 67  -981,
 68  -980)
 69  AND lt.fac_pay_date is not null             AND bi.indi_id = lt.indi_id
         AND bs.sex = bi.sex             AND bi.indi_id = tab_hosp.indi_id(+)
 70  AND lbr.busi_reco_no = lba.busi_reco_no                 AND lbr.busi_bill_s
n = lbb.busi_bill_sn                 AND lt.center_id = lbb.center_id
    AND lt.busi_asg_no = lba.busi_asg_no                AND lt.indi_id =  bi.ind
i_id             AND pt.pers_type = bi.pers_type             AND bpi.indi_id = b
i.indi_id             AND lt.center_id = pt.center_id             AND bf.family_
id = bi.family_id            AND bf.family_sta = 1             AND bi.indi_sta =
 1             AND bpi.indi_join_sta = 1            AND bf.center_id = lt.center
_id             AND bf.corp_id = lt.corp_id             AND   lt.policy_item_cod
e like '%INDI_TOPAY'
 71  AND   lt.corp_id='19159'             AND   bpi.insr_detail_code=21
     AND   lt.center_id= '430726'              AND   lt.curr_year= '2015'
    AND  lt.fac_pay_date >= to_date('2014-12-01 00:00:00',
 72  'yyyy-MM-dd hh24:mi:ss')
 73  AND  lt.fac_pay_date < = to_date('2015-01-05 23:59:59',
 74  'yyyy-MM-dd hh24:mi:ss')
 75  and exists             (select 'X' FROM lv_busi_bill       lbb,
 76  lv_busi_record     lbr,
 77  lv_busi_assign     lba,
 78  lv_urban_topay_tmp lutt           WHERE lbr.busi_reco_no = lba.busi_reco_no
             AND lbr.busi_bill_sn = lbb.busi_bill_sn               AND   lbb.cen
ter_id= '430726'             AND   lutt.corp_id='19159'            AND lutt.cent
er_id = lbb.center_id             AND lutt.busi_asg_no = lba.busi_asg_no
      and  lba.busi_asg_no  =   lt.busi_asg_no              and lutt.indi_id =
bi.indi_id)
 79  order by lt.fac_pay_date,
 80  bi.indi_id,
 81  bi.name
 82  ]';
 83  h := SYS.SQLPROF_ATTR(
 84  q'[BEGIN_OUTLINE_DATA]',
 85  q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
 86  q'[OPTIMIZER_FEATURES_ENABLE('10.2.0.4')]',
 87  q'[OPT_PARAM('optimizer_index_cost_adj' 20)]',
 88  q'[OPT_PARAM('optimizer_index_caching' 90)]',
 89  q'[ALL_ROWS]',
 90  q'[OUTLINE_LEAF(@"SEL$3")]',
 91  q'[OUTLINE_LEAF(@"SEL$639F1A6F")]',
 92  q'[PUSH_PRED(@"SEL$1" "TAB_HOSP"@"SEL$1" 12)]',
 93  q'[OUTLINE_LEAF(@"SEL$1")]',
 94  q'[OUTLINE(@"SEL$3")]',
 95  q'[OUTLINE(@"SEL$2")]',
 96  q'[OUTLINE(@"SEL$1")]',
 97  q'[INDEX_RS_ASC(@"SEL$1" "LT"@"SEL$1" ("LV_URBAN_TOPAY_TMP"."CORP_ID" "LV_U
RBAN_TOPAY_TMP"."CURR_YEAR" "LV_URBAN_TOPAY_TMP"."PERS_TYPE"))]',
 98  q'[INDEX_RS_ASC(@"SEL$1" "LBA"@"SEL$1" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))]',

 99  q'[INDEX_RS_ASC(@"SEL$1" "LBR"@"SEL$1" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))]'
,
100  q'[INDEX_RS_ASC(@"SEL$1" "LBB"@"SEL$1" ("LV_BUSI_BILL"."BUSI_BILL_SN"))]',
101  q'[INDEX_RS_ASC(@"SEL$1" "BI"@"SEL$1" ("BS_INSURED"."INDI_ID"))]',
102  q'[INDEX_RS_ASC(@"SEL$1" "BF"@"SEL$1" ("BS_FAMILY"."FAMILY_ID"))]',
103  q'[INDEX_RS_ASC(@"SEL$1" "PT"@"SEL$1" ("BS_PERSON_TYPE"."PERS_TYPE" "BS_PER
SON_TYPE"."CENTER_ID"))]',
104  q'[INDEX(@"SEL$1" "BPI"@"SEL$1" ("BS_PRES_INSUR"."INDI_ID" "BS_PRES_INSUR".
"INSR_DETAIL_CODE" "BS_PRES_INSUR"."INDI_JOIN_STA"))]',
105  q'[NO_ACCESS(@"SEL$1" "TAB_HOSP"@"SEL$1")]',
106  q'[INDEX_RS_ASC(@"SEL$1" "BS"@"SEL$1" ("BS_SEX"."SEX"))]',
107  q'[LEADING(@"SEL$1" "LT"@"SEL$1" "LBA"@"SEL$1" "LBR"@"SEL$1" "LBB"@"SEL$1"
"BI"@"SEL$1" "BF"@"SEL$1" "PT"@"SEL$1" "BPI"@"SEL$1" "TAB_HOSP"@"SEL$1" "BS"@"SE
L$1")]',
108  q'[USE_NL(@"SEL$1" "LBA"@"SEL$1")]',
109  q'[USE_NL(@"SEL$1" "LBR"@"SEL$1")]',
110  q'[USE_NL(@"SEL$1" "LBB"@"SEL$1")]',
111  q'[USE_NL(@"SEL$1" "BI"@"SEL$1")]',
112  q'[USE_NL(@"SEL$1" "BF"@"SEL$1")]',
113  q'[USE_NL(@"SEL$1" "PT"@"SEL$1")]',
114  q'[USE_NL(@"SEL$1" "BPI"@"SEL$1")]',
115  q'[USE_NL(@"SEL$1" "TAB_HOSP"@"SEL$1")]',
116  q'[USE_NL(@"SEL$1" "BS"@"SEL$1")]',
117  q'[INDEX_RS_ASC(@"SEL$639F1A6F" "BPH"@"SEL$2" ("BS_PERS_HOSP"."INDI_ID" "BS
_PERS_HOSP"."HOSPITAL_ID" "BS_PERS_HOSP"."FIRST_FLAG" "BS_PERS_HOSP"."BEG_YEAR"
"BS_PERS_HOSP"."BIZ_TYPE"))]',
118  q'[INDEX_RS_ASC(@"SEL$639F1A6F" "BH"@"SEL$2" ("BS_HOSPITAL"."HOSPITAL_ID"))
]',
119  q'[LEADING(@"SEL$639F1A6F" "BPH"@"SEL$2" "BH"@"SEL$2")]',
120  q'[USE_NL(@"SEL$639F1A6F" "BH"@"SEL$2")]',
121  q'[INDEX_RS_ASC(@"SEL$3" "LBA"@"SEL$3" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))]',

122  q'[INDEX_RS_ASC(@"SEL$3" "LBR"@"SEL$3" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))]'
,
123  q'[INDEX_RS_ASC(@"SEL$3" "LBB"@"SEL$3" ("LV_BUSI_BILL"."BUSI_BILL_SN"))]',
124  q'[INDEX_RS_ASC(@"SEL$3" "LUTT"@"SEL$3" ("LV_URBAN_TOPAY_TMP"."INDI_ID"))]'
,
125  q'[LEADING(@"SEL$3" "LBA"@"SEL$3" "LBR"@"SEL$3" "LBB"@"SEL$3" "LUTT"@"SEL$3
")]',
126  q'[USE_NL(@"SEL$3" "LBR"@"SEL$3")]',
127  q'[USE_NL(@"SEL$3" "LBB"@"SEL$3")]',
128  q'[USE_NL(@"SEL$3" "LUTT"@"SEL$3")]',
129  q'[END_OUTLINE_DATA]');
130  :signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);
131  DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
132  sql_text    => sql_txt,
133  profile     => h,
134  name        => 'coe_36cbabzyq13gy_1849931106',
135  description => 'coe 36cbabzyq13gy 1849931106 '||:signature||'',
136  category    => 'DEFAULT',
137  validate    => TRUE,
138  replace     => TRUE,
139  force_match => TRUE /* TRUE:FORCE (match even when different literals in SQ
L). FALSE:EXACT (similar to CURSOR_SHARING) */ );
140  END;
141  /

PL/SQL 过程已成功完成。

SQL>WHENEVER SQLERROR CONTINUE
SQL>SET ECHO OFF;

            SIGNATURE
---------------------
   718970022444771957


... manual custom SQL Profile has been created


COE_XFR_SQL_PROFILE_36cbabzyq13gy_1849931106 completed

现在我们再来执行原SQL语句来检测SQL Profile是否生效:

SQL>SELECT /*+ index(lt,PK_LV_URBAN_TOPAY_TMP) */
 bi.indi_id,
 bi.name,
 pt.pers_name,
 bs.sex_name,
 lt.pay_money,
 bi.idcard,
 bi.birthday,
 bf.headed_name,
 lt.fac_pay_date,
 lbb.audit_man,
 tab_hosp.hospital_name as hospital_name,
 to_char(lbb.make_bill_tm, 'yyyy-mm-dd') as make_bill_tm,
 bf.telephone,
 nvl((decode(lt.intensive_disability_flag,
             1,
             decode(lt.lowflag, 1, '重症伤残,', '重症伤残'),
             '') ||
     decode(lt.lowflag, 1, decode(lt.nothing_flag, 1, '低保,', '低保'), '') ||
     decode(lt.nothing_flag, 1, '三无', '')),
     '标准') as subsidykide
  FROM lv_urban_topay_tmp lt,
       bs_insured bi,
       bs_sex bs,
       bs_person_type pt,
       bs_pres_insur bpi,
       bs_family bf,
       lv_busi_bill lbb,
       lv_busi_record lbr,
       lv_busi_assign lba,
       (select bh.hospital_name, bph.indi_id
          from bs_pers_hosp bph, bs_hospital bh
         where bph.hospital_id = bh.hospital_id
           and bph.first_flag = 1
           and bph.end_year = '2015') tab_hosp
 WHERE nvl(lt.busi_asg_no, 0) <> 0
   AND nvl(lt.busi_asg_no, 0) not in (-999, -998, -997, -981, -980)
   AND lt.fac_pay_date is not null
   AND bi.indi_id = lt.indi_id
   AND bs.sex = bi.sex
   AND bi.indi_id = tab_hosp.indi_id(+)
   AND lbr.busi_reco_no = lba.busi_reco_no
   AND lbr.busi_bill_sn = lbb.busi_bill_sn
   AND lt.center_id = lbb.center_id
   AND lt.busi_asg_no = lba.busi_asg_no
   AND lt.indi_id = bi.indi_id
   AND pt.pers_type = bi.pers_type
   AND bpi.indi_id = bi.indi_id
   AND lt.center_id = pt.center_id
   AND bf.family_id = bi.family_id
   AND bf.family_sta = 1
   AND bi.indi_sta = 1
   AND bpi.indi_join_sta = 1
   AND bf.center_id = lt.center_id
   AND bf.corp_id = lt.corp_id
   AND lt.policy_item_code like '%INDI_TOPAY'
   AND lt.corp_id = '19159'
   AND bpi.insr_detail_code = 21
   AND lt.center_id = '430726'
   AND lt.curr_year = '2015'
   AND lt.fac_pay_date >= to_date('2014-12-01 00:00:00',
                                  'yyyy-MM-dd hh24:mi:ss')
   AND lt.fac_pay_date < =
       to_date('2015-01-05 23:59:59', 'yyyy-MM-dd hh24:mi:ss')
   and exists (select 'X'
          FROM lv_busi_bill       lbb,
               lv_busi_record     lbr,
               lv_busi_assign     lba,
               lv_urban_topay_tmp lutt
         WHERE lbr.busi_reco_no = lba.busi_reco_no
           AND lbr.busi_bill_sn = lbb.busi_bill_sn
           AND lbb.center_id = '430726'
           AND lutt.corp_id = '19159'
           AND lutt.center_id = lbb.center_id
           AND lutt.busi_asg_no = lba.busi_asg_no
           and lba.busi_asg_no = lt.busi_asg_no
           and lutt.indi_id = bi.indi_id)
 order by lt.fac_pay_date, bi.indi_id, bi.name
...省略输入结果
2304 rows selected.

Elapsed: 00:00:08.08

SQL> select * from table(dbms_xplan.display_cursor('3z8rmv9d64xyx',0,'advanced'));                                                                           

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  3z8rmv9d64xyx, child number 0
-------------------------------------
SELECT /*+ index(lt,PK_LV_URBAN_TOPAY_TMP) */  bi.indi_id,  bi.name,  pt.pers_name,  bs.sex_name,  lt.pay_money,
bi.idcard,  bi.birthday,  bf.headed_name,  lt.fac_pay_date,  lbb.audit_man,  tab_hosp.hospital_name as
hospital_name,  to_char(lbb.make_bill_tm, 'yyyy-mm-dd') as make_bill_tm,  bf.telephone,
nvl((decode(lt.intensive_disability_flag,              1,              decode(lt.lowflag, 1, '重症伤残,', '重症伤残'),
          '') ||      decode(lt.lowflag, 1, decode(lt.nothing_flag, 1, '低保,', '低保'), '') ||
decode(lt.nothing_flag, 1, '三无', '')),      '标准') as subsidykide   FROM lv_urban_topay_tmp lt,        bs_insured
bi,        bs_sex bs,        bs_person_type pt,        bs_pres_insur bpi,        bs_family bf,
lv_busi_bill lbb,        lv_busi_record lbr,        lv_busi_assign lba,        (select bh.hospital_name,
bph.indi_id           from bs_pers_hosp bph, bs_hospital bh          where bph.hospital_id = bh.hospital_id
     and bph.first_flag = 1

Plan hash value: 3748535674

--------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                               | Name                           | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                        |                                |       |       |    88 (100)|          |
|   1 |  SORT ORDER BY                          |                                |     1 |   278 |    88   (2)| 00:00:02 |
|   2 |   NESTED LOOPS                          |                                |     1 |   278 |    82   (0)| 00:00:01 |
|   3 |    NESTED LOOPS OUTER                   |                                |     1 |   272 |    81   (0)| 00:00:01 |
|   4 |     NESTED LOOPS                        |                                |     1 |   231 |    79   (0)| 00:00:01 |
|   5 |      NESTED LOOPS                       |                                |     1 |   219 |    78   (0)| 00:00:01 |
|   6 |       NESTED LOOPS                      |                                |     1 |   201 |    77   (0)| 00:00:01 |
|   7 |        NESTED LOOPS                     |                                |     1 |   169 |    76   (0)| 00:00:01 |
|   8 |         NESTED LOOPS                    |                                |     1 |   113 |    75   (0)| 00:00:01 |
|   9 |          NESTED LOOPS                   |                                |     1 |    88 |    74   (0)| 00:00:01 |
|  10 |           NESTED LOOPS                  |                                |     1 |    77 |    73   (0)| 00:00:01 |
|* 11 |            TABLE ACCESS BY INDEX ROWID  | LV_URBAN_TOPAY_TMP             |     1 |    65 |    72   (0)| 00:00:01 |
|* 12 |             INDEX RANGE SCAN            | IDX_LV_URBAN_TOPAY_TMP_CORP_ID |   954 |       |     1   (0)| 00:00:01 |
|  13 |            TABLE ACCESS BY INDEX ROWID  | LV_BUSI_ASSIGN                 |     1 |    12 |     1   (0)| 00:00:01 |
|* 14 |             INDEX UNIQUE SCAN           | PK_LV_BUSI_ASSIGN              |     1 |       |     1   (0)| 00:00:01 |
|  15 |           TABLE ACCESS BY INDEX ROWID   | LV_BUSI_RECORD                 |     1 |    11 |     1   (0)| 00:00:01 |
|* 16 |            INDEX UNIQUE SCAN            | PK_LV_BUSI_RECORD              |     1 |       |     1   (0)| 00:00:01 |
|* 17 |          TABLE ACCESS BY INDEX ROWID    | LV_BUSI_BILL                   |     1 |    25 |     1   (0)| 00:00:01 |
|* 18 |           INDEX UNIQUE SCAN             | PK_LV_BUSI_BILL                |     1 |       |     1   (0)| 00:00:01 |
|* 19 |         TABLE ACCESS BY INDEX ROWID     | BS_INSURED                     |     1 |    56 |     1   (0)| 00:00:01 |
|* 20 |          INDEX UNIQUE SCAN              | PK_BS_INSURED                  |     1 |       |     1   (0)| 00:00:01 |
|  21 |           NESTED LOOPS                  |                                |     1 |    56 |     5   (0)| 00:00:01 |
|  22 |            NESTED LOOPS                 |                                |     1 |    35 |     3   (0)| 00:00:01 |
|  23 |             NESTED LOOPS                |                                |     1 |    23 |     2   (0)| 00:00:01 |
|  24 |              TABLE ACCESS BY INDEX ROWID| LV_BUSI_ASSIGN                 |     1 |    12 |     1   (0)| 00:00:01 |
|* 25 |               INDEX UNIQUE SCAN         | PK_LV_BUSI_ASSIGN              |     1 |       |     1   (0)| 00:00:01 |
|  26 |              TABLE ACCESS BY INDEX ROWID| LV_BUSI_RECORD                 |     1 |    11 |     1   (0)| 00:00:01 |
|* 27 |               INDEX UNIQUE SCAN         | PK_LV_BUSI_RECORD              |     1 |       |     1   (0)| 00:00:01 |
|* 28 |             TABLE ACCESS BY INDEX ROWID | LV_BUSI_BILL                   |     1 |    12 |     1   (0)| 00:00:01 |
|* 29 |              INDEX UNIQUE SCAN          | PK_LV_BUSI_BILL                |     1 |       |     1   (0)| 00:00:01 |
|* 30 |            TABLE ACCESS BY INDEX ROWID  | LV_URBAN_TOPAY_TMP             |     1 |    21 |     2   (0)| 00:00:01 |
|* 31 |             INDEX RANGE SCAN            | IDX_LV_URBAN_TOPAY_TMP_INDI    |    12 |       |     1   (0)| 00:00:01 |
|* 32 |        TABLE ACCESS BY INDEX ROWID      | BS_FAMILY                      |     1 |    32 |     1   (0)| 00:00:01 |
|* 33 |         INDEX UNIQUE SCAN               | PK_BS_FAMILY                   |     1 |       |     1   (0)| 00:00:01 |
|  34 |       TABLE ACCESS BY INDEX ROWID       | BS_PERSON_TYPE                 |     1 |    18 |     1   (0)| 00:00:01 |
|* 35 |        INDEX UNIQUE SCAN                | PK_BS_PERSON_TYPE              |     1 |       |     1   (0)| 00:00:01 |
|* 36 |      INDEX UNIQUE SCAN                  | INDEX_BS_PRES_INSUR_UNIQUE     |     1 |    12 |     1   (0)| 00:00:01 |
|  37 |     VIEW PUSHED PREDICATE               |                                |     1 |    41 |     2   (0)| 00:00:01 |
|  38 |      NESTED LOOPS                       |                                |     1 |    57 |     2   (0)| 00:00:01 |
|* 39 |       TABLE ACCESS BY INDEX ROWID       | BS_PERS_HOSP                   |     1 |    25 |     1   (0)| 00:00:01 |
|* 40 |        INDEX RANGE SCAN                 | PK_BS_PERS_HOSP                |     2 |       |     1   (0)| 00:00:01 |
|  41 |       TABLE ACCESS BY INDEX ROWID       | BS_HOSPITAL                    |     1 |    32 |     1   (0)| 00:00:01 |
|* 42 |        INDEX UNIQUE SCAN                | PK_BS_HOSPITAL                 |     1 |       |     1   (0)| 00:00:01 |
|  43 |    TABLE ACCESS BY INDEX ROWID          | BS_SEX                         |     1 |     6 |     1   (0)| 00:00:01 |
|* 44 |     INDEX UNIQUE SCAN                   | PK_BS_SEX                      |     1 |       |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------------------------

Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------

   1 - SEL$1
  11 - SEL$1        / LT@SEL$1
  12 - SEL$1        / LT@SEL$1
  13 - SEL$1        / LBA@SEL$1
  14 - SEL$1        / LBA@SEL$1
  15 - SEL$1        / LBR@SEL$1
  16 - SEL$1        / LBR@SEL$1
  17 - SEL$1        / LBB@SEL$1
  18 - SEL$1        / LBB@SEL$1
  19 - SEL$1        / BI@SEL$1
  20 - SEL$1        / BI@SEL$1
  21 - SEL$3
  24 - SEL$3        / LBA@SEL$3
  25 - SEL$3        / LBA@SEL$3
  26 - SEL$3        / LBR@SEL$3
  27 - SEL$3        / LBR@SEL$3
  28 - SEL$3        / LBB@SEL$3
  29 - SEL$3        / LBB@SEL$3
  30 - SEL$3        / LUTT@SEL$3
  31 - SEL$3        / LUTT@SEL$3
  32 - SEL$1        / BF@SEL$1
  33 - SEL$1        / BF@SEL$1
  34 - SEL$1        / PT@SEL$1
  35 - SEL$1        / PT@SEL$1
  36 - SEL$1        / BPI@SEL$1
  37 - SEL$639F1A6F / TAB_HOSP@SEL$1
  38 - SEL$639F1A6F
  39 - SEL$639F1A6F / BPH@SEL$2
  40 - SEL$639F1A6F / BPH@SEL$2
  41 - SEL$639F1A6F / BH@SEL$2
  42 - SEL$639F1A6F / BH@SEL$2
  43 - SEL$1        / BS@SEL$1
  44 - SEL$1        / BS@SEL$1

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
      OPT_PARAM('optimizer_index_cost_adj' 20)
      OPT_PARAM('optimizer_index_caching' 90)
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$3")
      OUTLINE_LEAF(@"SEL$639F1A6F")
      PUSH_PRED(@"SEL$1" "TAB_HOSP"@"SEL$1" 12)
      OUTLINE_LEAF(@"SEL$1")
      OUTLINE(@"SEL$3")
      OUTLINE(@"SEL$2")
      OUTLINE(@"SEL$1")
      INDEX_RS_ASC(@"SEL$1" "LT"@"SEL$1" ("LV_URBAN_TOPAY_TMP"."CORP_ID" "LV_URBAN_TOPAY_TMP"."CURR_YEAR"
              "LV_URBAN_TOPAY_TMP"."PERS_TYPE"))
      INDEX_RS_ASC(@"SEL$1" "LBA"@"SEL$1" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))
      INDEX_RS_ASC(@"SEL$1" "LBR"@"SEL$1" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))
      INDEX_RS_ASC(@"SEL$1" "LBB"@"SEL$1" ("LV_BUSI_BILL"."BUSI_BILL_SN"))
      INDEX_RS_ASC(@"SEL$1" "BI"@"SEL$1" ("BS_INSURED"."INDI_ID"))
      INDEX_RS_ASC(@"SEL$1" "BF"@"SEL$1" ("BS_FAMILY"."FAMILY_ID"))
      INDEX_RS_ASC(@"SEL$1" "PT"@"SEL$1" ("BS_PERSON_TYPE"."PERS_TYPE" "BS_PERSON_TYPE"."CENTER_ID"))
      INDEX(@"SEL$1" "BPI"@"SEL$1" ("BS_PRES_INSUR"."INDI_ID" "BS_PRES_INSUR"."INSR_DETAIL_CODE"
              "BS_PRES_INSUR"."INDI_JOIN_STA"))
      NO_ACCESS(@"SEL$1" "TAB_HOSP"@"SEL$1")
      INDEX_RS_ASC(@"SEL$1" "BS"@"SEL$1" ("BS_SEX"."SEX"))
      LEADING(@"SEL$1" "LT"@"SEL$1" "LBA"@"SEL$1" "LBR"@"SEL$1" "LBB"@"SEL$1" "BI"@"SEL$1" "BF"@"SEL$1" "PT"@"SEL$1"
              "BPI"@"SEL$1" "TAB_HOSP"@"SEL$1" "BS"@"SEL$1")
      USE_NL(@"SEL$1" "LBA"@"SEL$1")
      USE_NL(@"SEL$1" "LBR"@"SEL$1")
      USE_NL(@"SEL$1" "LBB"@"SEL$1")
      USE_NL(@"SEL$1" "BI"@"SEL$1")
      USE_NL(@"SEL$1" "BF"@"SEL$1")
      USE_NL(@"SEL$1" "PT"@"SEL$1")
      USE_NL(@"SEL$1" "BPI"@"SEL$1")
      USE_NL(@"SEL$1" "TAB_HOSP"@"SEL$1")
      USE_NL(@"SEL$1" "BS"@"SEL$1")
      INDEX_RS_ASC(@"SEL$639F1A6F" "BPH"@"SEL$2" ("BS_PERS_HOSP"."INDI_ID" "BS_PERS_HOSP"."HOSPITAL_ID"
              "BS_PERS_HOSP"."FIRST_FLAG" "BS_PERS_HOSP"."BEG_YEAR" "BS_PERS_HOSP"."BIZ_TYPE"))
      INDEX_RS_ASC(@"SEL$639F1A6F" "BH"@"SEL$2" ("BS_HOSPITAL"."HOSPITAL_ID"))
      LEADING(@"SEL$639F1A6F" "BPH"@"SEL$2" "BH"@"SEL$2")
      USE_NL(@"SEL$639F1A6F" "BH"@"SEL$2")
      INDEX_RS_ASC(@"SEL$3" "LBA"@"SEL$3" ("LV_BUSI_ASSIGN"."BUSI_ASG_NO"))
      INDEX_RS_ASC(@"SEL$3" "LBR"@"SEL$3" ("LV_BUSI_RECORD"."BUSI_RECO_NO"))
      INDEX_RS_ASC(@"SEL$3" "LBB"@"SEL$3" ("LV_BUSI_BILL"."BUSI_BILL_SN"))
      INDEX_RS_ASC(@"SEL$3" "LUTT"@"SEL$3" ("LV_URBAN_TOPAY_TMP"."INDI_ID"))
      LEADING(@"SEL$3" "LBA"@"SEL$3" "LBR"@"SEL$3" "LBB"@"SEL$3" "LUTT"@"SEL$3")
      USE_NL(@"SEL$3" "LBR"@"SEL$3")
      USE_NL(@"SEL$3" "LBB"@"SEL$3")
      USE_NL(@"SEL$3" "LUTT"@"SEL$3")
      END_OUTLINE_DATA
  */

Predicate Information (identified by operation id):
---------------------------------------------------

  11 - filter(("LT"."FAC_PAY_DATE">=TO_DATE(' 2014-12-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
              "LT"."CENTER_ID"='430726' AND "LT"."POLICY_ITEM_CODE" LIKE '%INDI_TOPAY' AND "LT"."FAC_PAY_DATE" IS NOT NULL AND
              "LT"."BUSI_ASG_NO" IS NOT NULL AND NVL("LT"."BUSI_ASG_NO",0)<>0 AND NVL("LT"."BUSI_ASG_NO",0)<>(-980) AND
              NVL("LT"."BUSI_ASG_NO",0)<>(-981) AND NVL("LT"."BUSI_ASG_NO",0)<>(-997) AND NVL("LT"."BUSI_ASG_NO",0)<>(-998) AND
              NVL("LT"."BUSI_ASG_NO",0)<>(-999) AND "LT"."FAC_PAY_DATE"< =TO_DATE(' 2015-01-05 23:59:59', 'syyyy-mm-dd
              hh24:mi:ss')))
  12 - access("LT"."CORP_ID"=19159 AND "LT"."CURR_YEAR"='2015')
  14 - access("LT"."BUSI_ASG_NO"="LBA"."BUSI_ASG_NO")
  16 - access("LBR"."BUSI_RECO_NO"="LBA"."BUSI_RECO_NO")
  17 - filter("LBB"."CENTER_ID"='430726')
  18 - access("LBR"."BUSI_BILL_SN"="LBB"."BUSI_BILL_SN")
  19 - filter(("BI"."FAMILY_ID" IS NOT NULL AND "BI"."INDI_STA"=1))
  20 - access("BI"."INDI_ID"="LT"."INDI_ID")
       filter( IS NOT NULL)
  25 - access("LBA"."BUSI_ASG_NO"=:B1)
  27 - access("LBR"."BUSI_RECO_NO"="LBA"."BUSI_RECO_NO")
  28 - filter("LBB"."CENTER_ID"='430726')
  29 - access("LBR"."BUSI_BILL_SN"="LBB"."BUSI_BILL_SN")
  30 - filter(("LUTT"."BUSI_ASG_NO"=:B1 AND "LUTT"."CORP_ID"=19159 AND "LUTT"."CENTER_ID"='430726'))
  31 - access("LUTT"."INDI_ID"=:B1)
  32 - filter(("BF"."CORP_ID"=19159 AND "BF"."CENTER_ID"='430726' AND "BF"."FAMILY_STA"=1))
  33 - access("BF"."FAMILY_ID"="BI"."FAMILY_ID")
  35 - access("PT"."PERS_TYPE"="BI"."PERS_TYPE" AND "PT"."CENTER_ID"='430726')
  36 - access("BPI"."INDI_ID"="BI"."INDI_ID" AND "BPI"."INSR_DETAIL_CODE"=21 AND "BPI"."INDI_JOIN_STA"=1)
  39 - filter("BPH"."END_YEAR"='2015')
  40 - access("BPH"."INDI_ID"="BI"."INDI_ID" AND "BPH"."FIRST_FLAG"=1)
       filter("BPH"."FIRST_FLAG"=1)
  42 - access("BPH"."HOSPITAL_ID"="BH"."HOSPITAL_ID")
  44 - access("BS"."SEX"=TO_NUMBER("BI"."SEX"))

Column Projection Information (identified by operation id):
-----------------------------------------------------------

   1 - (#keys=3) "LT"."FAC_PAY_DATE"[DATE,7], "BI"."INDI_ID"[NUMBER,22], "BI"."NAME"[VARCHAR2,20],
       "BF"."TELEPHONE"[VARCHAR2,20], TO_CHAR(INTERNAL_FUNCTION("LBB"."MAKE_BILL_TM"),'yyyy-mm-dd')[10],
       "PT"."PERS_NAME"[VARCHAR2,20], "BS"."SEX_NAME"[VARCHAR2,5], "LT"."PAY_MONEY"[NUMBER,22],
       "BI"."IDCARD"[VARCHAR2,21], "BI"."BIRTHDAY"[DATE,7], "BF"."HEADED_NAME"[VARCHAR2,50],
       NVL(DECODE("LT"."INTENSIVE_DISABILITY_FLAG",1,DECODE("LT"."LOWFLAG",1,'重症伤残,','重症伤残'),'')||DECODE("LT"."LOWFLAG",1
       ,DECODE("LT"."NOTHING_FLAG",1,'低保,','低保'),'')||DECODE("LT"."NOTHING_FLAG",1,'三无',''),'标准')[18],
       "LBB"."AUDIT_MAN"[VARCHAR2,50], "TAB_HOSP"."HOSPITAL_NAME"[VARCHAR2,70]
   2 - "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22], "LT"."LOWFLAG"[NUMBER,22],
       "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."FAC_PAY_DATE"[DATE,7], "LBB"."MAKE_BILL_TM"[DATE,7],
       "LBB"."AUDIT_MAN"[VARCHAR2,50], "BI"."INDI_ID"[NUMBER,22], "BI"."NAME"[VARCHAR2,20], "BI"."BIRTHDAY"[DATE,7],
       "BI"."IDCARD"[VARCHAR2,21], "BF"."HEADED_NAME"[VARCHAR2,50], "BF"."TELEPHONE"[VARCHAR2,20],
       "PT"."PERS_NAME"[VARCHAR2,20], "TAB_HOSP"."HOSPITAL_NAME"[VARCHAR2,70], "BS"."SEX_NAME"[VARCHAR2,5]
   3 - "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22], "LT"."LOWFLAG"[NUMBER,22],
       "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."FAC_PAY_DATE"[DATE,7], "LBB"."MAKE_BILL_TM"[DATE,7],
       "LBB"."AUDIT_MAN"[VARCHAR2,50], "BI"."INDI_ID"[NUMBER,22], "BI"."NAME"[VARCHAR2,20], "BI"."SEX"[CHARACTER,1],
       "BI"."BIRTHDAY"[DATE,7], "BI"."IDCARD"[VARCHAR2,21], "BF"."HEADED_NAME"[VARCHAR2,50],
       "BF"."TELEPHONE"[VARCHAR2,20], "PT"."PERS_NAME"[VARCHAR2,20], "TAB_HOSP"."HOSPITAL_NAME"[VARCHAR2,70]
   4 - "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22], "LT"."LOWFLAG"[NUMBER,22],
       "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."FAC_PAY_DATE"[DATE,7], "LBB"."MAKE_BILL_TM"[DATE,7],
       "LBB"."AUDIT_MAN"[VARCHAR2,50], "BI"."INDI_ID"[NUMBER,22], "BI"."NAME"[VARCHAR2,20], "BI"."SEX"[CHARACTER,1],
       "BI"."BIRTHDAY"[DATE,7], "BI"."IDCARD"[VARCHAR2,21], "BF"."HEADED_NAME"[VARCHAR2,50],
       "BF"."TELEPHONE"[VARCHAR2,20], "PT"."PERS_NAME"[VARCHAR2,20]
   5 - "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22], "LT"."LOWFLAG"[NUMBER,22],
       "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."FAC_PAY_DATE"[DATE,7], "LBB"."MAKE_BILL_TM"[DATE,7],
       "LBB"."AUDIT_MAN"[VARCHAR2,50], "BI"."INDI_ID"[NUMBER,22], "BI"."NAME"[VARCHAR2,20], "BI"."SEX"[CHARACTER,1],
       "BI"."BIRTHDAY"[DATE,7], "BI"."IDCARD"[VARCHAR2,21], "BF"."HEADED_NAME"[VARCHAR2,50],
       "BF"."TELEPHONE"[VARCHAR2,20], "PT"."PERS_NAME"[VARCHAR2,20]
   6 - "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22], "LT"."LOWFLAG"[NUMBER,22],
       "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."FAC_PAY_DATE"[DATE,7], "LBB"."MAKE_BILL_TM"[DATE,7],
       "LBB"."AUDIT_MAN"[VARCHAR2,50], "BI"."INDI_ID"[NUMBER,22], "BI"."PERS_TYPE"[NUMBER,22], "BI"."NAME"[VARCHAR2,20],
       "BI"."SEX"[CHARACTER,1], "BI"."BIRTHDAY"[DATE,7], "BI"."IDCARD"[VARCHAR2,21], "BF"."HEADED_NAME"[VARCHAR2,50],
       "BF"."TELEPHONE"[VARCHAR2,20]
   7 - "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22], "LT"."LOWFLAG"[NUMBER,22],
       "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."FAC_PAY_DATE"[DATE,7], "LBB"."MAKE_BILL_TM"[DATE,7],
       "LBB"."AUDIT_MAN"[VARCHAR2,50], "BI"."INDI_ID"[NUMBER,22], "BI"."PERS_TYPE"[NUMBER,22], "BI"."NAME"[VARCHAR2,20],
       "BI"."SEX"[CHARACTER,1], "BI"."BIRTHDAY"[DATE,7], "BI"."IDCARD"[VARCHAR2,21], "BI"."FAMILY_ID"[NUMBER,22]
   8 - "LT"."INDI_ID"[NUMBER,22], "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22],
       "LT"."LOWFLAG"[NUMBER,22], "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."BUSI_ASG_NO"[NUMBER,22],
       "LT"."FAC_PAY_DATE"[DATE,7], "LBB"."MAKE_BILL_TM"[DATE,7], "LBB"."AUDIT_MAN"[VARCHAR2,50]
   9 - "LT"."INDI_ID"[NUMBER,22], "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22],
       "LT"."LOWFLAG"[NUMBER,22], "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."BUSI_ASG_NO"[NUMBER,22],
       "LT"."FAC_PAY_DATE"[DATE,7], "LBR"."BUSI_BILL_SN"[NUMBER,22]
  10 - "LT"."INDI_ID"[NUMBER,22], "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22],
       "LT"."LOWFLAG"[NUMBER,22], "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."BUSI_ASG_NO"[NUMBER,22],
       "LT"."FAC_PAY_DATE"[DATE,7], "LBA"."BUSI_RECO_NO"[NUMBER,22]
  11 - "LT"."INDI_ID"[NUMBER,22], "LT"."INTENSIVE_DISABILITY_FLAG"[NUMBER,22], "LT"."PAY_MONEY"[NUMBER,22],
       "LT"."LOWFLAG"[NUMBER,22], "LT"."NOTHING_FLAG"[NUMBER,22], "LT"."BUSI_ASG_NO"[NUMBER,22],
       "LT"."FAC_PAY_DATE"[DATE,7]
  12 - "SYS_ALIAS_1".ROWID[ROWID,10]
  13 - "LBA"."BUSI_RECO_NO"[NUMBER,22]
  14 - "LBA".ROWID[ROWID,10]
  15 - "LBR"."BUSI_BILL_SN"[NUMBER,22]
  16 - "LBR".ROWID[ROWID,10]
  17 - "LBB"."MAKE_BILL_TM"[DATE,7], "LBB"."AUDIT_MAN"[VARCHAR2,50]
  18 - "LBB".ROWID[ROWID,10]
  19 - "BI"."INDI_ID"[NUMBER,22], "BI"."PERS_TYPE"[NUMBER,22], "BI"."NAME"[VARCHAR2,20], "BI"."SEX"[CHARACTER,1],
       "BI"."BIRTHDAY"[DATE,7], "BI"."IDCARD"[VARCHAR2,21], "BI"."FAMILY_ID"[NUMBER,22]
  20 - "SYS_ALIAS_2".ROWID[ROWID,10], "BI"."INDI_ID"[NUMBER,22]
  23 - "LBR"."BUSI_BILL_SN"[NUMBER,22]
  24 - "LBA"."BUSI_RECO_NO"[NUMBER,22]
  25 - "LBA".ROWID[ROWID,10]
  26 - "LBR"."BUSI_BILL_SN"[NUMBER,22]
  27 - "LBR".ROWID[ROWID,10]
  29 - "LBB".ROWID[ROWID,10]
  31 - "LUTT".ROWID[ROWID,10]
  32 - "BF"."HEADED_NAME"[VARCHAR2,50], "BF"."TELEPHONE"[VARCHAR2,20]
  33 - "BF".ROWID[ROWID,10]
  34 - "PT"."PERS_NAME"[VARCHAR2,20]
  35 - "PT".ROWID[ROWID,10]
  37 - "TAB_HOSP"."HOSPITAL_NAME"[VARCHAR2,70]
  38 - "BH"."HOSPITAL_NAME"[VARCHAR2,70]
  39 - "BPH"."HOSPITAL_ID"[VARCHAR2,20]
  40 - "BPH".ROWID[ROWID,10], "BPH"."HOSPITAL_ID"[VARCHAR2,20]
  41 - "BH"."HOSPITAL_NAME"[VARCHAR2,70]
  42 - "BH".ROWID[ROWID,10]
  43 - "BS"."SEX_NAME"[VARCHAR2,5]
  44 - "BS".ROWID[ROWID,10]

Note
-----
   - SQL profile "coe_36cbabzyq13gy_1849931106" used for this statement


276 rows selected.

从Note部分的SQL profile "coe_36cbabzyq13gy_1849931106" used for this statement可知SQL Profile对该SQL生效了,而且从执行计划中可知现在与去掉Hint“/*+ index(lt,PK_LV_URBAN_TOPAY_TMP) */”之后的SQL执行计划一样的。至此,对该SQL的优化也就完成。

这个SQL语句执行缓慢的原因就是因为使用了Hint"/*+ index(lt,PK_LV_URBAN_TOPAY_TMP) */"后,使CBO选择了错误的执行计划而造成的。

使用SQLT来构建Oracle测试用例

在进行性能优化尤其是SQL优化时不能在生产环境进行测试,或者在升级时对SQL语句性能进行测试时,构建一个测试环境很重要,这篇文章介绍使用SQLT工具来快速简单的构建测试用例的方法。其实要使用SQLT来构建一个测试用例不需要额外执行SQLT报告。运行SQLTXTRACT或SQLTXECUTE就能为测试用例创建足够的信息。

例如我要将在aix系统上Oracle 10g中运行的SQL语句在linux系统上Oracle 11g中来测试它的性能时,这就需要构建一个测试用例。要进行测试的语句如下:

select 
nvl(sum(real_pay), 0) as dYearA131
  from mt_biz_fin a, mt_pay_record_fin b, mt_apply c
 where a.hospital_id = b.hospital_id
   and a.serial_no = b.serial_no
   and a.treatment_type = '131'
   and a.indi_id = 5609194
   and a.serial_apply = 135888
   and a.valid_flag = '1'
   and b.valid_flag = '1'
   and a.serial_apply = c.serial_apply
   and c.valid_flag = '1'
   and b.POLICY_ITEM_CODE in ('C000', 'C001', 'C004')
   and exists (select 1
          from mt_pay_record_fin b
         where b.fund_id not in ('003', '999')
           and a.serial_no = b.serial_no);

为sqltxecute.sql脚本创建一个来测试的sql文件

[IBMP740-1:oracle:/oracle/sqlt/input/sample]$vi mysql2.sql

-- execute sqlt xecute as sh passing script name
-- cd sqlt
-- #sqlplus sh
-- SQL> start run/sqltxecute.sql input/sample/script1.sql

REM Optional ALTER SESSION commands
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--ALTER SESSION SET statistics_level = ALL;

REM Optional Binds
REM ~~~~~~~~~~~~~~

VAR b1 NUMBER;
EXEC :b1 := 10;

REM SQL statement to be executed
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SELECT /*+ gather_plan_statistics monitor bind_aware */
       /* ^^unique_id */
"mysql2.sql" 35 lines, 756 characters


       /* ^^unique_id */

nvl(sum(real_pay), 0) as dYearA131
  from mt_biz_fin a, mt_pay_record_fin b, mt_apply c
 where a.hospital_id = b.hospital_id
   and a.serial_no = b.serial_no
   and a.treatment_type = '131'
   and a.indi_id = 5609194
   and a.serial_apply = 135888
   and a.valid_flag = '1'
   and b.valid_flag = '1'
   and a.serial_apply = c.serial_apply
   and c.valid_flag = '1'
   and b.POLICY_ITEM_CODE in ('C000', 'C001', 'C004')
   and exists (select 1
          from mt_pay_record_fin b
         where b.fund_id not in ('003', '999')
           and a.serial_no = b.serial_no);

/
/

REM Notes:
/
/

REM Notes:
REM 1. SQL must contain token: /* ^^unique_id */
"mysql2.sql" 48 lines, 1259 characters 

现在在Oracle 10g中对上面的SQL语句执行sqltxectue.sql来进行性能分析

[IBMP740-1:oracle:/oracle/sqlt/run]$sqlplus /nolog

SQL*Plus: Release 10.2.0.4.0 - Production on Tue Aug 26 09:29:40 2014

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

SQL> conn / as sysdba
Connected.
SQL> @sqltxecute.sql /oracle/sqlt/input/sample/mysql2.sql



PL/SQL procedure successfully completed.



Parameter 1:
SCRIPT name which contains SQL and its binds (required)


Paremeter 2:
SQLTXPLAIN password (required)

Enter value for 2: sqlt

PL/SQL procedure successfully completed.



PL/SQL procedure successfully completed.


Value passed to sqltxecute:
SCRIPT_WITH_SQL: "/oracle/sqlt/input/sample/mysql2.sql"


PL/SQL procedure successfully completed.

***
*** NOTE:
*** If you get error below it means SQLTXPLAIN is not installed:
***   PLS-00201: identifier 'SQLTXADMIN.SQLT$A' must be declared.
*** In such case look for errors in NN_*.log files created during install.
***



SQLT_VERSION
----------------------------------------
SQLT version number: 12.1.09
SQLT version date  : 2014-06-13
Installation date  : 2014-07-29/15:45:43

... please wait ...
  adding: alert_RLZY.log (deflated 93%)

NOTE:
You used the XECUTE method connected as INSUR_CHANGDE.

In case of a session disconnect please verify the following:
1. There are no errors in sqltxecute.log or sqltxecute2.log.
2. Your SQL contains token "^^unique_id" within a comment.
3. Your SQL ends with a semi-colon ";".
4. You connected as the application user that issued original SQL.
5. Script /oracle/sqlt/input/sample/mysql2.sql can execute stand-alone connected as INSUR_CHANGDE
6. User INSUR_CHANGDE has been granted SQLT_USER_ROLE.

In case of errors ORA-03113, ORA-03114 or ORA-07445 please just
re-try this SQLT method. This tool handles some of the errors behind
a disconnect when executed a second time.

To actually diagnose the problem behind the disconnect, read ALERT
log and provide referenced traces to Support. After the root cause
of the disconnect is fixed then reset SQLT corresponding parameter.

... executing /oracle/sqlt/input/sample/mysql2.sql ...

In case of a disconnect review sqltxecute2.log and mysql2_output_s34879.txt


To monitor progress, login into another session and execute:
SQL> SELECT * FROM SQLTXADMIN.sqlt$_log_v;

... collecting diagnostics details, please wait ...

In case of a disconnect review log file in current directory
If running as SYS in 12c make sure to review sqlt_instructions.html first

09:30:47   17 sqlt$a: ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT OFF'
09:30:47    0 sqlt$a: ALTER SESSION SET EVENTS '10046 TRACE NAME CONTEXT FOREVER, LEVEL 8'
09:30:47    0 sqlt$a: skip 10241, 10032, 10033, 10104, 10730, 46049 off as per parameter event_others
09:31:18   31 sqlt$d: collect_gv$sesstat
09:31:18    0 sqlt$d: 760 rows collected
09:31:18    0 sqlt$d: collect_gv$cell_state
09:31:18    0 sqlt$d: 0 rows collected
09:31:18    0 sqlt$d: collect_gv$session_event
09:31:18    0 sqlt$d: 19 rows collected
09:31:18    0 sqlt$d: collect_gv$segment_statistics
09:31:18    0 sqlt$d: 510 rows collected
09:31:18    0 sqlt$d: collect_gv$statname
09:31:18    0 sqlt$d: 380 rows collected
09:31:18    0 sqlt$d: collect_gv$pq_slave
09:31:18    0 sqlt$d: 0 rows collected
09:31:18    0 sqlt$d: collect_gv$pq_sysstat
09:31:18    0 sqlt$d: 32 rows collected
09:31:18    0 sqlt$d: collect_gv$px_process_sysstat
09:31:18    0 sqlt$d: 30 rows collected
09:31:18    0 sqlt$d: collect_gv$px_process
09:31:18    0 sqlt$d: 0 rows collected
09:31:18    0 sqlt$d: collect_gv$px_session
09:31:18    0 sqlt$d: 0 rows collected
09:31:18    0 sqlt$d: collect_gv$pq_sesstat
09:31:18    0 sqlt$d: 22 rows collected
09:31:18    0 sqlt$d: collect_gv$px_sesstat
09:31:18    0 sqlt$d: 0 rows collected
09:31:18    0 sqlt$d: collect_gv$px_instance_group
09:31:18    0 sqlt$d: 0 rows collected
09:31:18    0 sqlt$d: collect_gv$pq_tqstat
09:31:18    0 sqlt$d: 0 rows collected
09:31:18    0 sqlt$d: < = collect_perf_stats_post 09:31:18 0 sqlt$a: ALTER SESSION SET STATISTICS_LEVEL = 'TYPICAL' 09:31:18 0 sqlt$a: -> session_trace_filename
09:31:18    0 sqlt$a: session_trace_filename, current trace_filename
09:31:18    0 sqlt$a: session_trace_filename, current process_name ora
09:31:18    0 sqlt$a: < - session_trace_filename rlzy_ora_3081178_s34879_10046_10053.trc
09:31:18    0 sqlt$a: in udump: "rlzy_ora_3081178_s34879_10046_10053.trc"
09:31:18    0 sqlt$a: in local: "sqlt_s34879_10046_10053_execute.trc"
09:31:18    0 sqlt$a: ALTER SESSION SET TRACEFILE_IDENTIFIER = "S34879_SQLT_TRACE"
09:31:18    0 sqlt$a: timestamp_before: 26-AUG-14 09.30.30.240238 AM +08:00
09:31:18    0 sqlt$a: timestamp_after: 26-AUG-14 09.30.47.115196 AM +08:00
09:31:18    0 sqlt$a: statement_response_time: +00 00:00:16.874958
09:31:18    0 sqlt$a: <= event_10046_10053_off 09:31:18 0 sqlt$d: => capture_sqltext
09:31:18    0 sqlt$d: -> capture_statement
09:31:18    0 sqlt$a: -> find_sql_in_memory_or_awr
09:31:18    0 sqlt$a: -> get_sql_id_or_hash_value
09:31:18    0 sqlt$a: sql_id = "7fv05tum90t4j"
09:31:18    0 sqlt$a: < - get_sql_id_or_hash_value 09:31:18 0 sqlt$a: -> sql_in_memory_or_awr
09:31:18    0 sqlt$a: sql found in memory using sql_id = "7fv05tum90t4j" and string = "sqlt_s34879" (excludes PL/SQL EXECUTE)
09:31:18    0 sqlt$a: hash_value = "2794480785"
09:31:18    0 sqlt$a: SELECT /*+ gather_plan_statistics monitor bind_aware */        /* sqlt_s34879 */ nvl(sum(real_pay), 0) as dYearA131   from mt_biz_fin a, mt_pay_record_fin b, mt_apply c  where a.hospital_id = b.hospital_id    and a.serial_no = b.seri
al_no    and a.treatment_type = '131'    and a.indi_id = 5609194    and a.serial_apply = 135888    and a.valid_flag = '1'    and b.valid_flag = '1'    and a.serial_apply = c.serial_apply    and c.valid_flag = '1'    and b.POLICY_ITEM_CODE in ('C000', 'C00
1', 'C004')    and exists (select 1           from mt_pay_record_fin b          where b.fund_id not in ('003', '999')            and a.serial_no = b.serial_no)
09:31:18    0 sqlt$a: sql not found in awr using sql_id = "7fv05tum90t4j"
09:31:18    0 sqlt$a: < - sql_in_memory_or_awr
09:31:18    0 sqlt$a:  explain_plan_and_10053
09:31:19    0 sqlt$i: sql_length = "631"
09:31:19    0 sqlt$i: => remote_trace_begin
09:31:19    0 sqlt$i: no remote db_links were found/activated at this step
09:31:19    0 sqlt$i: < = remote_trace_begin 09:31:19 0 sqlt$a: -> event_10053_on
09:31:19    0 sqlt$a: ALTER SESSION SET MAX_DUMP_FILE_SIZE = '200M'
09:31:19    0 sqlt$a: ALTER SESSION SET TRACEFILE_IDENTIFIER = "s34879_10053"
09:31:19    0 sqlt$a: ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT FOREVER, LEVEL 1'
09:31:19    0 sqlt$a: ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT OFF'
09:31:19    0 sqlt$a: -> session_trace_filename
09:31:19    0 sqlt$a: session_trace_filename, current trace_filename
09:31:19    0 sqlt$a: session_trace_filename, current process_name ora
09:31:19    0 sqlt$a: < - session_trace_filename rlzy_ora_3081178_s34879_10053.trc
09:31:19    0 sqlt$a: in udump: "rlzy_ora_3081178_s34879_10053.trc"
09:31:19    0 sqlt$a: in local: "sqlt_s34879_10053_explain.trc"
09:31:19    0 sqlt$a: ALTER SESSION SET TRACEFILE_IDENTIFIER = "S34879_SQLT_TRACE"
09:31:19    0 sqlt$a:  clean_sqlt$_sql_plan_table
09:31:19    0 sqlt$a: < - clean_sqlt$_sql_plan_table 09:31:19 0 sqlt$d: -> capture_xplain_plan_hash_value
09:31:19    0 sqlt$d: < - capture_xplain_plan_hash_value "2582817425" for xplain_sql_id "6kxjb1zyt8qdt" with cost of "83997"
09:31:19    0 sqlt$i: <= explain_plan_and_10053 09:31:19 0 sqlt$i: => remote_trace_end
09:31:19    0 sqlt$i: < = remote_trace_end 09:31:19 0 sqlt$d: collect_gv$parameter_cbo 09:31:19 0 sqlt$d: 190 rows collected 09:31:19 0 sqlt$a: -> reset_init_parameters
09:31:19    0 sqlt$a: optimizer_index_cost_adj was "20"
09:31:19    0 sqlt$a: ALTER SESSION SET optimizer_index_cost_adj = 100
09:31:19    0 sqlt$a: < - reset_init_parameters 09:31:19 0 sqlt$d: => diagnostics_data_collection_1
09:31:19    0 sqlt$d: -> collection from memory
09:31:19    0 sqlt$d: sql_id = "7fv05tum90t4j", hash_value = "2794480785"
09:31:19    0 sqlt$d: collect_gv$sql_shared_cursor
09:31:20    1 sqlt$d: 1 rows collected
09:31:20    0 sqlt$d: collect_gv$sql_bind_capture
09:31:20    0 sqlt$d: 0 rows collected
09:31:20    0 sqlt$d: collect_gv$sql_optimizer_env
09:31:20    0 sqlt$d: 1342040 KB -> 1374248960
09:31:20    0 sqlt$d: 5 rows collected
09:31:20    0 sqlt$d: collect_gv$sql_workarea
09:31:20    0 sqlt$d: 1 rows collected
09:31:20    0 sqlt$d: collect_gv$sql_plan_statistics
09:31:20    0 sqlt$d: 11 rows collected
09:31:20    0 sqlt$d: collect_gv$sql_plan
09:31:20    0 sqlt$d: include predicates on plan table (lock).
09:31:20    0 sqlt$d: included predicates on plan table (unlock).
09:31:20    0 sqlt$d: 12 rows collected
09:31:20    0 sqlt$d: collect_gv$sql
09:31:20    0 sqlt$d: 1 rows collected
09:31:20    0 sqlt$d: collect_gv$sqlarea_plan_hash
09:31:20    0 sqlt$d: 1 rows collected
09:31:20    0 sqlt$d: collect_gv$sqlarea
09:31:20    0 sqlt$d: 1 rows collected
09:31:20    0 sqlt$d: collect_gv$sqlstats
09:31:20    0 sqlt$d: 1 rows collected
09:31:20    0 sqlt$d: collect_gv$object_dependency
09:31:20    0 sqlt$d: sql_id="7fv05tum90t4j"
09:31:20    0 sqlt$d: hash_value="2794480785"
09:31:20    0 sqlt$d: xplain_sql_id="6kxjb1zyt8qdt"
09:31:20    0 sqlt$d: root inst_id="1", hash_value="2794480785", address="0700000438927940", depth="0"
09:31:20    0 sqlt$d: root inst_id="1", hash_value="4254357945", address="0700000671675E40", depth="0"
09:31:20    0 sqlt$d: 3 rows collected
09:31:20    0 sqlt$d: collect_gv$vpd_policy
09:31:21    1 sqlt$d: 0 rows collected
09:31:21    0 sqlt$d: collect_gv$active_session_hist
09:31:23    2 sqlt$d: 16 rows collected
09:31:23    0 sqlt$d: collect_dbms_xplan_cursor_last
09:31:24    1 sqlt$d: 0 rows collected
09:31:24    0 sqlt$d: collect_dbms_xplan_cursor_all
09:31:24    0 sqlt$d: 0 rows collected
09:31:24    0 sqlt$d: -> create_tuning_task_memory
09:31:24    0 sqlt$d: task name = "sqlt_s34879_mem"
09:31:24    0 sqlt$d: < - create_tuning_task_memory 09:31:24 0 sqlt$d: -> create_tuning_task_text
09:31:24    0 sqlt$d: parsing_schema_name:INSUR_CHANGDE
09:31:25    1 sqlt$d: task name = "sqlt_s34879_mem"
09:31:25    0 sqlt$d: < - create_tuning_task_text 09:31:25 0 sqlt$d: -> collect_tuning_sets_mem
09:31:25    0 sqlt$d: sqlt$_gv$sql_plan: 2582817425
09:31:25    0 sqlt$d: created sqlset: s34879_2582817425_mem
09:31:26    1 sqlt$d: loaded sqlset: s34879_2582817425_mem
09:31:26    0 sqlt$d: < - collect_tuning_sets_mem
09:31:26    0 sqlt$d:  diagnostics_data_collection_2
09:31:26    0 sqlt$d: sql_id = "7fv05tum90t4j"
09:31:26    0 sqlt$d: in_awr = "N"
09:31:26    0 sqlt$d: s_db_link = ""
09:31:26    0 sqlt$d: collect_dba_hist_snapshot
09:31:26    0 sqlt$d: 179 rows collected
09:31:26    0 sqlt$d: collect_dba_hist_parameter
09:31:28    2 sqlt$d: 47793 rows collected
09:31:28    0 sqlt$d: collect_dba_hist_parameter_m
09:31:28    0 sqlt$d: 88 rows collected
09:31:28    0 sqlt$d: -> expanded collection
09:31:28    0 sqlt$d: collect_gv$parameter2
09:31:28    0 sqlt$d: 263 rows collected
09:31:28    0 sqlt$d: collect_gv$nls_parameters
09:31:28    0 sqlt$d: 19 rows collected
09:31:28    0 sqlt$d: collect_gv$system_parameter
09:31:28    0 sqlt$d: 261 rows collected
09:31:28    0 sqlt$d: collect_nls_database_params
09:31:28    0 sqlt$d: 20 rows collected
09:31:28    0 sqlt$d: collect_v$session_fix_control
09:31:28    0 sqlt$d: 115 rows collected
09:31:28    0 sqlt$d: collect_dba_dependencies
09:31:28    0 sqlt$d: 0 rows collected
09:31:28    0 sqlt$d: list_of_objects
09:31:28    0 sqlt$d: preliminary_list_of_tables
09:31:28    0 sqlt$d: preliminary_list_of_indexes
09:31:28    0 sqlt$d: final_list_of_tables
09:31:30    2 sqlt$d: list_of_fixed_objects
09:31:30    0 sqlt$d: final_list_of_indexes
09:31:30    0 sqlt$d: list_of_other_objects
09:31:30    0 sqlt$d: final_list_of_other_objects
09:31:35    5 sqlt$d: 20 rows collected
09:31:35    0 sqlt$d: collect_schema_object_stats
09:31:35    0 sqlt$d: export table stats
09:31:35    0 sqlt$d: 4762 rows collected
09:31:35    0 sqlt$d: export dictionary stats
09:31:35    0 sqlt$d: dictionary objects stats export skipped because of export_dict_stats param
09:31:35    0 sqlt$d: export fixed objects stats
09:31:35    0 sqlt$d: 0 rows collected
09:31:35    0 sqlt$d: collect_dba_tables
09:31:35    0 sqlt$d: 3 rows collected
09:31:35    0 sqlt$d: collect_dba_object_tables
09:31:35    0 sqlt$d: 0 rows collected
09:31:35    0 sqlt$d: collect_dba_nested_tables
09:31:41    6 sqlt$d: 0 rows collected
09:31:41    0 sqlt$d: collect_dba_tab_statistics
09:31:41    0 sqlt$d: 3 rows collected
09:31:41    0 sqlt$d: collect_dba_tab_modifications
09:31:41    0 sqlt$d: 3 rows collected
09:31:41    0 sqlt$d: collect_dba_tab_cols
09:31:41    0 sqlt$d: 190 rows collected
09:31:41    0 sqlt$d: collect_dba_nested_table_cols
09:31:41    0 sqlt$d: 0 rows collected
09:31:41    0 sqlt$d: collect_dba_indexes
09:31:41    0 sqlt$d: 17 rows collected
09:31:41    0 sqlt$d: collect_dba_ind_statistics
09:31:41    0 sqlt$d: 17 rows collected
09:31:41    0 sqlt$d: collect_dba_ind_columns
09:31:41    0 sqlt$d: 39 rows collected
09:31:41    0 sqlt$d: collect_dba_ind_expressions
09:31:41    0 sqlt$d: 0 rows collected
09:31:41    0 sqlt$d: collect_dba_tab_histograms
09:31:42    1 sqlt$d: 4825 rows collected
09:31:42    0 sqlt$d: collect_dba_constraints
09:31:42    0 sqlt$d: 50 rows collected
09:31:42    0 sqlt$d: Skipped gv$im_segments since version is older than 12.1.0.2 or parameter c_inmemory is set to N
09:31:42    0 sqlt$d: Skipped gv$im_column_level since version is older than 12.1.0.2 or parameter c_inmemory is set to N
09:31:42    0 sqlt$d: collect_dba_segments GLOBAL
09:31:51    9 sqlt$d: 20 rows collected
09:31:51    0 sqlt$d: collect_dba_tablespaces
09:31:52    1 sqlt$d: 8 rows collected
09:31:52    0 sqlt$d: collect_dba_objects GLOBAL
09:31:52    0 sqlt$d: 20 rows collected
09:31:52    0 sqlt$d: collect_dba_source
09:31:52    0 sqlt$d: 0 rows collected
09:31:52    0 sqlt$d: collect_dba_col_usage$
09:31:52    0 sqlt$d: 93 rows collected
09:31:52    0 sqlt$d: collect_dba_policies
09:31:52    0 sqlt$d: 0 rows collected
09:31:52    0 sqlt$d: collect_dba_audit_policies
09:31:52    0 sqlt$d: 0 rows collected
09:31:52    0 sqlt$d: capture up to "31" days of CBO statistics versions as per parameter c_cbo_stats_vers_days
09:31:52    0 sqlt$d: collect_dba_optstat_operations
09:31:52    0 sqlt$d: 29 rows collected
09:31:52    0 sqlt$d: collect_dba_tab_stats_versn GLOBAL
09:31:52    0 sqlt$d: 1 rows collected
09:31:52    0 sqlt$d: collect_dba_ind_stats_versn GLOBAL
09:31:52    0 sqlt$d: 9 rows collected
09:31:52    0 sqlt$d: collect_dba_col_stats_versn GLOBAL
09:31:53    1 sqlt$d: 78 rows collected
09:31:53    0 sqlt$d: collect_dba_histgrm_stats_ver GLOBAL
09:31:59    6 sqlt$d: 2758 rows collected
09:31:59    0 sqlt$d: collect_wri$_optstat_aux_hist
09:31:59    0 sqlt$d: 0 rows collected
09:31:59    0 sqlt$d: collect_aux_stats$
09:31:59    0 sqlt$d: 13 rows collected
09:31:59    0 sqlt$d: collect_dbms_xplan_display
09:32:00    1 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: collect_dba_outlines
09:32:00    0 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: collect_dba_outline_hints
09:32:00    0 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: collect_wri$_adv_tasks
09:32:00    0 sqlt$d: 2 rows collected
09:32:00    0 sqlt$d: collect_wri$_adv_rationale
09:32:00    0 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: collect_dba_sqltune_plans
09:32:00    0 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: collect_dba_sql_profiles
09:32:00    0 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: -> collect_dbms_stats_glob_prefs
09:32:00    0 sqlt$d: < - collect_dbms_stats_glob_prefs
09:32:00    0 sqlt$d: collect_sqlprof$attr
09:32:00    0 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: collect_sqlprof$
09:32:00    0 sqlt$d: 0 rows collected
09:32:00    0 sqlt$d: collect_dba_scheduler_jobs
09:32:00    0 sqlt$d: 1 rows collected
09:32:00    0 sqlt$d: one_plan_per_hv_mem
09:32:00    0 sqlt$d: 1 selected plans on sqlt$_gv$sql
09:32:00    0 sqlt$d: one_plan_per_hv_sta
09:32:00    0 sqlt$d: 0 selected plans on sqlt$_dba_sqltune_plans
09:32:00    0 sqlt$d: collect_plan_extensions
09:32:00    0 sqlt$d: 24 rows collected
09:32:00    0 sqlt$d:  sql_tuning_advisor
09:32:01    1 sqlt$i: max_plan_et_secs:5.404 sta_time_limit_secs:1800
09:32:01    0 sqlt$i: -> SYS.DBMS_SQLTUNE.EXECUTE_TUNING_TASK('sqlt_s34879_mem')
09:36:56  295 sqlt$i: < - SYS.DBMS_SQLTUNE.EXECUTE_TUNING_TASK('sqlt_s34879_mem') 09:36:56 0 sqlt$i: -> SYS.DBMS_SQLTUNE.EXECUTE_TUNING_TASK('sqlt_s34879_txt')
09:38:05   69 sqlt$i: < - SYS.DBMS_SQLTUNE.EXECUTE_TUNING_TASK('sqlt_s34879_txt') 09:38:05 0 sqlt$a: -> upload_sta_files
09:38:05    0 sqlt$a: "sqlt_s34879_sta_report_mem.txt" was uploaded to repository
09:38:05    0 sqlt$a: "sqlt_s34879_sta_script_mem.sql" was uploaded to repository
09:38:05    0 sqlt$a: "sqlt_s34879_sta_report_txt.txt" was uploaded to repository
09:38:05    0 sqlt$a: "sqlt_s34879_sta_script_txt.sql" was uploaded to repository
09:38:05    0 sqlt$a: < - upload_sta_files
09:38:05    0 sqlt$i: <= sql_tuning_advisor 09:38:05 0 sqlt$i: => test_case_builder
09:38:05    0 sqlt$i: skip test_case_builder since rdbms_release does not provide it
09:38:05    0 sqlt$r: -> tcb_driver
09:38:05    0 sqlt$r: generated sqlt_s34879_tcb_driver.sql
09:38:05    0 sqlt$r: < - tcb_driver
09:38:05    0 sqlt$i: <= test_case_builder 09:38:05 0 sqlt$i: => ebs_application_specific
09:38:05    0 sqlt$i: this is not an EBS application
09:38:05    0 sqlt$i: skip "bde_chk_cbo" since this is not an EBS application
09:38:05    0 sqlt$i: < = ebs_application_specific 09:38:05 0 sqlt$i: => siebel_application_specific
09:38:05    0 sqlt$i: < = siebel_application_specific 09:38:05 0 sqlt$i: => psft_application_specific
09:38:05    0 sqlt$i: < = psft_application_specific 09:38:05 0 sqlt$i: => collect_metadata
09:38:05    0 sqlt$i: -> collect_metadata_objects transformed = "N"
09:38:08    3 sqlt$i: < - collect_metadata_objects transformed = "N" 09:38:08 0 sqlt$i: -> collect_metadata_objects transformed = "Y"
09:38:09    1 sqlt$i: < - collect_metadata_objects transformed = "Y" 09:38:09 0 sqlt$i: -> collect_metadata_constraints transformed = "Y"
09:38:11    2 sqlt$i: < - collect_metadata_constraints transformed = "Y"
09:38:11    0 sqlt$i: <= collect_metadata 09:38:11 0 sqlt$i: => compute_full_table_scan_cost
09:38:11    0 sqlt$i: < = compute_full_table_scan_cost 09:38:11 0 sqlt$i: => perform_count_star
09:38:11    0 sqlt$i: num_rows=119951 sql=SELECT /*+ FULL(t) PARALLEL */ COUNT(*) * 1e2 FROM "INSUR_CHANGDE"."MT_APPLY" SAMPLE (1) t
09:38:11    0 sqlt$i: 121500 rows counted
09:38:11    0 sqlt$i: num_rows=14014679 sql=SELECT /*+ FULL(t) PARALLEL */ COUNT(*) * 1e4 FROM "INSUR_CHANGDE"."MT_BIZ_FIN" SAMPLE (.01) t
09:38:15    4 sqlt$i: 13860000 rows counted
09:38:15    0 sqlt$i: num_rows=35518818 sql=SELECT /*+ FULL(t) PARALLEL */ COUNT(*) * 1e4 FROM "INSUR_CHANGDE"."MT_PAY_RECORD_FIN" SAMPLE (.01) t
09:38:15    0 sqlt$i: 38670000 rows counted
09:38:15    0 sqlt$i: < = perform_count_star 09:38:15 0 sqlt$i: collect_dbms_space 09:38:15 0 sqlt$i: collect_dbms_space.tables 09:38:15 0 sqlt$i: DBMS_SPACE.CREATE_TABLE_COST tablespace_name:HYGEIA avg_row_size:291 row_count:121500 pct_free:10 09:38:16 1 sqlt$i: DBMS_SPACE.CREATE_TABLE_COST tablespace_name:HYGEIA avg_row_size:292 row_count:13860000 pct_free:10 09:38:16 0 sqlt$i: DBMS_SPACE.CREATE_TABLE_COST tablespace_name:HYGEIA avg_row_size:70 row_count:38670000 pct_free:10 09:38:16 0 sqlt$i: collect_dbms_space.indexes 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX$$_429C0002 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX$$_429C0001 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_BIZ_FIN_END_DATE 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_BIZ_FIN_INDI_ID 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_APPLY_INDI 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_BIZ_FIN_FIN_DATE_01 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_APPLY_SERIAL 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:INDI_MT_BIZ_FIN_H_F 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_PAY_RECORD_FIN_2 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_PAY_RECORD_FIN_1 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:PK_MT_PAY_RECORD_FIN 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:PK_MT_BIZ_FIN 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:PK_MT_APPLY 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_BIZ_FIN_FIN_DATE 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_BIZ_FIN_BEGIN_DATE 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_BIZ_FIN_1 09:38:16 0 sqlt$i: SYS.DBMS_SPACE.CREATE_INDEX_COST index_name:IDX_MT_APPLY_INPUT 09:38:16 0 sqlt$t: => perm_transformation
09:38:16    0 sqlt$t: put_statid_into_plan_table
09:38:16    0 sqlt$t: 12 rows updated
09:38:16    0 sqlt$t: put_obj_id_into_tables
09:38:16    0 sqlt$t: 3 rows updated
09:38:16    0 sqlt$t: put_obj_id_into_indexes
09:38:16    0 sqlt$t: 17 rows updated
09:38:16    0 sqlt$t: record_cbo_system_stats
09:38:16    0 sqlt$t: remap_metadata
09:38:17    1 sqlt$t: 70 metadata rows remapped in sqlt$_metadata
09:38:17    0 sqlt$t: table_histograms
09:38:17    0 sqlt$t: partition_histograms
09:38:17    0 sqlt$t: subpartition_histograms
09:38:17    0 sqlt$t: cook_low_and_high_values
09:38:17    0 sqlt$t: 170 rows updated in sqlt$_dba_all_table_cols_v
09:38:17    0 sqlt$t: 0 rows updated in sqlt$_dba_part_col_statistics
09:38:17    0 sqlt$t: 0 rows updated in sqlt$_dba_subpart_col_stats
09:38:17    0 sqlt$t: 78 rows updated in sqlt$_dba_col_stats_versions
09:38:17    0 sqlt$t: compute_mutating_ndv
09:38:17    0 sqlt$t: 0 rows updated with mutating_ndv
09:38:17    0 sqlt$t: compute_endpoints_count
09:38:17    0 sqlt$t: 35 rows updated in sqlt$_dba_histgrm_stats_versn with endpoints_count > 0
09:38:17    0 sqlt$t: compute_mutating_endpoints
09:38:17    0 sqlt$t: 0 rows updated with mutating_endpoints
09:38:17    0 sqlt$t: compute_mutating_num_rows
09:38:17    0 sqlt$t: 0 rows updated with mutating_num_rows
09:38:17    0 sqlt$t: compute_mutating_blevel
09:38:17    0 sqlt$t: 0 rows updated with mutating_blevel
09:38:17    0 sqlt$t: index_in_plan
09:38:17    0 sqlt$t: 3 indexes in plan
09:38:17    0 sqlt$t: column_in_indexes
09:38:17    0 sqlt$t: 30 columns in indexes
09:38:17    0 sqlt$t: at_least_1_notnull_col
09:38:18    1 sqlt$t: 14 indexes updated
09:38:18    0 sqlt$t: skip add_column_default
09:38:18    0 sqlt$t: not_shared_cursors
09:38:18    0 sqlt$t: 0 rows inserted into sqlg$_sql_shared_cursor_n
09:38:18    0 sqlt$t: 0 rows inserted into sqlt$_sql_shared_cursor_d
09:38:18    0 sqlt$t: flag_dba_hist_sqlstat
09:38:18    0 sqlt$t: 0 rows flagged in in_plan_extension
09:38:18    0 sqlt$t: 0 plans in in_plan_summary_v
09:38:18    0 sqlt$t: best_and_worst_plans
09:38:18    0 sqlt$t: fix_cardinality_line_0
09:38:18    0 sqlt$t: 1 plans fixed
09:38:18    0 sqlt$t: execution_order
09:38:18    0 sqlt$t: real_depth
09:38:18    0 sqlt$t: real_depth_m
09:38:18    0 sqlt$t: process_other_xml
09:38:18    0 sqlt$t: 0 binds were processed out of other_xml columns
09:38:18    0 sqlt$t: 12 info rows were processed out of other_xml columns
09:38:18    0 sqlt$t: 68 hints were processed out of other_xml columns
09:38:18    0 sqlt$t: plan_operation
09:38:18    0 sqlt$t: top_cost
09:38:18    0 sqlt$t: top_last_cr_buffer_gets
09:38:18    0 sqlt$t: top_cr_buffer_gets
09:38:18    0 sqlt$t: top_last_cu_buffer_gets
09:38:18    0 sqlt$t: top_cu_buffer_gets
09:38:18    0 sqlt$t: top_last_disk_reads
09:38:18    0 sqlt$t: top_disk_reads
09:38:18    0 sqlt$t: top_last_disk_writes
09:38:18    0 sqlt$t: top_disk_writes
09:38:18    0 sqlt$t: top_last_elapsed_time
09:38:18    0 sqlt$t: top_elapsed_time
09:38:18    0 sqlt$t: build_plan_more_html_table
09:38:19    1 sqlt$t: 22 plan more html tables built
09:38:19    0 sqlt$t: build_workarea_html_table
09:38:19    0 sqlt$t: 1 work area html tables built
09:38:19    0 sqlt$t: build_workarea_html_table
09:38:19    0 sqlt$t: 14 go to html tables built
09:38:19    0 sqlt$t: sanitize_reason
09:38:19    0 sqlt$t: 0 reason columns have been sanitized
09:38:19    0 sqlt$t: sanitize_dir_notes
09:38:19    0 sqlt$t: 0 directives notes columns have been sanitized
09:38:19    0 sqlt$t: sanitize_other_xml
09:38:19    0 sqlt$t: 3 other_xml columns have been sanitized
09:38:19    0 sqlt$t: extend_peeked_binds
09:38:19    0 sqlt$t: 0 peeked_binds were extended
09:38:19    0 sqlt$t: extend_gv$sql_bind_capture
09:38:19    0 sqlt$t: 0 captured_binds were extended with phv
09:38:19    0 sqlt$t: 0 captured_binds were extended with value
09:38:19    0 sqlt$t: extend_gv$sql_optimizer_env
09:38:19    0 sqlt$t: 5 optimizer_env were extended
09:38:19    0 sqlt$t: extend_dba_hist_sqlbind
09:38:19    0 sqlt$t: 0 captured_binds were extended with phv
09:38:19    0 sqlt$t: 0 captured_binds were extended with value
09:38:19    0 sqlt$t: binds_in_predicates
09:38:19    0 sqlt$t: 0 binds in predicates
09:38:19    0 sqlt$t: column_in_predicates
09:38:19    0 sqlt$t: 18 columns in predicates
09:38:19    0 sqlt$t: column_in_projection
09:38:19    0 sqlt$t: 10 columns in projection
09:38:19    0 sqlt$t: extend_gv$sql_monitor
09:38:19    0 sqlt$t: 0 sql_monitor rows were extended
09:38:19    0 sqlt$t: extend_sqlt$_aux_stats$
09:38:19    0 sqlt$t: compute_index_range_scan_cost
09:38:19    0 sqlt$t: compute_index_leaf_estimate
09:38:19    0 sqlt$t: new_11g_ndv_algorithm_used
09:38:19    0 sqlt$t: skip col_group_usage_report
09:38:19    0 sqlt$t: add_dv_censored
09:38:19    0 sqlt$t: < = perm_transformation 09:38:19 0 sqlt$r: -> sql_monitor_reports
09:38:19    0 sqlt$r: skip "sql_monitor_reports" since not available in "10.2.0.4.0"
09:38:19    0 sqlt$r: < - sql_monitor_reports 09:38:19 0 sqlt$r: -> sql_detail_report
09:38:19    0 sqlt$r: skip "sql_detail_report" since not available in "10.2.0.4.0"
09:38:19    0 sqlt$r: < - sql_detail_report 09:38:19 0 sqlt$r: -> awrrpt_driver
09:38:19    0 sqlt$r: generated sqlt_s34879_awrrpt_driver.sql
09:38:19    0 sqlt$r: < - awrrpt_driver 09:38:19 0 sqlt$r: -> addmrpt_driver
09:38:19    0 sqlt$r: generated sqlt_s34879_addmrpt_driver.sql
09:38:19    0 sqlt$r: < - addmrpt_driver 09:38:19 0 sqlt$r: -> ashrpt_driver
09:38:19    0 sqlt$r: generated sqlt_s34879_ashrpt_driver.sql
09:38:19    0 sqlt$r: < - ashrpt_driver 09:38:19 0 sqlt$r: -> xpand_sql_driver
09:38:19    0 sqlt$r: generated sqlt_s34879_xpand_sql_driver.sql
09:38:19    0 sqlt$r: < - xpand_sql_driver 09:38:19 0 sqlt$r: -> script_output_driver
09:38:19    0 sqlt$r: generated sqlt_s34879_script_output_driver.sql
09:38:19    0 sqlt$r: < - script_output_driver 09:38:19 0 sqlt$r: -> tkprof_px_driver
09:38:19    0 sqlt$a: -> session_trace_filename
09:38:19    0 sqlt$a: session_trace_filename, current trace_filename
09:38:19    0 sqlt$a: session_trace_filename, current process_name ora
09:38:19    0 sqlt$a: < - session_trace_filename rlzy_ora_3081178_s34879_10046_10053.trc
09:38:19    0 sqlt$r: trace rlzy_ora_3081178_s34879_10046_10053.trc exists in /oracle/admin/RLZY/udump/
09:38:19    0 sqlt$r: px files were not found
09:38:19    0 sqlt$r: generated sqlt_s34879_tkprof_px_driver.sql
09:38:19    0 sqlt$r:  call_trace_analyzer_px
09:38:19    0 sqlt$i: skip "trace_analyzer_px" since there are no accesible PX traces
09:38:19    0 sqlt$i: < = call_trace_analyzer_px 09:38:19 0 sqlt$r: -> export_parfile
09:38:20    1 sqlt$r: generated sqlt_s34879_export_parfile.txt
09:38:20    0 sqlt$r: < - export_parfile 09:38:20 0 sqlt$r: -> export_parfile2
09:38:20    0 sqlt$r: generated sqlt_s34879_export_parfile2.txt
09:38:20    0 sqlt$r: < - export_parfile2 09:38:20 0 sqlt$r: -> export_driver
09:38:20    0 sqlt$r: generated sqlt_s34879_export_driver.sql
09:38:20    0 sqlt$r: < - export_driver 09:38:20 0 sqlt$r: -> import_script
09:38:20    0 sqlt$r: generated sqlt_s34879_import.sh
09:38:20    0 sqlt$r: < - import_script 09:38:20 0 sqlt$r: -> metadata_script
09:38:20    0 sqlt$r: < - metadata_script 09:38:20 0 sqlt$r: -> metadata_script1
09:38:20    0 sqlt$r: < - metadata_script1 09:38:20 0 sqlt$r: -> metadata_script2
09:38:20    0 sqlt$r: < - metadata_script2 09:38:20 0 sqlt$r: -> system_stats_script
09:38:20    0 sqlt$r: < - system_stats_script 09:38:20 0 sqlt$r: -> schema_stats_script
09:38:20    0 sqlt$r: < - schema_stats_script 09:38:20 0 sqlt$r: -> set_cbo_env_script
09:38:20    0 sqlt$r: < - set_cbo_env_script 09:38:20 0 sqlt$r: -> custom_sql_profile
09:38:20    0 sqlt$r: ** skip "custom_sql_profile" as per "custom_sql_profile" parameter. this functionality is now disabled by default.
09:38:20    0 sqlt$r: ** to enable this functionality execute: SQL> EXEC SQLTXADMIN.sqlt$a.set_param('custom_sql_profile', 'Y');
09:38:20    0 sqlt$r: < - custom_sql_profile 09:38:20 0 sqlt$r: -> plan
09:38:20    0 sqlt$r: < - plan 09:38:20 0 sqlt$r: -> s10053
09:38:20    0 sqlt$r: < - s10053 09:38:20 0 sqlt$r: -> flush
09:38:20    0 sqlt$r: < - flush 09:38:20 0 sqlt$r: -> purge
09:38:20    0 sqlt$r: < - purge 09:38:20 0 sqlt$r: -> restore
09:38:20    0 sqlt$r: < - restore 09:38:20 0 sqlt$r: -> del_hgrm
09:38:20    0 sqlt$r: < - del_hgrm 09:38:20 0 sqlt$r: -> tc_sql
09:38:20    0 sqlt$r: < - tc_sql 09:38:20 0 sqlt$r: -> xpress_sh
09:38:20    0 sqlt$r: < - xpress_sh 09:38:20 0 sqlt$r: -> xpress_sql
09:38:20    0 sqlt$r: < - xpress_sql 09:38:20 0 sqlt$r: -> setup
09:38:20    0 sqlt$r: < - setup 09:38:20 0 sqlt$r: -> readme
09:38:20    0 sqlt$r: < - readme 09:38:20 0 sqlt$r: -> tc_pkg
09:38:20    0 sqlt$r: < - tc_pkg 09:38:20 0 sqlt$r: -> sel
09:38:20    0 sqlt$r: < - sel 09:38:20 0 sqlt$r: -> sel_aux
09:38:20    0 sqlt$r: < - sel_aux 09:38:20 0 sqlt$r: -> install_sh
09:38:20    0 sqlt$r: < - install_sh 09:38:20 0 sqlt$r: -> install_sql
09:38:20    0 sqlt$r: < - install_sql 09:38:20 0 sqlt$r: -> tcx_pkg
09:38:20    0 sqlt$r: < - tcx_pkg 09:38:20 0 sqlt$r: -> lite_report
09:38:20    0 sqlt$r: -> lite_report.header
09:38:20    0 sqlt$r: -> lite_report.plans_summary
09:38:20    0 sqlt$r: -> lite_report.plans_list
09:38:20    0 sqlt$r: -> lite_report.plans
09:38:21    1 sqlt$r: -> lite_report.tables
09:38:21    0 sqlt$r: -> lite_report.table_columns
09:38:21    0 sqlt$r: -> lite_report.indexes
09:38:21    0 sqlt$r: -> lite_report.index_columns
09:38:22    1 sqlt$r: -> lite_report.footer
09:38:22    0 sqlt$r: < - lite_report 09:38:22 0 sqlt$a: -> upload_10053_trace
09:38:22    0 sqlt$a: -> upload_trace
09:38:22    0 sqlt$a: source = "rlzy_ora_3081178_s34879_10053.trc"
09:38:22    0 sqlt$a: target = "sqlt_s34879_10053_explain.trc"
09:38:22    0 sqlt$a: prepare file workspace
09:38:22    0 sqlt$a: open source trace (input)
09:38:22    0 sqlt$a: open target clob (output)
09:38:22    0 sqlt$a: source_offset:1 target_offset:1
09:38:22    0 sqlt$a: close trace and clob
09:38:22    0 sqlt$a: update file_size
09:38:22    0 sqlt$a: -> set_filesize for:sqlt_s34879_10053_explain.trc
09:38:22    0 sqlt$a: < - set_filesize for:sqlt_s34879_10053_explain.trc
09:38:22    0 sqlt$a:  upload_10053_xtract
09:38:22    0 sqlt$a: -> upload_trace
09:38:22    0 sqlt$a: there is no trace to upload to repository
09:38:22    0 sqlt$a: < - upload_trace
09:38:22    0 sqlt$a:  remote_trace_analyzer_and_copy
09:38:22    0 sqlt$i: < = remote_trace_analyzer_and_copy 09:38:22 0 sqlt$r: -> remote_driver
09:38:22    0 sqlt$r: generated sqlt_s34879_remote_driver.sql
09:38:22    0 sqlt$r: < - remote_driver 09:38:22 0 sqlt$a: input_filename "/oracle/sqlt/input/sample/mysql2.sql" was recorded 09:38:22 0 sqlt$m: => main_report_root
09:38:22    0 sqlt$a: -> common_initialization
09:38:22    0 sqlt$a: ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ".,"
09:38:22    0 sqlt$a: ALTER SESSION SET NLS_SORT = BINARY
09:38:22    0 sqlt$a: < - common_initialization 09:38:22 0 sqlt$t: => temp_transformation
09:38:22    0 sqlt$t: build_column_html_table_pred
09:38:22    0 sqlt$t: 8 column html tables built
09:38:22    0 sqlt$t: build_column_html_table_idx
09:38:23    1 sqlt$t: 27 column html tables built
09:38:23    0 sqlt$t: index_columns
09:38:23    0 sqlt$t: < = temp_transformation 09:38:23 0 sqlt$h: => health_check
09:38:23    0 sqlt$h: -> global_hc
09:38:23    0 sqlt$h: < - global_hc 09:38:23 0 sqlt$h: -> table_hc_MT_APPLY
09:38:23    0 sqlt$h: < - table_hc_MT_APPLY 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_APPLY_INDI
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_APPLY_INDI 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_APPLY_INPUT
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_APPLY_INPUT 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_APPLY_SERIAL
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_APPLY_SERIAL 09:38:23 0 sqlt$h: -> index_hc_PK_MT_APPLY
09:38:23    0 sqlt$h: < - index_hc_PK_MT_APPLY 09:38:23 0 sqlt$h: -> column_hc_MT_APPLY_HOSPITAL_ID
09:38:23    0 sqlt$h: < - column_hc_MT_APPLY_HOSPITAL_ID 09:38:23 0 sqlt$h: -> column_hc_MT_APPLY_INDI_ID
09:38:23    0 sqlt$h: < - column_hc_MT_APPLY_INDI_ID 09:38:23 0 sqlt$h: -> column_hc_MT_APPLY_SERIAL_APPLY
09:38:23    0 sqlt$h: < - column_hc_MT_APPLY_SERIAL_APPLY 09:38:23 0 sqlt$h: -> column_hc_MT_APPLY_SERIAL_NO
09:38:23    0 sqlt$h: < - column_hc_MT_APPLY_SERIAL_NO 09:38:23 0 sqlt$h: -> column_hc_MT_APPLY_TREATMENT_TYPE
09:38:23    0 sqlt$h: < - column_hc_MT_APPLY_TREATMENT_TYPE 09:38:23 0 sqlt$h: -> column_hc_MT_APPLY_VALID_FLAG
09:38:23    0 sqlt$h: < - column_hc_MT_APPLY_VALID_FLAG 09:38:23 0 sqlt$h: -> table_hc_MT_BIZ_FIN
09:38:23    0 sqlt$h: < - table_hc_MT_BIZ_FIN 09:38:23 0 sqlt$h: -> index_hc_IDX$$_429C0001
09:38:23    0 sqlt$h: < - index_hc_IDX$$_429C0001 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_BIZ_FIN_1
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_BIZ_FIN_1 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_BIZ_FIN_BEGIN_DATE
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_BIZ_FIN_BEGIN_DATE 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_BIZ_FIN_END_DATE
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_BIZ_FIN_END_DATE 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_BIZ_FIN_FIN_DATE
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_BIZ_FIN_FIN_DATE 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_BIZ_FIN_FIN_DATE_01
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_BIZ_FIN_FIN_DATE_01 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_BIZ_FIN_INDI_ID
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_BIZ_FIN_INDI_ID 09:38:23 0 sqlt$h: -> index_hc_INDI_MT_BIZ_FIN_H_F
09:38:23    0 sqlt$h: < - index_hc_INDI_MT_BIZ_FIN_H_F 09:38:23 0 sqlt$h: -> index_hc_PK_MT_BIZ_FIN
09:38:23    0 sqlt$h: < - index_hc_PK_MT_BIZ_FIN 09:38:23 0 sqlt$h: -> column_hc_MT_BIZ_FIN_HOSPITAL_ID
09:38:23    0 sqlt$h: < - column_hc_MT_BIZ_FIN_HOSPITAL_ID 09:38:23 0 sqlt$h: -> column_hc_MT_BIZ_FIN_INDI_ID
09:38:23    0 sqlt$h: < - column_hc_MT_BIZ_FIN_INDI_ID 09:38:23 0 sqlt$h: -> column_hc_MT_BIZ_FIN_SERIAL_APPLY
09:38:23    0 sqlt$h: < - column_hc_MT_BIZ_FIN_SERIAL_APPLY 09:38:23 0 sqlt$h: -> column_hc_MT_BIZ_FIN_SERIAL_NO
09:38:23    0 sqlt$h: < - column_hc_MT_BIZ_FIN_SERIAL_NO 09:38:23 0 sqlt$h: -> column_hc_MT_BIZ_FIN_TREATMENT_TYPE
09:38:23    0 sqlt$h: < - column_hc_MT_BIZ_FIN_TREATMENT_TYPE 09:38:23 0 sqlt$h: -> column_hc_MT_BIZ_FIN_VALID_FLAG
09:38:23    0 sqlt$h: < - column_hc_MT_BIZ_FIN_VALID_FLAG 09:38:23 0 sqlt$h: -> table_hc_MT_PAY_RECORD_FIN
09:38:23    0 sqlt$h: < - table_hc_MT_PAY_RECORD_FIN 09:38:23 0 sqlt$h: -> index_hc_IDX$$_429C0002
09:38:23    0 sqlt$h: < - index_hc_IDX$$_429C0002 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_PAY_RECORD_FIN_1
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_PAY_RECORD_FIN_1 09:38:23 0 sqlt$h: -> index_hc_IDX_MT_PAY_RECORD_FIN_2
09:38:23    0 sqlt$h: < - index_hc_IDX_MT_PAY_RECORD_FIN_2 09:38:23 0 sqlt$h: -> index_hc_PK_MT_PAY_RECORD_FIN
09:38:23    0 sqlt$h: < - index_hc_PK_MT_PAY_RECORD_FIN 09:38:23 0 sqlt$h: -> column_hc_MT_PAY_RECORD_FIN_FUND_ID
09:38:23    0 sqlt$h: < - column_hc_MT_PAY_RECORD_FIN_FUND_ID 09:38:23 0 sqlt$h: -> column_hc_MT_PAY_RECORD_FIN_HOSPITAL_ID
09:38:23    0 sqlt$h: < - column_hc_MT_PAY_RECORD_FIN_HOSPITAL_ID 09:38:23 0 sqlt$h: -> column_hc_MT_PAY_RECORD_FIN_POLICY_ITEM_CODE
09:38:23    0 sqlt$h: < - column_hc_MT_PAY_RECORD_FIN_POLICY_ITEM_CODE 09:38:23 0 sqlt$h: -> column_hc_MT_PAY_RECORD_FIN_SERIAL_NO
09:38:23    0 sqlt$h: < - column_hc_MT_PAY_RECORD_FIN_SERIAL_NO 09:38:23 0 sqlt$h: -> column_hc_MT_PAY_RECORD_FIN_VALID_FLAG
09:38:23    0 sqlt$h: < - column_hc_MT_PAY_RECORD_FIN_VALID_FLAG
09:38:23    0 sqlt$h: <= health_check 09:38:23 0 sqlt$m: => main_report
09:38:23    0 sqlt$m: -> flags
09:38:24    1 sqlt$m: < - flags
09:38:24    0 sqlt$m: observations_sec
09:38:24    0 sqlt$m: sql_text_sec
09:38:24    0 sqlt$m: sql_identification_sec
09:38:24    0 sqlt$m: environment_sec
09:38:24    0 sqlt$m: cbo_environment_sec
09:38:24    0 sqlt$m: cbo_environment_mod
09:38:24    0 sqlt$m: cbo_environment_unmod
09:38:24    0 sqlt$m: bug_fix_control_sec
09:38:24    0 sqlt$m: bug_fix_control_sec_0
09:38:24    0 sqlt$m: bug_fix_control_sec_1
09:38:24    0 sqlt$m: system_stats_sec
09:38:24    0 sqlt$m: dbms_stats_setup_sec
09:38:25    1 sqlt$m: init_parameters_sec
09:38:25    0 sqlt$m: init_parameters_sec_FALSE
09:38:25    0 sqlt$m: init_parameters_sec_TRUE
09:38:25    0 sqlt$m: init_parameters_sys_mod
09:38:25    0 sqlt$m: init_parameters_sys
09:38:25    0 sqlt$m: nls_parameters_sec
09:38:25    0 sqlt$m: io_calibration_sec
09:38:25    0 sqlt$m: tool_config_params_sec
09:38:25    0 sqlt$m: cursor_sharing_sec
09:38:26    1 sqlt$m: plan_sum_sec
09:38:26    0 sqlt$m: plan_stats_sec
09:38:26    0 sqlt$m: plan_stats_sec_2582817425_GV$SQLAREA_PLAN_HASH_1
09:38:26    0 sqlt$m: plan_exec_sec
09:38:26    0 sqlt$m: plan_exec_sec_2582817425_1_1_0_07000005C96BA558
09:38:26    0 sqlt$m: src = "MEM"
09:38:26    0 sqlt$m: source = "GV$SQL_PLAN"
09:38:26    0 sqlt$m: phv = "2582817425"
09:38:26    0 sqlt$m: plan_id = "-1"
09:38:26    0 sqlt$m: inst_id = "1"
09:38:26    0 sqlt$m: child_number = "0"
09:38:26    0 sqlt$m: child_address = "07000005C96BA558"
09:38:26    0 sqlt$m: gv$sql_plan_statistics = "1"
09:38:26    0 sqlt$m: last_starts = "7"
09:38:26    0 sqlt$m: starts = "21"
09:38:26    0 sqlt$m: last_output_rows = "1185999"
09:38:26    0 sqlt$m: output_rows = "3557995"
09:38:26    0 sqlt$m: last_cr_buffer_gets = "408609"
09:38:26    0 sqlt$m: cr_buffer_gets = "1225838"
09:38:26    0 sqlt$m: last_cu_buffer_gets = "0"
09:38:26    0 sqlt$m: cu_buffer_gets = "0"
09:38:26    0 sqlt$m: last_disk_reads = "0"
09:38:26    0 sqlt$m: disk_reads = "1798"
09:38:26    0 sqlt$m: last_disk_writes = "0"
09:38:26    0 sqlt$m: disk_writes = "0"
09:38:26    0 sqlt$m: last_elapsed_time = "5388427"
09:38:26    0 sqlt$m: elapsed_time = "16192336"
09:38:26    0 sqlt$m: executions = "3"
09:38:26    0 sqlt$m: gv$sql_monitor.sql_exec_start = ""
09:38:26    0 sqlt$m: gv$sql_monitor.sql_exec_id = ""
09:38:26    0 sqlt$m: gv$sql_monitor.key = ""
09:38:26    0 sqlt$m: gv$sql_workarea = "1"
09:38:26    0 sqlt$m: sqlt$_plan_extension.more = "1"
09:38:26    0 sqlt$m: sqlt$_plan_extension.binds_peek = "0"
09:38:26    0 sqlt$m: sqlt$_plan_extension.binds_capt = "0"
09:38:26    0 sqlt$m: plan_exec_sec_2582817425_3_542___
09:38:26    0 sqlt$m: src = "XPL"
09:38:26    0 sqlt$m: source = "PLAN_TABLE"
09:38:26    0 sqlt$m: phv = "2582817425"
09:38:26    0 sqlt$m: plan_id = "542"
09:38:26    0 sqlt$m: inst_id = ""
09:38:26    0 sqlt$m: child_number = ""
09:38:26    0 sqlt$m: child_address = ""
09:38:26    0 sqlt$m: sqlt$_plan_extension.more = "1"
09:38:26    0 sqlt$m: sqlt$_plan_extension.binds_peek = "0"
09:38:26    0 sqlt$m: sqlt$_plan_extension.binds_capt = "0"
09:38:26    0 sqlt$m: act_sess_hist_sec
09:38:26    0 sqlt$m: sql_stats_sec
09:38:26    0 sqlt$m: sql_stats_sec_2582817425_1_0_07000005C96BA558_0700000438927940
09:38:26    0 sqlt$m: session_stats_sec
09:38:26    0 sqlt$m: session_event_sec
09:38:26    0 sqlt$m: parallel_processing_sec1
09:38:27    1 sqlt$m: table_sum_sec
09:38:27    0 sqlt$m: tab_stats_sec
09:38:27    0 sqlt$m: tab_stats_vers_sec
09:38:27    0 sqlt$m: tab_mod_sec
09:38:27    0 sqlt$m: tab_prop_sec
09:38:27    0 sqlt$m: tab_phy_prop_sec
09:38:27    0 sqlt$m: tab_cons_sec
09:38:27    0 sqlt$m: tab_cols_sec
09:38:29    2 sqlt$m: indexed_columns_sec
09:38:30    1 sqlt$m: tab_col_hgrm_sec
09:38:58   28 sqlt$m: index_sum_sec
09:39:00    2 sqlt$m: objects_sec
09:39:00    0 sqlt$m: dependencies_sec
09:39:00    0 sqlt$m: tablespaces_sec
09:39:00    0 sqlt$m: metadata_sec
09:39:00    0 sqlt$m: generated sqlt_s34879_main.html
09:39:00    0 sqlt$m: <= main_report 09:39:00 0 sqlt$e: -> get_file_attributes_from_repo
09:39:00    0 sqlt$e: < - get_file_attributes_from_repo
09:39:00    0 sqlt$m: main_report max_file_size: 104857600B (102400KB) (100MB)
09:39:00    0 sqlt$m: main_report current_size : 2786854B (2722KB) (3MB)
09:39:00    0 sqlt$m: no need to resize 1: scale down all lists by 0.5
09:39:00    0 sqlt$m: no need to resize 2: turn off go_to
09:39:00    0 sqlt$m: no need to resize 3: turn off overlib
09:39:00    0 sqlt$m: no need to resize 4: scale down all lists by 0.25
09:39:00    0 sqlt$m: no need to resize 5: turn off in_pred
09:39:00    0 sqlt$m: no need to resize 6: turn off sql_text
09:39:00    0 sqlt$m: no need to resize 7: scale down all lists by 0.125
09:39:00    0 sqlt$m: no need to resize 8: turn off metadata
09:39:00    0 sqlt$m: no need to resize 9: scale down all lists by 0.05
09:39:00    0 sqlt$m: <= main_report_root 09:39:00 0 sqlt$i: => call_trace_analyzer
Execution ID: 38597 started at 2014-08-26 09:39:00
In case of premature termination, read trcanlzr_error.log located in SQL*Plus default directory
/*************************************************************************************/
09:39:00 => trcanlzr
09:39:00 file_name:"rlzy_ora_3081178_s34879_10046_10053.trc"
09:39:00 analyze:"YES"
09:39:00 split:"YES"
09:39:00 tool_execution_id:"38597"
09:39:00 directory_alias_in:"SQLT$UDUMP"
09:39:00 file_name_log:"sqlt_s34879_"
09:39:00 file_name_html:"sqlt_s34879_"
09:39:00 file_name_txt:"sqlt_s34879_"
09:39:00 file_name_10046:""
09:39:00 file_name_10053:""
09:39:00 out_file_identifier:""
09:39:00 calling trca$p.parse_main
09:39:00 => parse_main
09:39:00 analyzing input file rlzy_ora_3081178_s34879_10046_10053.trc in /oracle/admin/RLZY/udump (SQLT$UDUMP)
09:39:00 -> parse_file
09:39:00 parsing file rlzy_ora_3081178_s34879_10046_10053.trc in /oracle/admin/RLZY/udump
09:39:01 invalid stat at line 233 "613" "" "123"
09:39:01 invalid stat at line 234 "613" "" "123"
09:39:01 invalid stat at line 235 "613" "" "123"
09:39:01 invalid stat at line 236 "613" "" "123"
09:39:01 invalid stat at line 237 "613" "" "123"
09:39:01 invalid stat at line 238 "613" "" "123"
09:39:01 invalid stat at line 239 "613" "" "123"
09:39:02 invalid stat at line 11296 "549" "" "105"
09:39:02 invalid stat at line 11297 "549" "" "105"
09:39:02 invalid stat at line 11298 "549" "" "105"
09:39:02 invalid stat at line 11299 "549" "" "105"
09:39:02 invalid stat at line 11300 "549" "" "105"
09:39:02 invalid stat at line 11301 "549" "" "105"
09:39:03 process_orphan_waits: creating some fake trace lines to aggregate waits into calls and cursors
09:39:03 =====================
09:39:03 PARSING IN CURSOR #0 len=9 dep=0 uid=0 oct=0 lid=0 tim=3502350433402 hv=0 ad='0'
09:39:03 CURSOR #0
09:39:03 END OF STMT
09:39:03 EXEC #0:c=0,e=340,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=0,tim=3502350433402
09:39:03 =====================
09:39:03 +
09:39:03 |                 161  BINDS sets.
09:39:03 |                 327  binds.
09:39:03 |                 239  PARSE CALLs.
09:39:03 |                 886  EXEC CALLs.
09:39:03 |                 910  FETCH CALLs.
09:39:03 |                   0  UNMAP CALLs.
09:39:03 |                   0  SORT UNMAP CALLs.
09:39:03 |            47427547  CALL elapsed.
09:39:03 |            30780000  CALL cpu.
09:39:03 |                1828  CALL disk.
09:39:03 |             6547018  CALL query.
09:39:03 |                 623  CALL current.
09:39:03 |                 116  CALL misses.
09:39:03 |                3603  CALL rows.
09:39:03 |                  21  WAIT count idle event.
09:39:03 |                 720  WAIT count non-idle event.
09:39:03 |               26656  WAIT ela idle event.
09:39:03 |              310992  WAIT ela non-idle event.
09:39:03 |                 885  STAT lines.
09:39:03 |                   0  ERROR lines.
09:39:03 +
09:39:03 |                   0  sessions in tracefile.
09:39:03 |                  72  transactions in tracefile.
09:39:03 |                   4  gaps in tracefile.
09:39:03 |                  84  user SQL statements in trace file.
09:39:03 |                 358  internal SQL statements in trace file.
09:39:03 |                 442  SQL statements in trace file.
09:39:03 |                  77  user unique SQL statements in trace file.
09:39:03 |                  38  internal unique SQL statements in trace file.
09:39:03 |                 115  unique SQL statements in trace file.
09:39:03 |               12043  lines in trace file.
09:39:03 |                   0  long lines in trace file.
09:39:03 |                  47  elapsed seconds in trace file.
09:39:03 +
09:39:03 parsed rlzy_ora_3081178_s34879_10046_10053.trc (input 713737 bytes, parsed as 713737 bytes)
09:39:03 < - parse_file
09:39:03  first_transformation
09:39:03 refresh tool data dictionary?
09:39:03 finding same database_id and host_name, considering dictionary refresh...
09:39:03 -> refresh_trca$_dict_from_this before(20140813)
09:39:03 => refresh_trca$_dict_from_this
09:39:03 -> purge_trca$_dict
09:39:03 dict_state_before_purge
09:39:03 -----------------------
09:39:03 -> print_dict_state
09:39:03 dict_refresh_days : 1
09:39:03 dict_refresh_date : 20140813
09:39:03 dict_database_id  : 1589671076
09:39:03 dict_database_name: RLZY
09:39:03 dict_instance_id  : 1
09:39:03 dict_instance_name: RLZY
09:39:03 dict_host_name    : IBMP740-1
09:39:03 dict_platform     : IBM/AIX RISC System/6000
09:39:03 dict_rdbms_version: 10.2.0.4.0
09:39:03 dict_db_files     : 200
09:39:03 < - print_dict_state 09:39:03 -> call_purge_trca$_dict_gtt
09:39:03 < - call_purge_trca$_dict_gtt 09:39:25 dict_state_after_purge 09:39:25 ---------------------- 09:39:25 -> print_dict_state
09:39:25 dict_refresh_days :
09:39:25 dict_refresh_date :
09:39:25 dict_database_id  :
09:39:25 dict_database_name:
09:39:25 dict_instance_id  :
09:39:25 dict_instance_name:
09:39:25 dict_host_name    :
09:39:25 dict_platform     :
09:39:25 dict_rdbms_version:
09:39:25 dict_db_files     :
09:39:25 < - print_dict_state
09:39:25  trca$_file$
09:39:25 < - trca$_file$ (78 rows) 09:39:25 -> trca$_segments
09:39:28 < - trca$_segments (96922 rows) 09:39:28 -> trca$_extents_dm
09:39:28 < - trca$_extents_dm (0 rows) 09:39:28 -> trca$_extents_lm
09:39:28 < - trca$_extents_lm (0 rows) 09:39:28 -> trca$_users
09:39:28 < - gather_table_stats: sqltxplain.trca$_users skipped
09:39:28  trca$_extents
09:39:28 < - gather_table_stats: sqltxplain.trca$_extents skipped
09:39:28  call_purge_trca$_dict_gtt
09:39:28 < - call_purge_trca$_dict_gtt 09:39:28 -> trca$_tables$
09:39:31 < - gather_table_stats: sqltxplain.trca$_tables$ skipped
09:39:31  trca$_indexes$
09:39:33 < - gather_table_stats: sqltxplain.trca$_indexes$ skipped
09:39:33  trca$_ind_columns$
09:39:43 < - gather_table_stats: sqltxplain.trca$_ind_columns$ skipped
09:39:43  trca$_tab_cols$
09:40:12 < - gather_table_stats: sqltxplain.trca$_tab_cols$ skipped
09:40:12  trca$_objects$
09:40:14 < - gather_table_stats: sqltxplain.trca$_objects$ skipped
09:40:14  trca$_parameter2$
09:40:14 < - gather_table_stats: sqltxplain.trca$_parameter2$ skipped
09:40:14  print_dict_state
09:40:14 dict_refresh_days : 2
09:40:14 dict_refresh_date : 20140826
09:40:14 dict_database_id  : 1589671076
09:40:14 dict_database_name: RLZY
09:40:14 dict_instance_id  : 1
09:40:14 dict_instance_name: RLZY
09:40:14 dict_host_name    : IBMP740-1
09:40:14 dict_platform     : IBM/AIX RISC System/6000
09:40:14 dict_rdbms_version: 10.2.0.4.0
09:40:14 dict_db_files     : 200
09:40:14 < - print_dict_state
09:40:14 <= refresh_trca$_dict_from_this
09:40:14  adjust_calls
09:40:14 adjusting tim=3502350433402 c: 0 -> 19970000
09:40:14 adjusting tim=3502350433402 e: 340 -> 30915713
09:40:14 adjusting tim=3502350433402 p: 0 -> 153
09:40:14 adjusting tim=3502350433402 cr: 0 -> 5319618
09:40:14 adjusting tim=3502350433402 cu: 0 -> 611
09:40:14 adjusted c count=1 adjustment=19970000
09:40:14 adjusted e count=1 adjustment=30915373
09:40:14 adjusted p count=1 adjustment=153
09:40:14 adjusted cr count=1 adjustment=5319618
09:40:14 adjusted cu count=1 adjustment=611
09:40:14 < - adjust_calls 09:40:14 -> min_and_max_tim
09:40:14 < - min_and_max_tim 09:40:14 -> call_tree
09:40:14 < - gather_table_stats: sqltxplain.trca$_call_tree skipped
09:40:14  exec_tree
09:40:14 < - gather_table_stats: sqltxplain.trca$_exec_tree skipped 09:40:14 -> exec_tree
09:40:14 < - genealogy_edge
09:40:14  genealogy
09:40:15 < - gather_table_stats: sqltxplain.trca$_genealogy skipped
09:40:15  tool_call_non_recursive
09:40:15 < - tool_call_non_recursive 09:40:15 -> tool_call_recursive
09:40:15 < - tool_call_recursive 09:40:15 -> tool_call
09:40:15 < - gather_table_stats: sqltxplain.trca$_tool_exec_call skipped
09:40:15  tool_call_total
09:40:15 < - gather_table_stats: sqltxplain.trca$_tool_exec_call skipped
09:40:15  group_call
09:40:15 < - gather_table_stats: sqltxplain.trca$_group_call skipped
09:40:15  group_call_total
09:40:15 < - gather_table_stats: sqltxplain.trca$_group_call skipped
09:40:15  compute_group_rank_rt
09:40:15 group_id:"647" tool_execution_id:"38597"
09:40:15   75 sqlt$i: ** ORA-01403: no data found
ORA-01403: no data found
09:40:15    0 sqlt$i: skip "trace_analyzer" as per error above
09:40:15    0 sqlt$i: < = call_trace_analyzer 09:40:15 0 sqlt$r: -> readme_report_html
09:40:15    0 sqlt$r: < - readme_report_html 09:40:15 0 sqlt$r: -> readme_report_txt
09:40:15    0 sqlt$r: < - readme_report_txt 09:40:15 0 sqlt$a: -> upload_10046_10053_trace
09:40:15    0 sqlt$a: -> upload_trace
09:40:15    0 sqlt$a: source = "rlzy_ora_3081178_s34879_10046_10053.trc"
09:40:15    0 sqlt$a: target = "sqlt_s34879_10046_10053_execute.trc"
09:40:15    0 sqlt$a: prepare file workspace
09:40:15    0 sqlt$a: open source trace (input)
09:40:15    0 sqlt$a: open target clob (output)
09:40:15    0 sqlt$a: source_offset:1 target_offset:1
09:40:15    0 sqlt$a: close trace and clob
09:40:15    0 sqlt$a: update file_size
09:40:15    0 sqlt$a: -> set_filesize for:sqlt_s34879_10046_10053_execute.trc
09:40:15    0 sqlt$a: < - set_filesize for:sqlt_s34879_10046_10053_execute.trc
09:40:15    0 sqlt$a:  sql_monitor_driver
09:40:15    0 sqlt$r: skip "sql_monitor_driver" since not available in "10.2.0.4.0"
09:40:15    0 sqlt$r: < - sql_monitor_driver
09:40:15    0 sqlt$i: <== xecute_end 09:40:15 0 sqlt$a: -> restore_init_parameters
09:40:15    0 sqlt$a: optimizer_index_cost_adj restored to "20"
09:40:15    0 sqlt$a: ALTER SESSION SET optimizer_index_cost_adj = 20
09:40:15    0 sqlt$a: < - restore_init_parameters 09:40:15 0 sqlt$r: -> process_log
09:40:15    0 sqlt$r: < - process_log
09:40:15    0 sqlt$i: SQLTXECUTE completed for "/oracle/sqlt/input/sample/mysql2.sql"
09:40:15    0 sqlt$i: ... please wait ...
Elapsed: 00:09:29.00
sar: The file access permissions do not allow the specified action.
... getting missing_file.txt out of sqlt repository ...
... getting sqlt_s34879_remote_driver.sql out of sqlt repository ...
  adding: sqlt_s34879_remote_driver.sql (deflated 46%)
... getting sqlt_s34879_main.html out of sqlt repository ...
... getting sqlt_s34879_lite.html out of sqlt repository ...
... getting sqlt_s34879_readme.html out of sqlt repository ...
... getting sqlt_s34879_readme.txt out of sqlt repository ...
... getting sqlt_s34879_metadata.sql out of sqlt repository ...
... getting sqlt_s34879_metadata1.sql out of sqlt repository ...
... getting sqlt_s34879_metadata2.sql out of sqlt repository ...
... getting sqlt_s34879_system_stats.sql out of sqlt repository ...
... getting sqlt_s34879_schema_stats.sql out of sqlt repository ...
... getting sqlt_s34879_set_cbo_env.sql out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting sqlt_s34879_sta_report_mem.txt out of sqlt repository ...
... getting sqlt_s34879_sta_script_mem.sql out of sqlt repository ...
... getting sqlt_s34879_sta_report_txt.txt out of sqlt repository ...
... getting sqlt_s34879_sta_script_txt.sql out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting sqlt_s34879_10053_explain.trc out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting sqlt_s34879_import.sh out of sqlt repository ...
... getting sqlt_s34879_export_parfile.txt out of sqlt repository ...
... getting sqlt_s34879_export_parfile2.txt out of sqlt repository ...
... getting plan.sql out of sqlt repository ...
... getting 10053.sql out of sqlt repository ...
... getting flush.sql out of sqlt repository ...
... getting sqlt_s34879_purge.sql out of sqlt repository ...
... getting sqlt_s34879_restore.sql out of sqlt repository ...
... getting sqlt_s34879_del_hgrm.sql out of sqlt repository ...
... getting tc.sql out of sqlt repository ...
... getting xpress.sh out of sqlt repository ...
... getting xpress.sql out of sqlt repository ...
... getting setup.sql out of sqlt repository ...
... getting readme.txt out of sqlt repository ...
... getting tc_pkg.sql out of sqlt repository ...
... getting sel.sql out of sqlt repository ...
... getting sel_aux.sql out of sqlt repository ...
... getting install.sh out of sqlt repository ...
... getting install.sql out of sqlt repository ...
... getting pack_tcx.sql out of sqlt repository ...
... getting sqlt_s34879_awrrpt_driver.sql out of sqlt repository ...
  adding: sqlt_s34879_awrrpt_driver.sql (deflated 47%)
... getting sqlt_s34879_addmrpt_driver.sql out of sqlt repository ...
  adding: sqlt_s34879_addmrpt_driver.sql (deflated 46%)
... getting sqlt_s34879_ashrpt_driver.sql out of sqlt repository ...
... generating sqlt_s34879_ashrpt_0001_mem_1_0826_0930.html ...
  adding: sqlt_s34879_ashrpt_0001_mem_1_0826_0930.html (deflated 80%)
  adding: sqlt_s34879_ashrpt_driver.sql (deflated 60%)
... getting sqlt_s34879_tcb_driver.sql out of sqlt repository ...
  adding: sqlt_s34879_tcb_driver.sql (deflated 13%)
... getting sqlt_s34879_xpand_sql_driver.sql out of sqlt repository ...
... getting sqlt_s34879_export_driver.sql out of sqlt repository ...

*******************************************************************
* Enter SQLTXPLAIN valid password to export SQLT repository       *
* Notes:                                                          *
* 1. If you entered an incorrect password you will have to enter  *
*    now both USER and PASSWORD. The latter is case sensitive     *
* 2. User is SQLTXPLAIN and not your application user.            *
*******************************************************************

Export: Release 10.2.0.4.0 - Production on Tue Aug 26 09:40:57 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: grants on tables/views/sequences/roles will not be exported
Note: indexes on tables will not be exported
Note: constraints on tables will not be exported

About to export specified tables via Conventional Path ...
. . exporting table                  SQLT$_STATTAB       4762 rows exported
Export terminated successfully without warnings.


Export: Release 10.2.0.4.0 - Production on Tue Aug 26 09:40:58 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
Note: grants on tables/views/sequences/roles will not be exported
Note: indexes on tables will not be exported
Note: constraints on tables will not be exported

About to export specified tables via Conventional Path ...
. . exporting table            SQLT$_SQL_STATEMENT          1 rows exported
. . exporting table               SQLT$_AUX_STATS$         13 rows exported
. . exporting table   SQLT$_DBA_COL_STATS_VERSIONS         78 rows exported
. . exporting table           SQLT$_DBA_COL_USAGE$         93 rows exported
. . exporting table          SQLT$_DBA_CONSTRAINTS         50 rows exported
. . exporting table     SQLT$_DBA_HIST_PARAMETER_M         88 rows exported
. . exporting table        SQLT$_DBA_HIST_SNAPSHOT        179 rows exported
. . exporting table  SQLT$_DBA_HISTGRM_STATS_VERSN       2758 rows exported
. . exporting table          SQLT$_DBA_IND_COLUMNS         39 rows exported
. . exporting table       SQLT$_DBA_IND_STATISTICS         17 rows exported
. . exporting table   SQLT$_DBA_IND_STATS_VERSIONS          9 rows exported
. . exporting table              SQLT$_DBA_INDEXES         17 rows exported
. . exporting table              SQLT$_DBA_OBJECTS         20 rows exported
. . exporting table   SQLT$_DBA_OPTSTAT_OPERATIONS         29 rows exported
. . exporting table       SQLT$_DBA_SCHEDULER_JOBS          1 rows exported
. . exporting table             SQLT$_DBA_SEGMENTS         20 rows exported
. . exporting table             SQLT$_DBA_TAB_COLS        190 rows exported
. . exporting table       SQLT$_DBA_TAB_HISTOGRAMS       4825 rows exported
. . exporting table    SQLT$_DBA_TAB_MODIFICATIONS          3 rows exported
. . exporting table       SQLT$_DBA_TAB_STATISTICS          3 rows exported
. . exporting table   SQLT$_DBA_TAB_STATS_VERSIONS          1 rows exported
. . exporting table               SQLT$_DBA_TABLES          3 rows exported
. . exporting table          SQLT$_DBA_TABLESPACES          8 rows exported
. . exporting table               SQLT$_DBMS_XPLAN        243 rows exported
. . exporting table SQLT$_GV$ACTIVE_SESSION_HISTOR         16 rows exported
. . exporting table        SQLT$_GV$NLS_PARAMETERS         19 rows exported
. . exporting table     SQLT$_GV$OBJECT_DEPENDENCY          3 rows exported
. . exporting table            SQLT$_GV$PARAMETER2        263 rows exported
. . exporting table         SQLT$_GV$PARAMETER_CBO        190 rows exported
. . exporting table            SQLT$_GV$PQ_SESSTAT         22 rows exported
. . exporting table            SQLT$_GV$PQ_SYSSTAT         32 rows exported
. . exporting table    SQLT$_GV$PX_PROCESS_SYSSTAT         30 rows exported
. . exporting table    SQLT$_GV$SEGMENT_STATISTICS        510 rows exported
. . exporting table         SQLT$_GV$SESSION_EVENT         19 rows exported
. . exporting table               SQLT$_GV$SESSTAT        760 rows exported
. . exporting table                   SQLT$_GV$SQL          1 rows exported
. . exporting table     SQLT$_GV$SQL_OPTIMIZER_ENV          5 rows exported
. . exporting table              SQLT$_GV$SQL_PLAN         12 rows exported
. . exporting table   SQLT$_GV$SQL_PLAN_STATISTICS         11 rows exported
. . exporting table     SQLT$_GV$SQL_SHARED_CURSOR          1 rows exported
. . exporting table          SQLT$_GV$SQL_WORKAREA          1 rows exported
. . exporting table               SQLT$_GV$SQLAREA          1 rows exported
. . exporting table     SQLT$_GV$SQLAREA_PLAN_HASH          1 rows exported
. . exporting table              SQLT$_GV$SQLSTATS          1 rows exported
. . exporting table SQLT$_GV$SQLTEXT_WITH_NEWLINES         11 rows exported
. . exporting table              SQLT$_GV$STATNAME        380 rows exported
. . exporting table      SQLT$_GV$SYSTEM_PARAMETER        261 rows exported
. . exporting table                      SQLT$_LOG       1475 rows exported
. . exporting table                 SQLT$_METADATA        160 rows exported
. . exporting table  SQLT$_NLS_DATABASE_PARAMETERS         20 rows exported
. . exporting table             SQLT$_OUTLINE_DATA         68 rows exported
. . exporting table           SQLT$_PLAN_EXTENSION         24 rows exported
. . exporting table                SQLT$_PLAN_INFO         12 rows exported
. . exporting table           SQLT$_SQL_PLAN_TABLE         12 rows exported
. . exporting table                  SQLT$_STATTAB       4762 rows exported
. . exporting table    SQLT$_V$SESSION_FIX_CONTROL        115 rows exported
. . exporting table           SQLT$_WRI$_ADV_TASKS          2 rows exported
Export terminated successfully without warnings.

  adding: sqlt_s34879_exp.dmp (deflated 89%)
  adding: sqlt_s34879_import.sh (deflated 33%)
  adding: sqlt_s34879_exp2.dmp (deflated 93%)
  adding: sqlt_s34879_exp.log (deflated 78%)
  adding: sqlt_s34879_exp2.log (deflated 42%)
  adding: sqlt_s34879_export_driver.sql (deflated 67%)
  adding: sqlt_s34879_export_parfile.txt (deflated 73%)
  adding: sqlt_s34879_export_parfile2.txt (deflated 32%)
... getting sqlt_s34879_10046_10053_execute.trc out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting missing_file.txt out of sqlt repository ...
... getting sqlt_s34879_tkprof_px_driver.sql out of sqlt repository ...

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:02 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


  adding: rlzy_ora_3081178_s34879_10046_10053.trc (deflated 87%)
  adding: rlzy_ora_3081178_s34879_10046_10053.tkprof (deflated 91%)
  adding: sqlt_s34879_tkprof_px_driver.sql (deflated 57%)
... getting sqlt_s34879_script_output_driver.sql out of sqlt repository ...
  adding: sqlt_s34879_script_output_driver.sql (deflated 38%)
### copy command below will error out on windows. disregard error.
### copy command below will error out on linux and unix. disregard error.
/usr/bin/ksh: copy:  not found.
### tkprof commands below may error out with "could not open trace file". disregard error.

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:02 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.



TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:03 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


### copy command below will error out on linux and unix. disregard error.
/usr/bin/ksh: copy:  not found.
### tkprof commands below may error out with "could not open trace file". disregard error.

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:04 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


could not open trace file /oracle/admin/RLZY/udump/S34879_SQLT_TRACE.trc

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:04 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


could not open trace file /oracle/admin/RLZY/udump/S34879_SQLT_TRACE.trc
### tkprof commands below may error out with "could not open trace file". disregard error.

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:04 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


could not open trace file *_ora_*_S34879_SQLT_TRACE.trc

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:04 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


could not open trace file *_ora_*_S34879_SQLT_TRACE.trc
  adding: sqlt_s34879_sqlt_tkprof_nosort.txt (deflated 93%)
  adding: sqlt_s34879_sqlt_tkprof_sort.txt (deflated 92%)
updating: alert_RLZY.log (deflated 93%)
  adding: spfileRLZY.ora (deflated 79%)
        zip warning: name not matched: /oracle/product/10.2.0/db_1/cfgtoollogs/opatch/opatch*

zip error: Nothing to do! (sqlt_s34879_opatch.zip)
### chmod command below will error out on windows. disregard error.
  adding: sqlt_s34879_system_stats.sql (deflated 48%)
  adding: sqlt_s34879_set_cbo_env.sql (deflated 74%)
  adding: sqlt_s34879_metadata1.sql (deflated 83%)
  adding: sqlt_s34879_metadata2.sql (deflated 66%)
  adding: q.sql (deflated 52%)
  adding: plan.sql (deflated 27%)
  adding: 10053.sql (deflated 21%)
  adding: flush.sql (deflated 5%)
  adding: tc.sql (deflated 17%)
  adding: sel.sql (deflated 40%)
  adding: sel_aux.sql (deflated 34%)
  adding: install.sql (deflated 58%)
  adding: install.sh (deflated 10%)
  adding: pack_tcx.sql (deflated 64%)
  adding: sqlt_s34879_schema_stats.sql (deflated 52%)
### chmod command below will error out on windows. disregard error.
  adding: sqlt_s34879_system_stats.sql (deflated 48%)
  adding: sqlt_s34879_set_cbo_env.sql (deflated 74%)
  adding: sqlt_s34879_metadata.sql (deflated 82%)
  adding: sqlt_s34879_readme.txt (deflated 75%)
  adding: q.sql (deflated 52%)
  adding: plan.sql (deflated 27%)
  adding: 10053.sql (deflated 21%)
  adding: flush.sql (deflated 5%)
  adding: tc.sql (deflated 17%)
  adding: sel.sql (deflated 40%)
  adding: sel_aux.sql (deflated 34%)
  adding: xpress.sql (deflated 60%)
  adding: xpress.sh (deflated 11%)
  adding: setup.sql (deflated 43%)
  adding: readme.txt (stored 0%)
  adding: tc_pkg.sql (deflated 52%)
  adding: sqlt_s34879_purge.sql (deflated 30%)
  adding: sqlt_s34879_restore.sql (deflated 42%)
  adding: sqlt_s34879_del_hgrm.sql (deflated 26%)
        zip warning: name not matched: sqlt_s34879_opatch.zip

zip error: Nothing to do! (sqlt_s34879_tc.zip)
  adding: rlzy_ora_3081178_s34879_10053.trc (deflated 84%)
  adding: sqlt_s34879_10046_10053_execute.trc (deflated 87%)
  adding: sqlt_s34879_10053_explain.trc (deflated 84%)
### tkprof commands below may error out with "could not open trace file". disregard error.

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:05 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.



TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:05 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


### tkprof commands below may error out with "could not open trace file". disregard error.

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:05 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


could not open trace file rlzy_ora_3081178_s34879_10046_10053.trc

TKPROF: Release 10.2.0.4.0 - Production on Tue Aug 26 09:41:05 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


could not open trace file rlzy_ora_3081178_s34879_10046_10053.trc
  adding: mysql2.sql (deflated 52%)
  adding: sqltxecute.log (deflated 78%)
  adding: sqltxecute2.log (deflated 82%)
  adding: missing_file.txt (deflated 16%)
deleting: sqltxecute.log
deleting: sqltxecute2.log
deleting: missing_file.txt
### ls commands below will error out on windows. disregard error.
### who command below will error out on windows. disregard error.
  adding: sqlt_s34879_xpand_sql_driver.sql (stored 0%)
  adding: sqlt_s34879_cell_state_begin.txt (stored 0%)
  adding: sqlt_s34879_cell_state_begin_and_end.txt (stored 0%)
  adding: sqlt_s34879_cell_state_end.txt (stored 0%)
  adding: sqlt_s34879_xecute.log (deflated 78%)
  adding: sqltxhost.log (deflated 51%)
  adding: sqlt_s34879_10046_10053_execute.trc (deflated 87%)
  adding: sqlt_s34879_10053_explain.trc (deflated 84%)
  adding: sqlt_s34879_ashrpt_0001.zip (stored 0%)
  adding: sqlt_s34879_cell_state.zip (stored 0%)
  adding: sqlt_s34879_driver.zip (stored 0%)
  adding: sqlt_s34879_lite.html (deflated 86%)
  adding: sqlt_s34879_log.zip (stored 0%)
  adding: sqlt_s34879_main.html (deflated 91%)
  adding: sqlt_s34879_readme.html (deflated 73%)
  adding: sqlt_s34879_sta_report_mem.txt (deflated 85%)
  adding: sqlt_s34879_sta_report_txt.txt (deflated 85%)
  adding: sqlt_s34879_sta_script_mem.sql (deflated 67%)
  adding: sqlt_s34879_sta_script_txt.sql (deflated 67%)
  adding: sqlt_s34879_tc.zip (stored 0%)
  adding: sqlt_s34879_tcx.zip (stored 0%)
  adding: sqlt_s34879_tkprof_nosort.txt (deflated 91%)
  adding: sqlt_s34879_tkprof_sort.txt (deflated 91%)
  adding: sqlt_s34879_trc.zip (stored 0%)
Archive:  sqlt_s34879_xecute.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
     1259  08-26-14 09:23   mysql2.sql
   713442  08-26-14 09:41   sqlt_s34879_10046_10053_execute.trc
   169497  08-26-14 09:40   sqlt_s34879_10053_explain.trc
     3117  08-26-14 09:40   sqlt_s34879_ashrpt_0001.zip
      556  08-26-14 09:41   sqlt_s34879_cell_state.zip
     6486  08-26-14 09:41   sqlt_s34879_driver.zip
    47872  08-26-14 09:40   sqlt_s34879_lite.html
  1376973  08-26-14 09:41   sqlt_s34879_log.zip
  2793361  08-26-14 09:40   sqlt_s34879_main.html
    14101  08-26-14 09:40   sqlt_s34879_readme.html
    18123  08-26-14 09:40   sqlt_s34879_sta_report_mem.txt
    18087  08-26-14 09:40   sqlt_s34879_sta_report_txt.txt
     1796  08-26-14 09:40   sqlt_s34879_sta_script_mem.sql
     1796  08-26-14 09:40   sqlt_s34879_sta_script_txt.sql
   382871  08-26-14 09:41   sqlt_s34879_tc.zip
    83017  08-26-14 09:41   sqlt_s34879_tcx.zip
   152642  08-26-14 09:41   sqlt_s34879_tkprof_nosort.txt
   152674  08-26-14 09:41   sqlt_s34879_tkprof_sort.txt
   257761  08-26-14 09:41   sqlt_s34879_trc.zip
 --------                   -------
  6195431                   19 files

File sqlt_s34879_xecute.zip for /oracle/sqlt/input/sample/mysql2.sql has been created.
sqlt_s34879_sqldx
T
CSV
7fv05tum90t4j

Parameter 1:
Oracle Pack License (Tuning or Diagnostics) [T|D] (required)



Parameter 2:
Output Type (HTML or CSV or Both) [H|C|B] (required)



Parameter 3:
SQL_ID of the SQL to be analyzed (required)


Values passed:
License: "T"
Output : "CSV"
SQL_ID : "7fv05tum90t4j"


### ... getting SQL text ...


### ... getting signature ...


### ... getting tables ...


### ... generating dynamic script, please wait ...


sqlt_s34879_sqldx_7fv05tum90t4j_driver.sql file has been created.

###
### by sql_id
###
2014-08-26/09:41:29 DBA_HIST_SQLTEXT
2014-08-26/09:41:29 DBA_SQLSET_PLANS
2014-08-26/09:41:29 DBA_SQLSET_STATEMENTS
2014-08-26/09:41:29 GV$ACTIVE_SESSION_HISTORY
2014-08-26/09:41:31 GV$SQL
2014-08-26/09:41:31 GV$SQLAREA
2014-08-26/09:41:31 GV$SQLAREA_PLAN_HASH
2014-08-26/09:41:31 GV$SQLSTATS
2014-08-26/09:41:31 GV$SQLTEXT
2014-08-26/09:41:31 GV$SQLTEXT_WITH_NEWLINES
2014-08-26/09:41:31 GV$SQL_OPTIMIZER_ENV
2014-08-26/09:41:31 GV$SQL_PLAN
2014-08-26/09:41:32 GV$SQL_PLAN_STATISTICS
2014-08-26/09:41:32 GV$SQL_PLAN_STATISTICS_ALL
2014-08-26/09:41:32 GV$SQL_REDIRECTION
2014-08-26/09:41:36 GV$SQL_SHARED_CURSOR
2014-08-26/09:41:36 GV$SQL_SHARED_MEMORY
2014-08-26/09:41:37 GV$SQL_WORKAREA
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_DBA_HIST_SQLTEXT.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_DBA_SQLSET_PLANS.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_DBA_SQLSET_STATEMENTS.csv (deflated 95%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsACTIVE_SESSION_HISTORY.csv (deflated 96%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL.csv (deflated 82%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLAREA.csv (deflated 98%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLAREA_PLAN_HASH.csv (deflated 82%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLSTATS.csv (deflated 77%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLTEXT.csv (deflated 89%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLTEXT_WITH_NEWLINES.csv (deflated 89%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_OPTIMIZER_ENV.csv (deflated 87%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_PLAN.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_PLAN_STATISTICS.csv (deflated 91%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_PLAN_STATISTICS_ALL.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_REDIRECTION.csv (deflated 94%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_SHARED_CURSOR.csv (deflated 70%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_SHARED_MEMORY.csv (deflated 95%)
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_WORKAREA.csv (deflated 75%)
Archive:  sqlt_s34879_sqldx_7fv05tum90t4j_csv.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    80800  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_DBA_HIST_SQLTEXT.csv
   342745  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_DBA_SQLSET_PLANS.csv
    15441  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_DBA_SQLSET_STATEMENTS.csv
    23832  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsACTIVE_SESSION_HISTORY.csv
     6456  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL.csv
   140280  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLAREA.csv
     5898  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLAREA_PLAN_HASH.csv
     1926  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLSTATS.csv
     1495  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLTEXT.csv
     1495  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQLTEXT_WITH_NEWLINES.csv
     5323  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_OPTIMIZER_ENV.csv
   299724  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_PLAN.csv
     6084  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_PLAN_STATISTICS.csv
   332892  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_PLAN_STATISTICS_ALL.csv
     4712  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_REDIRECTION.csv
      588  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_SHARED_CURSOR.csv
    72891  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_SHARED_MEMORY.csv
     1336  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_GVsSQL_WORKAREA.csv
 --------                   -------
  1343918                   18 files
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_csv.zip (stored 0%)
Archive:  sqlt_s34879_sqldx.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    26770  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_csv.zip
 --------                   -------
    26770                   1 file
###
### by exact signature
###
###
### by force signature
###
2014-08-26/09:41:37 DBA_SQLSET_PLANS
2014-08-26/09:41:37 DBA_SQLSET_STATEMENTS
2014-08-26/09:41:37 GV$ACTIVE_SESSION_HISTORY
2014-08-26/09:41:40 GV$SQL
2014-08-26/09:41:46 GV$SQLAREA
2014-08-26/09:41:52 GV$SQLAREA_PLAN_HASH
  adding: sqlt_s34879_sqldx_3644691823526457268_force_DBA_SQLSET_PLANS.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_3644691823526457268_force_DBA_SQLSET_STATEMENTS.csv (deflated 95%)
  adding: sqlt_s34879_sqldx_3644691823526457268_force_GVsACTIVE_SESSION_HISTORY.csv (deflated 96%)
  adding: sqlt_s34879_sqldx_3644691823526457268_force_GVsSQL.csv (deflated 82%)
  adding: sqlt_s34879_sqldx_3644691823526457268_force_GVsSQLAREA.csv (deflated 82%)
  adding: sqlt_s34879_sqldx_3644691823526457268_force_GVsSQLAREA_PLAN_HASH.csv (deflated 82%)
Archive:  sqlt_s34879_sqldx_3644691823526457268_force_csv.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
   342745  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_DBA_SQLSET_PLANS.csv
    15441  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_DBA_SQLSET_STATEMENTS.csv
    23832  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_GVsACTIVE_SESSION_HISTORY.csv
     6456  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_GVsSQL.csv
     6087  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_GVsSQLAREA.csv
     5898  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_GVsSQLAREA_PLAN_HASH.csv
 --------                   -------
   400459                   6 files
  adding: sqlt_s34879_sqldx_3644691823526457268_force_csv.zip (stored 0%)
Archive:  sqlt_s34879_sqldx.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    26770  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_csv.zip
     9463  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_csv.zip
 --------                   -------
    36233                   2 files
###
### by table
###
2014-08-26/09:41:58 DBA_ALL_TABLES
2014-08-26/09:41:59 DBA_CACHEABLE_TABLES
2014-08-26/09:41:59 DBA_CATALOG
2014-08-26/09:41:59 DBA_COL_COMMENTS
2014-08-26/09:41:59 DBA_CONSTRAINTS
2014-08-26/09:42:00 DBA_CONS_COLUMNS
2014-08-26/09:42:01 DBA_INDEXES
2014-08-26/09:42:01 DBA_IND_COLUMNS
2014-08-26/09:42:01 DBA_IND_STATISTICS
2014-08-26/09:42:02 DBA_SYNONYMS
2014-08-26/09:42:02 DBA_TABLES
2014-08-26/09:42:02 DBA_TAB_COLS
2014-08-26/09:42:02 DBA_TAB_COLUMNS
2014-08-26/09:42:02 DBA_TAB_COL_STATISTICS
2014-08-26/09:42:03 DBA_TAB_COMMENTS
2014-08-26/09:42:03 DBA_TAB_HISTOGRAMS
2014-08-26/09:42:09 DBA_TAB_PRIVS
2014-08-26/09:42:09 DBA_TAB_STATISTICS
2014-08-26/09:42:09 DBA_TAB_STATS_HISTORY
2014-08-26/09:42:09 DBA_UPDATABLE_COLUMNS
2014-08-26/09:42:09 TABLE_PRIVILEGES
  adding: sqlt_s34879_sqldx_table_DBA_ALL_TABLES.csv (deflated 85%)
  adding: sqlt_s34879_sqldx_table_DBA_CACHEABLE_TABLES.csv (deflated 69%)
  adding: sqlt_s34879_sqldx_table_DBA_CATALOG.csv (deflated 75%)
  adding: sqlt_s34879_sqldx_table_DBA_COL_COMMENTS.csv (deflated 88%)
  adding: sqlt_s34879_sqldx_table_DBA_CONSTRAINTS.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_table_DBA_CONS_COLUMNS.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_table_DBA_INDEXES.csv (deflated 95%)
  adding: sqlt_s34879_sqldx_table_DBA_IND_COLUMNS.csv (deflated 99%)
  adding: sqlt_s34879_sqldx_table_DBA_IND_STATISTICS.csv (deflated 89%)
  adding: sqlt_s34879_sqldx_table_DBA_SYNONYMS.csv (deflated 89%)
  adding: sqlt_s34879_sqldx_table_DBA_TABLES.csv (deflated 84%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_COLS.csv (deflated 98%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_COLUMNS.csv (deflated 98%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_COL_STATISTICS.csv (deflated 91%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_COMMENTS.csv (deflated 96%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_HISTOGRAMS.csv (deflated 100%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_PRIVS.csv (deflated 92%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_STATISTICS.csv (deflated 82%)
  adding: sqlt_s34879_sqldx_table_DBA_TAB_STATS_HISTORY.csv (deflated 74%)
  adding: sqlt_s34879_sqldx_table_DBA_UPDATABLE_COLUMNS.csv (deflated 94%)
  adding: sqlt_s34879_sqldx_table_TABLE_PRIVILEGES.csv (deflated 86%)
Archive:  sqlt_s34879_sqldx_table_csv.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
     4437  08-26-14 09:41   sqlt_s34879_sqldx_table_DBA_ALL_TABLES.csv
      235  08-26-14 09:41   sqlt_s34879_sqldx_table_DBA_CACHEABLE_TABLES.csv
      351  08-26-14 09:41   sqlt_s34879_sqldx_table_DBA_CATALOG.csv
    24772  08-26-14 09:41   sqlt_s34879_sqldx_table_DBA_COL_COMMENTS.csv
   225238  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_CONSTRAINTS.csv
   233615  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_CONS_COLUMNS.csv
    36900  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_INDEXES.csv
   171874  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_IND_COLUMNS.csv
     9411  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_IND_STATISTICS.csv
     1510  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_SYNONYMS.csv
     4042  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TABLES.csv
   925879  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_COLS.csv
   908439  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_COLUMNS.csv
    73815  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_COL_STATISTICS.csv
     4450  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_COMMENTS.csv
 19846498  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_HISTOGRAMS.csv
     2410  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_PRIVS.csv
     2267  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_STATISTICS.csv
      500  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_TAB_STATS_HISTORY.csv
    20160  08-26-14 09:42   sqlt_s34879_sqldx_table_DBA_UPDATABLE_COLUMNS.csv
     1114  08-26-14 09:42   sqlt_s34879_sqldx_table_TABLE_PRIVILEGES.csv
 --------                   -------
 22497917                   21 files
  adding: sqlt_s34879_sqldx_table_csv.zip (stored 0%)
Archive:  sqlt_s34879_sqldx.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    26770  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_csv.zip
     9463  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_csv.zip
   150718  08-26-14 09:42   sqlt_s34879_sqldx_table_csv.zip
 --------                   -------
   186951                   3 files
###
### by global
###
2014-08-26/09:42:10 DBA_HIST_SNAPSHOT
2014-08-26/09:42:10 GV$PARAMETER2
  adding: sqlt_s34879_sqldx_global_DBA_HIST_SNAPSHOT.csv (deflated 95%)
  adding: sqlt_s34879_sqldx_global_GVsPARAMETER2.csv (deflated 97%)
Archive:  sqlt_s34879_sqldx_global_csv.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    74029  08-26-14 09:42   sqlt_s34879_sqldx_global_DBA_HIST_SNAPSHOT.csv
   397832  08-26-14 09:42   sqlt_s34879_sqldx_global_GVsPARAMETER2.csv
 --------                   -------
   471861                   2 files
  adding: sqlt_s34879_sqldx_global_csv.zip (stored 0%)
Archive:  sqlt_s34879_sqldx.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    26770  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_csv.zip
     9463  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_csv.zip
   150718  08-26-14 09:42   sqlt_s34879_sqldx_table_csv.zip
    16829  08-26-14 09:42   sqlt_s34879_sqldx_global_csv.zip
 --------                   -------
   203780                   4 files

sqlt_s34879_sqldx_*.zip files have been created.
  adding: sqlt_s34879_sqldx_7fv05tum90t4j_driver.sql (deflated 93%)
  adding: sqldx.log (deflated 60%)

Archive:  sqlt_s34879_sqldx_7fv05tum90t4j_log.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    54527  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_driver.sql
     3917  08-26-14 09:41   sqldx.log
 --------                   -------
    58444                   2 files

  adding: sqlt_s34879_sqldx_7fv05tum90t4j_log.zip (stored 0%)


SQLDX files have been created.

Archive:  sqlt_s34879_sqldx.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    26770  08-26-14 09:41   sqlt_s34879_sqldx_7fv05tum90t4j_csv.zip
     9463  08-26-14 09:41   sqlt_s34879_sqldx_3644691823526457268_force_csv.zip
   150718  08-26-14 09:42   sqlt_s34879_sqldx_table_csv.zip
    16829  08-26-14 09:42   sqlt_s34879_sqldx_global_csv.zip
     5565  08-26-14 09:42   sqlt_s34879_sqldx_7fv05tum90t4j_log.zip
 --------                   -------
   209345                   5 files

  adding: sqlt_s34879_sqldx.zip (stored 0%)


SQLTXECUTE completed.

从上面显示的信息可知生成了sqlt_s34879_sqldx.zip文件,将这个sqlt_s34879_sqldx.zip文件拷贝到测试数据库所在主机上,
这里显示了sqlt_s34879_sqldx.zip文件中的目录信息。

[oracle@jyrac1 sqlt_s34879]$ ls -lrt
total 9036
-rw-r--r-- 1 root   root    1259 Aug 26 09:23 mysql2.sql
-rw-r--r-- 1 root   root   14101 Aug 26 09:40 sqlt_s34879_readme.html
-rw-r--r-- 1 root   root 2793361 Aug 26 09:40 sqlt_s34879_main.html
-rw-r--r-- 1 root   root   47872 Aug 26 09:40 sqlt_s34879_lite.html
-rw-r--r-- 1 root   root    1796 Aug 26 09:40 sqlt_s34879_sta_script_txt.sql
-rw-r--r-- 1 root   root    1796 Aug 26 09:40 sqlt_s34879_sta_script_mem.sql
-rw-r--r-- 1 root   root   18087 Aug 26 09:40 sqlt_s34879_sta_report_txt.txt
-rw-r--r-- 1 root   root   18123 Aug 26 09:40 sqlt_s34879_sta_report_mem.txt
-rw-r--r-- 1 root   root  169497 Aug 26 09:40 sqlt_s34879_10053_explain.trc
-rw-r--r-- 1 root   root    3117 Aug 26 09:40 sqlt_s34879_ashrpt_0001.zip
-rw-r--r-- 1 root   root  713442 Aug 26 09:41 sqlt_s34879_10046_10053_execute.trc
-rw-r--r-- 1 root   root  257761 Aug 26 09:41 sqlt_s34879_trc.zip
-rw-r--r-- 1 root   root  152674 Aug 26 09:41 sqlt_s34879_tkprof_sort.txt
-rw-r--r-- 1 root   root  152642 Aug 26 09:41 sqlt_s34879_tkprof_nosort.txt
-rw-r--r-- 1 root   root  382871 Aug 26 09:41 sqlt_s34879_tc.zip
-rw-r--r-- 1 root   root   83017 Aug 26 09:41 sqlt_s34879_tcx.zip
-rw-r--r-- 1 root   root 1376973 Aug 26 09:41 sqlt_s34879_log.zip
-rw-r--r-- 1 root   root    6486 Aug 26 09:41 sqlt_s34879_driver.zip
-rw-r--r-- 1 root   root     556 Aug 26 09:41 sqlt_s34879_cell_state.zip
-rw-r--r-- 1 root   root  210301 Aug 26 09:42 sqlt_s34879_sqldx.zip
-rw-r--r-- 1 root   root 2750929 Aug 26 10:05 sqlt_s34879_xecute.zip

这个目录列表中有两个文件要注意。第一个sqlt_s34879_tc.zip是一个标准的测试用例文件,第二个sqlt_s34879_tcx.zip是最近才增加的(2012.12)。
1.构建测试用例的步骤
创建测试用例的第一步是在主SQLT区域创建一个子目录。然后复制sqlt_s34879_tc.zip文件到这个子目录中并进行解压。
这样会创建一些文件并且我们将对每一个进行描述。这里是一个示例列表。

[oracle@jyrac1 sqlt_s34879_tc]$ ls -lrt
total 3732
-rwxrwxrwx 1 oracle dba        11964 Aug 26 09:40 sqlt_s34879_readme.txt
-rwxrwxrwx 1 oracle dba          137 Aug 26 09:40 tc.sql
-rwxrwxrwx 1 oracle dba         1240 Aug 26 09:40 sqlt_s34879_system_stats.sql
-rwxrwxrwx 1 oracle dba        36572 Aug 26 09:40 sqlt_s34879_set_cbo_env.sql
-rwxrwxrwx 1 oracle dba          747 Aug 26 09:40 sqlt_s34879_restore.sql
-rwxrwxrwx 1 oracle dba          238 Aug 26 09:40 sqlt_s34879_purge.sql
-rwxrwxrwx 1 oracle dba        22402 Aug 26 09:40 sqlt_s34879_metadata.sql
-rwxrwxrwx 1 oracle dba          663 Aug 26 09:40 sqlt_s34879_import.sh
-rwxrwxrwx 1 oracle dba          261 Aug 26 09:40 sqlt_s34879_del_hgrm.sql
-rwxrwxrwx 1 oracle dba          273 Aug 26 09:40 plan.sql
-rwxrwxrwx 1 oracle dba          101 Aug 26 09:40 flush.sql
-rwxrwxrwx 1 oracle dba          187 Aug 26 09:40 10053.sql
-rwxrwxrwx 1 oracle dba         1049 Aug 26 09:40 xpress.sql
-rwxrwxrwx 1 oracle dba          114 Aug 26 09:40 xpress.sh
-rwxrwxrwx 1 oracle dba          935 Aug 26 09:40 tc_pkg.sql
-rwxrwxrwx 1 oracle dba          438 Aug 26 09:40 setup.sql
-rwxrwxrwx 1 oracle dba          412 Aug 26 09:40 sel.sql
-rwxrwxrwx 1 oracle dba          370 Aug 26 09:40 sel_aux.sql
-rwxrwxrwx 1 oracle dba           37 Aug 26 09:40 readme.txt
-rwxrwxrwx 1 oracle dba      3137536 Aug 26 09:41 sqlt_s34879_exp.dmp
-rwxrwxrwx 1 oracle dba         1259 Aug 26 09:41 q.sql
-rw-r--r-- 1 oracle oinstall   55276 Aug 26 15:12 sqlt_s34879_metadata.log
-rw-r--r-- 1 oracle oinstall    9663 Aug 26 15:12 sqlt_s34879_purge.log
-rw-r--r-- 1 oracle oinstall    4790 Aug 26 15:12 sqlt_s34879_imp.log
-rw-r--r-- 1 oracle oinstall    1798 Aug 26 15:12 sqlt_s34879_restore.log
-rw-r--r-- 1 oracle oinstall    1602 Aug 26 15:12 sqlt_s34879_system_stats.log
-rw-r--r-- 1 oracle oinstall   47794 Aug 26 15:12 sqlt_s34879_set_cbo_env.log
-rw-r--r-- 1 oracle oinstall    3167 Aug 26 15:58 plan.log
-rw-r--r-- 1 oracle oinstall     682 Aug 26 18:24 sel.log

在这个目录中的文件都是必要的(使用SQLT来在你的数据库中创建一个测试用例)。在下一节我们将查看这些文件的详细信息。

2.测试用例文件

目录中的脚本和其它的文件被用来简单和快速地构建一个测试用例。我列出了每一个文件和它们的描述。后面我们将看到怎样使用这些文件来构建一个真实的测试环境。
. 10053.sql—设置10053的跟踪级别为1
. flush.sql—清空共享池
. plan.sql—显示最近执行SQL的执行计划并将其输出到plan.log中,它是调用的dbms_xplan.display_cursor过程来显示执行计划
. q.sql—被调查的SQL
. readme.txt—指令。它们非常简单:例如”connect as sys and execute setup.sql”
. sel.sql—计算谓词选择性。这个脚本依赖于sel_aux.sql并且会打印出表名和谓词然后给你显示出谓词基数和选择性。下面有一个使用sel.sql的示例
. sel_aux.sql—使用sel.sql基于不同的谓词来生成预期的基数和选择性
. setup.sql—设置系统统计信息,创建测试用户和元数据,导入对象统计信息和优化器环境,执行测试查询并显示执行计划
. sqlt_snnnnn_del_hgrm.sql—删除测试用户方案的直方图信息
. sqlt_snnnnn_exp.dmp—包含统计信息的转储文件
. sqlt_snnnnn_import.sh—Unix版本的导入SQLT对象脚本
. sqlt_snnnnn_metadat.sql—setup.sql调用该脚本;创建测试用户和用户对象
. sqlt_snnnnn_purge.sql—从SQL档案库中删除对测试用例SQL的引用
. sqlt_snnnnn_readmet.txt—记录特定的测试用例,包含导出和导入SQLT档案库信息的简单命令,SQLTCOMPARE的使用,还原CBO统计信息和在快捷模式和客户模式下完成测试用例
. sqlt_snnnnn_restore.sql—导入CBO的统计信息到测试用例中
. sqlt_snnnnn_set_cbo_env.sql—设置测试用例的CBO环境
. sqlt_snnnnn_system_stats.sql—设置测试系统的系统统计信息
. tc.sql—运行测试sql并显示执行计划
. tc_pkg.sql—对一些小的测试用例文件进行打包并生成tc.zip文件
. xpress.sh—xpress.sql的Unix版本。用来构建整个测试用例

. xpress.sql—这个脚本以快捷方式来构建整个测试用例

正如你所看到的一旦解压后在sqlt_s34879_tc目录中会生成许多文件。它们中的大部分会被xpress.sql和setup.sql脚本调用,因此我们不会详细讨论它们,
但有一些有趣的单独的功能在我们构建测试用例后来查看。

3.快速构建一个测试用例(XPRESS.sql)
首先我们创建一个目录来存储SQLTXTRACT报告文件。在这个目录中我创建一个TC目录并将测试用例zip文件放入TC目录。现在我们有了测试用例目录,解压测试用例文件来快速和简单的构建一个测试用户。记住你需要用SYS用户进行登录并执行这个操作。这是因为xpress.sql中的有些操作将会改变数据库环境。这种环境是不能与其它用户进行共享的。因此使用有警告的方式来构建一个测试用例。

首先我们将执行xpress.sql。这将在各个部分暂停并给你机会来检查步骤和任何错误。如果没有错误,那么正常情况你只需要按下回车键就会执行下一步操作。脚本中的这些步骤每一个都被突出的显示出来例如:

SQL> @xpress.sql
1/7 Press ENTER to create TC user and schema objects for statement_id 34879.

下面按级别列出了查看脚本的步骤。下面我们将查看这七步操作的详细信息:
1. 创建测试用户,用户对象(包含表和索引),用户名的形式为TCnnnnn。在步骤1中你被要求输入测试用户用户名的前缀。你在这时可以按回车键或者输入像DEV这样的前缀。在这一步的最后你应该检查是否存在任何无效对象。有效对象会被列出来
2. 任何SQL语句以前版本的SQL档案库信息会被清除
3. 使用导入工具SQL语句将被导入到SQL档案库中并且会还原系统环境。你将被要求输入SQLTXPLAIN用户的密码。执行这一步的就是因为你不应该在系统中运行快捷方式不能避免丢失的原因
4. 测试用户方案对象统计信息会被还原
5. 系统统计信息会被还原
6. 你被连接到测试用户方案并设置CBO环境
7. 测试用户方案环境被设置,SQL被执行并显示其执行计划

一旦你到达这个阶段,假设没有任何错误,你就可以自由的修改测试环境(记住在测试完成后这个系统就会被丢弃)。你可以根据提高你测试用例性能的要求进行修改,或者有时为了更好的理解发生的操作和执行计划你可能会对测试用例进行一些修改。下面我们将查看七步操作每一步的详细信息。我们将根据看到的示例输出并解释正在执行的操作。我们将通过这所有的步骤来构建一个能进行测试的测试环境。
1. 在步骤1中你被要求确认你想要创建的测试用户(在我的例子中是TC64661)和方案对象

如果你输入回车键来完成步骤1。在这个步骤中运行了sqlt_metadata.sql脚本。你被要求为测试用户输入一个前缀。通常的值为”_1”,但你可以输入回车键接受缺省值,不使用前缀。然后就会创建元数据对象,比如表和索引,还有其它约束,函数和包,视图或者任何其它的元数据。在这个步骤的最后将会显示对象的状态。它就座都为valid有效。这里是我的示例的一个截屏。

SQL> 
SQL> 
SQL> /**********************************************************************/
SQL> 
SQL> REM PACKAGE
SQL> 
SQL> 
SQL> /**********************************************************************/
SQL> 
SQL> REM VIEW
SQL> 
SQL> 
SQL> /**********************************************************************/
SQL> REM FUNCTION, PROCEDURE, LIBRARY and PACKAGE BODY
SQL> 
SQL> 
SQL> /**********************************************************************/
SQL> 
SQL> REM OTHERS
SQL> 
SQL> 
SQL> 
SQL> /**********************************************************************/
SQL> 
SQL> SET ECHO OFF VER OFF PAGES 1000 LIN 80 LONG 8000000 LONGC 800000;

PL/SQL procedure successfully completed.


:VALID_OBJECTS
--------------------------------------------------------------------------------
VALID TABLE TC34879 MT_APPLY
VALID TABLE TC34879 MT_BIZ_FIN
VALID TABLE TC34879 MT_PAY_RECORD_FIN
VALID INDEX TC34879 IDX$$_429C0001
VALID INDEX TC34879 IDX$$_429C0002
VALID INDEX TC34879 IDX_MT_APPLY_INDI
VALID INDEX TC34879 IDX_MT_APPLY_INPUT
VALID INDEX TC34879 IDX_MT_APPLY_SERIAL
VALID INDEX TC34879 IDX_MT_BIZ_FIN_1
VALID INDEX TC34879 IDX_MT_BIZ_FIN_BEGIN_DATE
VALID INDEX TC34879 IDX_MT_BIZ_FIN_END_DATE
VALID INDEX TC34879 IDX_MT_BIZ_FIN_FIN_DATE
VALID INDEX TC34879 IDX_MT_BIZ_FIN_FIN_DATE_01
VALID INDEX TC34879 IDX_MT_BIZ_FIN_INDI_ID
VALID INDEX TC34879 IDX_MT_PAY_RECORD_FIN_1
VALID INDEX TC34879 IDX_MT_PAY_RECORD_FIN_2
VALID INDEX TC34879 INDI_MT_BIZ_FIN_H_F
VALID INDEX TC34879 PK_MT_APPLY
VALID INDEX TC34879 PK_MT_BIZ_FIN
VALID INDEX TC34879 PK_MT_PAY_RECORD_FIN



:INVALID_OBJECTS
--------------------------------------------------------------------------------


SQL> REM In case of INVALID OBJECTS: review log, fix errors and execute again.
SQL> SPO OFF;
SQL> SET ECHO OFF;

2/7 Press ENTER to purge statement_id 34879 from SQLT repository.

在我们例子中所有元数据对象都是有效的,并且我这里没有包,视图,函数,或过程。因此这里没有无效对象,我输入回车键开始执行步骤2.
2. 在步骤2中将运行sqlt_snnnnn_purge.sql脚本。它将清空任何与被分析SQL语句相关的SQLT档案库信息。在需要的时候重新加载一个测试用例是很常见的。这个脚本的输出类似如:

SQL> @@sqlt_s34879_purge.sql
SQL> REM Purges statement_id 34879 from local SQLT repository. Just execute "@sqlt_s34879_purge.sql" from sqlplus.
SQL> SPO sqlt_s34879_purge.log;
SQL> SET SERVEROUT ON;
SQL> EXEC SQLTXADMIN.sqlt$a.purge_repository(34879, 34879);
15:12:11    0 sqlt$a: purging statement_id = "34879"
15:12:12    1 sqlt$a:        0 rows deleted from SQLI$_DBA_HIST_PARAMETER
15:12:12    0 sqlt$a:        0 rows deleted from SQLI$_DB_LINK
15:12:12    0 sqlt$a:        0 rows deleted from SQLI$_FILE
15:12:12    0 sqlt$a:       13 rows deleted from SQLT$_AUX_STATS$
15:12:12    0 sqlt$a:        0 rows deleted from SQLT$_DBA_AUDIT_POLICIES
15:12:12    0 sqlt$a:        0 rows deleted from SQLT$_DBA_AUTOTASK_CLIENT
15:12:12    0 sqlt$a:        0 rows deleted from SQLT$_DBA_AUTOTASK_CLIENT_HST
15:12:12    0 sqlt$a:       78 rows deleted from SQLT$_DBA_COL_STATS_VERSIONS
15:12:12    0 sqlt$a:       93 rows deleted from SQLT$_DBA_COL_USAGE$
15:12:12    0 sqlt$a:       50 rows deleted from SQLT$_DBA_CONSTRAINTS
15:12:12    0 sqlt$a:        0 rows deleted from SQLT$_DBA_DEPENDENCIES
15:12:13    1 sqlt$a:     2758 rows deleted from SQLT$_DBA_HISTGRM_STATS_VERSN
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_HIST_ACTIVE_SESS_HIS
15:12:13    0 sqlt$a:       88 rows deleted from SQLT$_DBA_HIST_PARAMETER_M
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_HIST_SEG_STAT_OBJ
15:12:13    0 sqlt$a:      179 rows deleted from SQLT$_DBA_HIST_SNAPSHOT
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_HIST_SQLBIND
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_HIST_SQLSTAT
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_HIST_SQLTEXT
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_HIST_SQL_PLAN
15:12:13    0 sqlt$a:       17 rows deleted from SQLT$_DBA_INDEXES
15:12:13    0 sqlt$a:       39 rows deleted from SQLT$_DBA_IND_COLUMNS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_IND_EXPRESSIONS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_IND_PARTITIONS
15:12:13    0 sqlt$a:       17 rows deleted from SQLT$_DBA_IND_STATISTICS
15:12:13    0 sqlt$a:        9 rows deleted from SQLT$_DBA_IND_STATS_VERSIONS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_IND_SUBPARTITIONS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_NESTED_TABLES
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_NESTED_TABLE_COLS
15:12:13    0 sqlt$a:       20 rows deleted from SQLT$_DBA_OBJECTS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_OBJECT_TABLES
15:12:13    0 sqlt$a:       29 rows deleted from SQLT$_DBA_OPTSTAT_OPERATIONS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_OUTLINES
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_OUTLINE_HINTS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_PART_COL_STATISTICS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_PART_HISTOGRAMS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_PART_KEY_COLUMNS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_POLICIES
15:12:13    0 sqlt$a:        1 rows deleted from SQLT$_DBA_SCHEDULER_JOBS
15:12:13    0 sqlt$a:       20 rows deleted from SQLT$_DBA_SEGMENTS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SOURCE
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SQLTUNE_PLANS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SQL_PATCHES
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SQL_PLAN_BASELINES
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SQL_PLAN_DIRECTIVES
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SQL_PLAN_DIR_OBJS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SQL_PROFILES
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_STAT_EXTENSIONS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SUBPART_COL_STATS
15:12:13    0 sqlt$a:        0 rows deleted from SQLT$_DBA_SUBPART_HISTOGRAMS
15:12:13    0 sqlt$a:        3 rows deleted from SQLT$_DBA_TABLES
15:12:13    0 sqlt$a:        8 rows deleted from SQLT$_DBA_TABLESPACES
15:12:13    0 sqlt$a:      190 rows deleted from SQLT$_DBA_TAB_COLS
15:12:14    1 sqlt$a:        0 rows deleted from SQLT$_DBA_TAB_COL_STATISTICS
15:12:14    0 sqlt$a:     4825 rows deleted from SQLT$_DBA_TAB_HISTOGRAMS
15:12:14    0 sqlt$a:        3 rows deleted from SQLT$_DBA_TAB_MODIFICATIONS
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_DBA_TAB_PARTITIONS
15:12:14    0 sqlt$a:        3 rows deleted from SQLT$_DBA_TAB_STATISTICS
15:12:14    0 sqlt$a:        1 rows deleted from SQLT$_DBA_TAB_STATS_VERSIONS
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_DBA_TAB_SUBPARTITIONS
15:12:14    0 sqlt$a:      243 rows deleted from SQLT$_DBMS_XPLAN
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_DISPLAY_MAP
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_FND_HISTOGRAM_COLS
15:12:14    0 sqlt$a:       16 rows deleted from SQLT$_GV$ACTIVE_SESSION_HISTOR
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$CELL_STATE
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$IM_COLUMN_LEVEL
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$IM_SEGMENTS
15:12:14    0 sqlt$a:       19 rows deleted from SQLT$_GV$NLS_PARAMETERS
15:12:14    0 sqlt$a:        3 rows deleted from SQLT$_GV$OBJECT_DEPENDENCY
15:12:14    0 sqlt$a:      263 rows deleted from SQLT$_GV$PARAMETER2
15:12:14    0 sqlt$a:      190 rows deleted from SQLT$_GV$PARAMETER_CBO
15:12:14    0 sqlt$a:       22 rows deleted from SQLT$_GV$PQ_SESSTAT
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$PQ_SLAVE
15:12:14    0 sqlt$a:       32 rows deleted from SQLT$_GV$PQ_SYSSTAT
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$PQ_TQSTAT
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$PX_INSTANCE_GROUP
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$PX_PROCESS
15:12:14    0 sqlt$a:       30 rows deleted from SQLT$_GV$PX_PROCESS_SYSSTAT
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$PX_SESSION
15:12:14    0 sqlt$a:        0 rows deleted from SQLT$_GV$PX_SESSTAT
15:12:14    0 sqlt$a:      510 rows deleted from SQLT$_GV$SEGMENT_STATISTICS
15:12:14    0 sqlt$a:       19 rows deleted from SQLT$_GV$SESSION_EVENT
15:12:14    0 sqlt$a:      760 rows deleted from SQLT$_GV$SESSTAT
15:12:15    1 sqlt$a:        1 rows deleted from SQLT$_GV$SQL
15:12:15    0 sqlt$a:        1 rows deleted from SQLT$_GV$SQLAREA
15:12:15    0 sqlt$a:        1 rows deleted from SQLT$_GV$SQLAREA_PLAN_HASH
15:12:15    0 sqlt$a:        1 rows deleted from SQLT$_GV$SQLSTATS
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$SQLSTATS_PLAN_HASH
15:12:15    0 sqlt$a:       11 rows deleted from SQLT$_GV$SQLTEXT_WITH_NEWLINES
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$SQL_BIND_CAPTURE
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$SQL_CS_HISTOGRAM
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$SQL_CS_SELECTIVITY
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$SQL_CS_STATISTICS
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$SQL_MONITOR
15:12:15    0 sqlt$a:        5 rows deleted from SQLT$_GV$SQL_OPTIMIZER_ENV
15:12:15    0 sqlt$a:       12 rows deleted from SQLT$_GV$SQL_PLAN
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$SQL_PLAN_MONITOR
15:12:15    0 sqlt$a:       11 rows deleted from SQLT$_GV$SQL_PLAN_STATISTICS
15:12:15    0 sqlt$a:        1 rows deleted from SQLT$_GV$SQL_SHARED_CURSOR
15:12:15    0 sqlt$a:        1 rows deleted from SQLT$_GV$SQL_WORKAREA
15:12:15    0 sqlt$a:      380 rows deleted from SQLT$_GV$STATNAME
15:12:15    0 sqlt$a:      261 rows deleted from SQLT$_GV$SYSTEM_PARAMETER
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_GV$VPD_POLICY
15:12:15    0 sqlt$a:     1475 rows deleted from SQLT$_LOG
15:12:15    0 sqlt$a:      160 rows deleted from SQLT$_METADATA
15:12:15    0 sqlt$a:       20 rows deleted from SQLT$_NLS_DATABASE_PARAMETERS
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_OPTSTAT_USER_PREFS$
15:12:15    0 sqlt$a:       68 rows deleted from SQLT$_OUTLINE_DATA
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_PEEKED_BINDS
15:12:15    0 sqlt$a:       24 rows deleted from SQLT$_PLAN_EXTENSION
15:12:15    0 sqlt$a:       12 rows deleted from SQLT$_PLAN_INFO
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_SQLOBJ$
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_SQLOBJ$DATA
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_SQLPROF$
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_SQLPROF$ATTR
15:12:15    0 sqlt$a:       12 rows deleted from SQLT$_SQL_PLAN_TABLE
15:12:15    0 sqlt$a:        0 rows deleted from SQLT$_SQL_SHARED_CURSOR_D
15:12:15    0 sqlt$a:        1 rows deleted from SQLT$_SQL_STATEMENT
15:12:16    1 sqlt$a:      115 rows deleted from SQLT$_V$SESSION_FIX_CONTROL
15:12:16    0 sqlt$a:        0 rows deleted from SQLT$_WRI$_ADV_RATIONALE
15:12:16    0 sqlt$a:        2 rows deleted from SQLT$_WRI$_ADV_TASKS
15:12:16    0 sqlt$a:        0 rows deleted from SQLT$_WRI$_OPTSTAT_AUX_HISTORY
15:12:19    3 sqlt$a:     4762 rows deleted from SQLI$_STATTAB_TEMP
15:12:19    0 sqlt$a:     4762 rows deleted from SQLT$_STATTAB
15:12:19    0 sqlt$a:        0 rows deleted from SQLT$_STGTAB_BASELINE
15:12:19    0 sqlt$a:        0 rows deleted from SQLT$_STGTAB_DIRECTIVE
15:12:19    0 sqlt$a:        0 rows deleted from SQLT$_STGTAB_SQLPROF
15:12:19    0 sqlt$a:        0 rows deleted from SQLT$_STGTAB_SQLSET
15:12:19    0 sqlt$a:        0 rows deleted from SQLI$_STGTAB_SQLPROF
15:12:19    0 sqlt$a:        7 rows deleted from SQLI$_STGTAB_SQLSET
15:12:19    0 sqlt$a: 130 tables were purged for statement_id = "34879"

PL/SQL procedure successfully completed.

SQL> SET SERVEROUT OFF;
SQL> SPO OFF;
SQL> SET ECHO OFF;

3/7 Press ENTER to import SQLT repository for statement_id 34879.

3. 步骤3将从目标系统收集到的数据导入到SQLT档案库中。这里显示输出信息:

SQL> HOS imp SQLTXPLAIN FILE=sqlt_s34879_exp.dmp LOG=sqlt_s34879_imp.log TABLES=sqlt% IGNORE=Y

Import: Release 11.2.0.1.0 - Production on Tue Aug 26 15:12:22 2014

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Password: 

你需要输入SQLTXPLAIN用户的密码。当你输入密码并按下回车键时就会开始进行导入。下面是示例输出信息。

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SQLTXPLAIN's objects into SQLTXPLAIN
. importing SQLTXPLAIN's objects into SQLTXPLAIN
. . importing table          "SQLT$_SQL_STATEMENT"          1 rows imported
. . importing table             "SQLT$_AUX_STATS$"         13 rows imported
. . importing table "SQLT$_DBA_COL_STATS_VERSIONS"         78 rows imported
. . importing table         "SQLT$_DBA_COL_USAGE$"         93 rows imported
. . importing table        "SQLT$_DBA_CONSTRAINTS"         50 rows imported
. . importing table   "SQLT$_DBA_HIST_PARAMETER_M"         88 rows imported
. . importing table      "SQLT$_DBA_HIST_SNAPSHOT"        179 rows imported
. . importing table "SQLT$_DBA_HISTGRM_STATS_VERSN"       2758 rows imported
. . importing table        "SQLT$_DBA_IND_COLUMNS"         39 rows imported
. . importing table     "SQLT$_DBA_IND_STATISTICS"         17 rows imported
. . importing table "SQLT$_DBA_IND_STATS_VERSIONS"          9 rows imported
. . importing table            "SQLT$_DBA_INDEXES"         17 rows imported
. . importing table            "SQLT$_DBA_OBJECTS"         20 rows imported
. . importing table "SQLT$_DBA_OPTSTAT_OPERATIONS"         29 rows imported
. . importing table     "SQLT$_DBA_SCHEDULER_JOBS"          1 rows imported
. . importing table           "SQLT$_DBA_SEGMENTS"         20 rows imported
. . importing table           "SQLT$_DBA_TAB_COLS"        190 rows imported
. . importing table     "SQLT$_DBA_TAB_HISTOGRAMS"       4825 rows imported
. . importing table  "SQLT$_DBA_TAB_MODIFICATIONS"          3 rows imported
. . importing table     "SQLT$_DBA_TAB_STATISTICS"          3 rows imported
. . importing table "SQLT$_DBA_TAB_STATS_VERSIONS"          1 rows imported
. . importing table             "SQLT$_DBA_TABLES"          3 rows imported
. . importing table        "SQLT$_DBA_TABLESPACES"          8 rows imported
. . importing table             "SQLT$_DBMS_XPLAN"        243 rows imported
. . importing table "SQLT$_GV$ACTIVE_SESSION_HISTOR"         16 rows imported
. . importing table      "SQLT$_GV$NLS_PARAMETERS"         19 rows imported
. . importing table   "SQLT$_GV$OBJECT_DEPENDENCY"          3 rows imported
. . importing table          "SQLT$_GV$PARAMETER2"        263 rows imported
. . importing table       "SQLT$_GV$PARAMETER_CBO"        190 rows imported
. . importing table          "SQLT$_GV$PQ_SESSTAT"         22 rows imported
. . importing table          "SQLT$_GV$PQ_SYSSTAT"         32 rows imported
. . importing table  "SQLT$_GV$PX_PROCESS_SYSSTAT"         30 rows imported
. . importing table  "SQLT$_GV$SEGMENT_STATISTICS"        510 rows imported
. . importing table       "SQLT$_GV$SESSION_EVENT"         19 rows imported
. . importing table             "SQLT$_GV$SESSTAT"        760 rows imported
. . importing table                 "SQLT$_GV$SQL"          1 rows imported
. . importing table   "SQLT$_GV$SQL_OPTIMIZER_ENV"          5 rows imported
. . importing table            "SQLT$_GV$SQL_PLAN"         12 rows imported
. . importing table "SQLT$_GV$SQL_PLAN_STATISTICS"         11 rows imported
. . importing table   "SQLT$_GV$SQL_SHARED_CURSOR"          1 rows imported
. . importing table        "SQLT$_GV$SQL_WORKAREA"          1 rows imported
. . importing table             "SQLT$_GV$SQLAREA"          1 rows imported
. . importing table   "SQLT$_GV$SQLAREA_PLAN_HASH"          1 rows imported
. . importing table            "SQLT$_GV$SQLSTATS"          1 rows imported
. . importing table "SQLT$_GV$SQLTEXT_WITH_NEWLINES"         11 rows imported
. . importing table            "SQLT$_GV$STATNAME"        380 rows imported
. . importing table    "SQLT$_GV$SYSTEM_PARAMETER"        261 rows imported
. . importing table                    "SQLT$_LOG"       1475 rows imported
. . importing table               "SQLT$_METADATA"        160 rows imported
. . importing table "SQLT$_NLS_DATABASE_PARAMETERS"         20 rows imported
. . importing table           "SQLT$_OUTLINE_DATA"         68 rows imported
. . importing table         "SQLT$_PLAN_EXTENSION"         24 rows imported
. . importing table              "SQLT$_PLAN_INFO"         12 rows imported
. . importing table         "SQLT$_SQL_PLAN_TABLE"         12 rows imported
. . importing table                "SQLT$_STATTAB"       4762 rows imported
. . importing table  "SQLT$_V$SESSION_FIX_CONTROL"        115 rows imported
. . importing table         "SQLT$_WRI$_ADV_TASKS"          2 rows imported
Import terminated successfully without warnings.

SQL> SET ECHO OFF;

4/7 Press ENTER to restore schema object stats for TC34879.

正如你所看到的导入对象列表,步骤3已经将SQLT在执行SQLTXTRACT时所捕获到的信息导入在SQLT档案库中。然后你被要求执行步骤4,它将还原测试用例对象的统计信息。
4. 按下回车键开始处理步骤4。在步骤4中将使用SQLT档案库中的信息来替换数据字典的信息。这就是为什么你能对系统重建的原因。步骤4的输出信息如下:

SQL> @@sqlt_s34879_restore.sql
SQL> REM Restores schema object stats for statement_id 34879 from local SQLT repository into data dictionary. Just execute "@sqlt_s34879_restore.sql" from sqlplus.
SQL> SPO sqlt_s34879_restore.log;
SQL> SET SERVEROUT ON;
SQL> TRUNCATE TABLE SQLTXPLAIN.SQLI$_STATTAB_TEMP;

Table truncated.

SQL> ALTER SESSION SET optimizer_dynamic_sampling = 0;

Session altered.

SQL> ALTER SESSION SET EVENTS '10046 TRACE NAME CONTEXT FOREVER, LEVEL 12';

Session altered.

SQL> -- if you need to upload stats history so you can use SQLT XHUME you need to pass p_load_hist as Y
SQL> EXEC SQLTXADMIN.sqlt$a.import_cbo_stats(p_statement_id => 's34879', p_schema_owner => '&&tc_user.', p_include_bk => 'N', p_make_bk => 'N', p_load_hist => 'N');
remapping stats into user TC34879(99)
obtain statistics staging table version for this system
statistics version for this system: 5
+-----+
upgrade/downgrade of sqli$_stattab_temp to version 5 as per this system
restoring cbo stats for table TC34879.MT_APPLY
restoring cbo stats for table TC34879.MT_BIZ_FIN
restoring cbo stats for table TC34879.MT_PAY_RECORD_FIN
+
|
|   Stats from id "s34879_rlzy_ibmp7401"
|   have been restored into data dict
|
|           METRIC   IN STATTAB  RESTORED  OK
|     -------------  ----------  --------  --
|       STATS ROWS:        4762      4762  OK
|           TABLES:           3         3  OK
|       TABLE PART:           0         0  OK
|    TABLE SUBPART:           0         0  OK
|          INDEXES:          17        17  OK
|       INDEX PART:           0         0  OK
|    INDEX SUBPART:           0         0  OK
|          COLUMNS:        4742      4742  OK
|      COLUMN PART:           0         0  OK
|   COLUMN SUBPART:           0         0  OK
|     AVG AGE DAYS:        42.4      42.4  OK
|
+

PL/SQL procedure successfully completed.

SQL> ALTER SESSION SET SQL_TRACE = FALSE;

Session altered.

SQL> ALTER SESSION SET optimizer_dynamic_sampling = 2;

Session altered.

SQL> SET SERVEROUT OFF;
SQL> SPO OFF;
SQL> SET ECHO OFF;

5/7 Press ENTER to restore system statistics.

我们只是将对象统计信息导入到系统中的TC64661用户中因此它们是测试用户方案的统计信息。在这个过程的最后我们看到每一个对象的统计信息被成功导入并且要求我们处理步骤5。
5. 在步骤5中我们要删除已经存在的系统统计信息(我已经说了只有在系统中没有生产数据和其它用户时你才这么做)。然后用对系统统计信息设置新值。然后要求我们处理步骤6。

SQL> @@sqlt_s34879_system_stats.sql
SQL> SPO sqlt_s34879_system_stats.log;
SQL> SET ECHO ON TERM ON;
SQL> REM
SQL> REM $Header: 215187.1 sqlt_s34879_system_stats.sql 12.1.09 2014/08/26 mauro.pagano $
SQL> REM
SQL> REM Copyright (c) 2000-2014, Oracle Corporation. All rights reserved.
SQL> REM
SQL> REM AUTHOR
SQL> REM   mauro.pagano@oracle.com
SQL> REM
SQL> REM SCRIPT
SQL> REM   sqlt_s34879_system_stats.sql
SQL> REM
SQL> REM SOURCE
SQL> REM   Host    : IBMP740-1
SQL> REM   DB Name : RLZY
SQL> REM   Platform: IBM/AIX RISC System/6000
SQL> REM   Product : Oracle Database 10g Enterprise Edition (64bi)
SQL> REM   Version : 10.2.0.4.0
SQL> REM   Language: US:AMERICAN_AMERICA.ZHS16GBK
SQL> REM   EBS     : NO
SQL> REM   Siebel  : NO
SQL> REM   PSFT    : NO
SQL> REM
SQL> REM DESCRIPTION
SQL> REM   This script is generated automatically by the SQLT tool.
SQL> REM   It contains the SQL*Plus commands to set the CBO System
SQL> REM   Statistics as found on IBMP740-1
SQL> REM   at the time SQL 7fv05tum90t4j was analyzed by SQLT.
SQL> REM
SQL> REM PARAMETERS
SQL> REM   None.
SQL> REM
SQL> REM EXAMPLE
SQL> REM   SQL> START sqlt_s34879_system_stats.sql;
SQL> REM
SQL> REM NOTES
SQL> REM   1. Should be run as SYSTEM or SYSDBA.
SQL> REM
SQL> 
SQL> EXEC SYS.DBMS_STATS.DELETE_SYSTEM_STATS;

PL/SQL procedure successfully completed.

SQL> EXEC SYS.DBMS_STATS.SET_SYSTEM_STATS('CPUSPEEDNW', 855.040470934511);

PL/SQL procedure successfully completed.

SQL> EXEC SYS.DBMS_STATS.SET_SYSTEM_STATS('IOSEEKTIM', 10);

PL/SQL procedure successfully completed.

SQL> EXEC SYS.DBMS_STATS.SET_SYSTEM_STATS('IOTFRSPEED', 4096);

PL/SQL procedure successfully completed.

SQL> 
SQL> SPO OFF;
SQL> SET ECHO OFF;

6/7 Press ENTER to connect as TC34879 and set CBO env.

6. 在步骤6中我们将使用测试用户来登录数据库。输出信息如下:

SQL> CONN &&tc_user./&&tc_user.
Connected.
SQL> @@sqlt_s34879_set_cbo_env.sql

脚本sqlt_s34879_set_cbo_env.sql将设置CBO环境。它很重要你应该在执行它前查看其内容。

SQL> ALTER SESSION SET optimizer_features_enable = '10.2.0.4';
Session altered.
SQL>
SQL> SET ECHO OFF;
Press ENTER to execute ALTER SYSTEM/SESSION commands to set CBO env.

当你输入回车键时,所有的CBO环境设置将在系统级别进行。在我的例子中日志文件包含以下信息:

/*************************************************************************************/
SQL>
SQL> REM Non-Default or Modified Parameters
SQL>
SQL> -- enable modification monitoring. isdefault="TRUE" ismodified="SYSTEM_MOD"
issys_modifiable="IMMEDIATE"
SQL> ALTER SYSTEM SET "_dml_monitoring_enabled" = TRUE SCOPE=MEMORY;
System altered.
SQL>
SQL> -- optimizer secure view merging and predicate pushdown/movearound. isdefault="TRUE"
ismodified="SYSTEM_MOD" issys_modifiable="IMMEDIATE"
SQL> ALTER SYSTEM SET optimizer_secure_view_merging = TRUE SCOPE=MEMORY;
System altered.
SQL>
SQL> -- number of CPUs for this instance. isdefault="TRUE" ismodified="SYSTEM_MOD"
issys_modifiable="IMMEDIATE"
SQL> ALTER SYSTEM SET cpu_count = 2 SCOPE=MEMORY;
System altered.
SQL> -- number of parallel execution threads per CPU. isdefault="TRUE" ismodified="SYSTEM_MOD"
issys_modifiable="IMMEDIATE"
SQL> ALTER SYSTEM SET parallel_threads_per_cpu = 2 SCOPE=MEMORY;
System altered.
SQL>
SQL> -- Maximum size of the PGA memory for one process. isdefault="TRUE" ismodified="SYSTEM_MOD"
issys_modifiable="IMMEDIATE"
SQL> ALTER SYSTEM SET "_pga_max_size" = 209715200 SCOPE=MEMORY;
System altered.
SQL>
SQL> -- optimizer use feedback. isdefault="TRUE" ismodified="SYSTEM_MOD"
SQL> ALTER SESSION SET "_optimizer_use_feedback" = TRUE;
Session altered.
SQL>
SQL> -- optimizer dynamic sampling. isdefault="TRUE" ismodified="SYSTEM_MOD"
SQL> ALTER SESSION SET optimizer_dynamic_sampling = 0;
Session altered.

注意我们是如何修改系统参数的。例如optimizer_dynamic_sampling被设置为0。这是不缺省值,这里日志文件中所记录的对隐含会话参数的设置:

SQL>
SQL> -- compute join cardinality using non-rounded input values
SQL> ALTER SESSION SET "_optimizer_new_join_card_computation" = TRUE;
Session altered.
SQL>
SQL> -- null-aware antijoin parameter
SQL> ALTER SESSION SET "_optimizer_null_aware_antijoin" = TRUE;
Session altered.
SQL> -- Use subheap for optimizer or-expansion
SQL> ALTER SESSION SET "_optimizer_or_expansion_subheap" = TRUE;
Session altered.
SQL>
SQL> -- Eliminates order bys from views before query transformation
SQL> ALTER SESSION SET "_optimizer_order_by_elimination_enabled" = TRUE;
Session altered.

注意前面例子中的隐含参数。我们甚至设置了_fix_control参数,在下面的例子中,fix_control参数控制着特定的bug修复(包含数据库的)是否启用还是禁用。这里给出了日志文件中fix control部分的信息(我们将在下一章中讨论fix control)。

SQL>
SQL> -- remove distribution method optimization for insert/update qbc (ofe 11.2.0.1) (event 0)
SQL> ALTER SESSION SET "_fix_control" = '6376551:1';
Session altered.
SQL>
SQL> -- Convert outer-join to inner-join if single set aggregate functio (ofe 11.1.0.7) (event 0)
SQL> ALTER SESSION SET "_fix_control" = '6377505:1';
Session altered.
At the end of step 6 we are prompted to execute the test case.
SQL> /*********************************
SQL>
SQL> SPO OFF;
SQL> SET ECHO OFF;
7/7 Press ENTER to execute test case.

7. 在步骤7中我们最后从我们的测试环境中执行SQL。用测试用户来执行测试用例并将输出查询结果和执行计划。在我们的示例中输出结果如下所示:

SQL> @@tc.sql
SQL> REM Executes SQL on TC then produces execution plan. Just execute "@tc.sql" from sqlplus.
SQL> SET APPI OFF SERVEROUT OFF;
SQL> @@q.sql
SQL> REM
SQL> 
SQL> -- execute sqlt xecute as sh passing script name
SQL> -- cd sqlt
SQL> -- #sqlplus sh
SQL> -- SQL> start run/sqltxecute.sql input/sample/script1.sql
SQL> 
SQL> REM Optional ALTER SESSION commands
SQL> REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL> 
SQL> --ALTER SESSION SET statistics_level = ALL;
SQL> 
SQL> REM Optional Binds
SQL> REM ~~~~~~~~~~~~~~
SQL> 
SQL> VAR b1 NUMBER;
SQL> EXEC :b1 := 10;

PL/SQL procedure successfully completed.

SQL> 
SQL> REM SQL statement to be executed
SQL> REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL> 
SQL> SELECT /*+ gather_plan_statistics monitor bind_aware */
  2         /* ^^unique_id */
  3  nvl(sum(real_pay), 0) as dYearA131
  4    from mt_biz_fin a, mt_pay_record_fin b, mt_apply c
  5   where a.hospital_id = b.hospital_id
  6     and a.serial_no = b.serial_no
  7     and a.treatment_type = '131'
  8     and a.indi_id = 5609194
  9     and a.serial_apply = 135888
 10     and a.valid_flag = '1'
 11     and b.valid_flag = '1'
 12     and a.serial_apply = c.serial_apply
 13     and c.valid_flag = '1'
 14     and b.POLICY_ITEM_CODE in ('C000', 'C001', 'C004')
 15     and exists (select 1
 16            from mt_pay_record_fin b
 17           where b.fund_id not in ('003', '999')
 18             and a.serial_no = b.serial_no);

 DYEARA131
----------
         0

SQL> /

 DYEARA131
----------
         0

SQL> /

 DYEARA131
----------
         0

SQL> 
SQL> REM Notes:
SQL> REM 1. SQL must contain token: /* ^^unique_id */
SQL> REM 2. Do not replace ^^unique_id with your own tag.
SQL> REM 3. SQL may contain CBO Hints, like:
SQL> REM    /*+ gather_plan_statistics monitor bind_aware */
SQL> 
SQL> @@plan.sql
SQL> REM Displays plan for most recently executed SQL. Just execute "@plan.sql" from sqlplus.
SQL> SET PAGES 2000 LIN 180;
SQL> SPO plan.log;
SQL> --SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR);
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,'BASIC ROWS COST PREDICATE'));

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPLAINED SQL STATEMENT:
------------------------
SELECT /*+ gather_plan_statistics monitor bind_aware */        /*
^^unique_id */ nvl(sum(real_pay), 0) as dYearA131   from mt_biz_fin a,
mt_pay_record_fin b, mt_apply c  where a.hospital_id = b.hospital_id
and a.serial_no = b.serial_no    and a.treatment_type = '131'    and
a.indi_id = 5609194    and a.serial_apply = 135888    and a.valid_flag
= '1'    and b.valid_flag = '1'    and a.serial_apply = c.serial_apply
  and c.valid_flag = '1'    and b.POLICY_ITEM_CODE in ('C000', 'C001',
'C004')    and exists (select 1           from mt_pay_record_fin b
    where b.fund_id not in ('003', '999')            and a.serial_no =
b.serial_no)

Plan hash value: 3265746456

----------------------------------------------------------------------------------------
| Id  | Operation                        | Name                   | Rows  | Cost (%CPU)|
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                 |                        |       | 83997 (100)|
|   1 |  SORT AGGREGATE                  |                        |     1 |            |
|*  2 |   HASH JOIN SEMI                 |                        |     1 | 83997   (2)|
|*  3 |    TABLE ACCESS BY INDEX ROWID   | MT_PAY_RECORD_FIN      |     1 |     1   (0)|
|   4 |     NESTED LOOPS                 |                        |     1 |     6   (0)|
|   5 |      NESTED LOOPS                |                        |     1 |     5   (0)|
|*  6 |       TABLE ACCESS BY INDEX ROWID| MT_APPLY               |     1 |     1   (0)|
|*  7 |        INDEX UNIQUE SCAN         | PK_MT_APPLY            |     1 |     1   (0)|
|*  8 |       TABLE ACCESS BY INDEX ROWID| MT_BIZ_FIN             |     1 |     4   (0)|
|*  9 |        INDEX RANGE SCAN          | IDX_MT_BIZ_FIN_INDI_ID |    23 |     1   (0)|
|* 10 |      INDEX RANGE SCAN            | IDX$$_429C0002         |     1 |     1   (0)|
|* 11 |    TABLE ACCESS FULL             | MT_PAY_RECORD_FIN      |  9218K| 83900   (2)|
----------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("A"."SERIAL_NO"="B"."SERIAL_NO")
   3 - filter((INTERNAL_FUNCTION("B"."POLICY_ITEM_CODE") AND
              "B"."VALID_FLAG"='1'))
   6 - filter("C"."VALID_FLAG"='1')
   7 - access("C"."SERIAL_APPLY"=135888)
   8 - filter(("A"."SERIAL_APPLY"=135888 AND "A"."TREATMENT_TYPE"='131' AND
              "A"."VALID_FLAG"='1'))
   9 - access("A"."INDI_ID"=5609194)
  10 - access("A"."HOSPITAL_ID"="B"."HOSPITAL_ID" AND
              "A"."SERIAL_NO"="B"."SERIAL_NO")
  11 - filter(("B"."FUND_ID"<>'999' AND "B"."FUND_ID"<>'003'))


47 rows selected.

上面是在linux Oracle 11g中测试的执行计划

而在原系统aix Oracle 10g中的执行计划如下:

SQL> select nvl(sum(real_pay), 0) as dYearA131
  2    from mt_biz_fin a, mt_pay_record_fin b, mt_apply c
  3   where a.hospital_id = b.hospital_id
  4     and a.serial_no = b.serial_no
  5     and a.treatment_type = '131'
  6     and a.indi_id = 5609194
  7     and a.serial_apply = 135888
  8     and a.valid_flag = '1'
  9     and b.valid_flag = '1'
 10     and a.serial_apply = c.serial_apply
 11     and c.valid_flag = '1'
 12     and b.POLICY_ITEM_CODE in ('C000', 'C001', 'C004')
 13     and exists (select 1
 14            from mt_pay_record_fin b
 15           where b.fund_id not in ('003', '999')
 16             and a.serial_no = b.serial_no)
 17  ;

 DYEARA131
----------
    1466.4

SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,'BASIC ROWS COST PREDICATE'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPLAINED SQL STATEMENT:
------------------------
select nvl(sum(real_pay), 0) as dYearA131   from mt_biz_fin a,
mt_pay_record_fin b, mt_apply c  where a.hospital_id = b.hospital_id    and
a.serial_no = b.serial_no    and a.treatment_type = '131'    and a.indi_id =
5609194    and a.serial_apply = 135888    and a.valid_flag = '1'    and
b.valid_flag = '1'    and a.serial_apply = c.serial_apply    and c.valid_flag =
'1'    and b.POLICY_ITEM_CODE in ('C000', 'C001', 'C004')    and exists (select
1           from mt_pay_record_fin b          where b.fund_id not in ('003',
'999')            and a.serial_no = b.serial_no)

Plan hash value: 2582817425

----------------------------------------------------------------------------------------
| Id  | Operation                        | Name                   | Rows  | Cost (%CPU)|
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                 |                        |       | 83997 (100)|
|   1 |  SORT AGGREGATE                  |                        |     1 |            |
|*  2 |   HASH JOIN SEMI                 |                        |     1 | 83997   (2)|
|*  3 |    TABLE ACCESS BY INDEX ROWID   | MT_PAY_RECORD_FIN      |     1 |     1   (0)|
|   4 |     NESTED LOOPS                 |                        |     1 |     6   (0)|
|   5 |      NESTED LOOPS                |                        |     1 |     5   (0)|
|*  6 |       TABLE ACCESS BY INDEX ROWID| MT_APPLY               |     1 |     1   (0)|
|*  7 |        INDEX UNIQUE SCAN         | PK_MT_APPLY            |     1 |     1   (0)|
|*  8 |       TABLE ACCESS BY INDEX ROWID| MT_BIZ_FIN             |     1 |     4   (0)|
|*  9 |        INDEX RANGE SCAN          | IDX_MT_BIZ_FIN_INDI_ID |    23 |     1   (0)|
|* 10 |      INDEX RANGE SCAN            | IDX$$_429C0002         |     1 |     1   (0)|
|* 11 |    TABLE ACCESS FULL             | MT_PAY_RECORD_FIN      |  9218K| 83900   (2)|
----------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("A"."SERIAL_NO"="B"."SERIAL_NO")
   3 - filter((INTERNAL_FUNCTION("B"."POLICY_ITEM_CODE") AND
              "B"."VALID_FLAG"='1'))
   6 - filter("C"."VALID_FLAG"='1')
   7 - access("C"."SERIAL_APPLY"=135888)
   8 - filter(("A"."SERIAL_APPLY"=135888 AND "A"."TREATMENT_TYPE"='131' AND
              "A"."VALID_FLAG"='1'))
   9 - access("A"."INDI_ID"=5609194)
  10 - access("A"."HOSPITAL_ID"="B"."HOSPITAL_ID" AND
              "A"."SERIAL_NO"="B"."SERIAL_NO")
  11 - filter(("B"."FUND_ID"<>'999' AND "B"."FUND_ID"<>'003'))


45 rows selected.

从上面的结果来看我们已经在linux Oracle 11g中成功构建了一个测试环境。

oracle 11g使用DML Error Logging来避免bulk insert故障

使用DML Error Logging来避免bulk insert故障
当使用带有子查询的insert语句来加载数据时如果出现错误.系统会终止该语句并回滚整个操作.这是非常消耗时间和资源的操作.如果insert这样的语句可以使用DML Error Logging功能来避免这种情况.

为了使用DML error logging功能需要增加一个子句来指定error logging表名来记录当DML操作所遇到的错误记录.当向insert
语句增加一个error logging子句时特定类型的错误将不会被终止和回滚语句.相反每一个错误记录会被记录到表中操作语句能继续执行.在操作完成后可以对错误记录执行修正操作.

DML error logging功能可以与insert,update,merge和delete语句一起使用.

为了使用DML error logging功能来插入数据
1.来创建一个error logging表
可以手工创建或者使用dbms_errlog包来自动创建.

2.执行一个包含error logging子句的insert语句:
.可以选择引用自己创建的error logging表.如果没有提供一个error logging表表名.数据库会使用一个缺省的error logging表.
缺省的error loggin表名为err$_后面紧接着是插入表名的前25个字符.

.可以选择包含一个标签(一个数字或者有括号的字符串)它将添加到错误日志中来帮助你识别哪个语句产生的错误.如果标签被忽略将使用null值

.可以选择包含reject limit子句
这个子句指示在insert语句终止和回滚之前可以遇到的错误的最大数量.可以指定为unlimited.缺省的reject limit为0,这意味着
在遇到第一个错误时会记录错误并回滚语句.对于并行操作reject limit应用到每一个并行服务器进程.

3.查询error logging表对于产生错误的行执行修正.

error logging表的格式
一个error logging表由两部分组成:
.描述错误的一组强制列.例如一个列包含了oracle的错误代码

.包含造成错误行数据的一组可选列.这些列名与执行插入操作的表中的列名相匹配.
error logging表中的这部分的列数可以是0,1或者多个直到与DML表中的列数相等.如果在error logging表中的列与DML表中的列
有相同的名字,那么违反插入操作的行记录中的相关数据会被写入这个error logging表中的列中.如果DML表中的列在error logging表中没有与之相关的列,那么这个列将不会记录.如果error logging表包含一个与DML表不相匹配的列那么这个列会被忽略.

因为类型转换错误是一种可能出现的错误类型,在error logging表中的可选列的数据类型必须是能捕获任何值而不会丢失数据或转换错误的数据类型.(如果可选日志列与DML表列有相同的数据类型,那么记录捕获问题数据时也会有相同的数据转换问题).数据库为了记录造成转换错误的数据的有用信息做出了最大努力.如果值不能通过派生得到,对于这个列会记录null值.插入errog logging表的一个错误会导致语句终止.

表:强制错误描述列

--------------------------------------------------------------------------------------------------------------
列名                            数据类型              描述
--------------------------------------------------------------------------------------------------------------
ora_err_number$                 number                oracle错误代码
ora_err_mesg$                   varchar2(2000)        oracle错误消息文本
ora_err_rowid$                  rowid                 错误行的rowid(对于更新和删除)
ora_err_optyp$                  varchar2(2)           操作类型:insert(i),update(u),delete(d)
                                                      注意:来自merge操作的update子句和insert子句的错误
                                                      通过U,I来区分
ora_err_tag$                    varchar2(2000)        提供给error logging子句的标签值
--------------------------------------------------------------------------------------------------------------

表:错误日志表的列数据类型

--------------------------------------------------------------------------------------------------------------
DML表列类型          错误日志表的列类型             注意
--------------------------------------------------------------------------------------------------------------
number               varchar2(4000)                 能够记录转换错误
char/varchar2(n)     varchar2(4000)                 记录没有信息丢失的任何值
nchar/nvarchar2(n)   nvarchar2(4000)                记录没有信息丢失的任何值
date/timestamp       varchar2(4000)                 记录没有信息丢失的任何值.使用缺省的date/time格式来转换成
                                                    字符格式
raw                  raw(2000)                      记录没有信息丢失的任何值
rowid                urowid                         记录任何类型的rowid
long/lob                                            不支持
用户定义数据类型                                    不支持
--------------------------------------------------------------------------------------------------------------

创建错误日志表
可以手工创建一个错误日志表或者使用pl/sql包来自动创建

使用dbms_errlog包可以自动创建一个错误日志表.create_error_log过程将创建一个有所有强制描述错误的列加上DML表中所有列
的一个错误日志表
​首先创建一个要存储数据的表test_emp

SQL> create table test_emp as select * from hr.employees where 1=2;

Table created.

SQL> alter table test_emp add primary key (employee_id);

Table altered.

先向test_temp表中插入一条记录因为让后面的插入操作产生违反主键约束的错误

SQL> insert into test_emp select * from hr.employees where rownum<2;

1 row created.

SQL> commit;

创建错误日志表

SQL> execute dbms_errlog.create_error_log('TEST_EMP','ERR_EMP');

PL/SQL procedure successfully completed.

SQL> desc err_emp
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ORA_ERR_NUMBER$                                    NUMBER
 ORA_ERR_MESG$                                      VARCHAR2(2000)
 ORA_ERR_ROWID$                                     ROWID
 ORA_ERR_OPTYP$                                     VARCHAR2(2)
 ORA_ERR_TAG$                                       VARCHAR2(2000)
 EMPLOYEE_ID                                        VARCHAR2(4000)
 FIRST_NAME                                         VARCHAR2(4000)
 LAST_NAME                                          VARCHAR2(4000)
 EMAIL                                              VARCHAR2(4000)
 PHONE_NUMBER                                       VARCHAR2(4000)
 HIRE_DATE                                          VARCHAR2(4000)
 JOB_ID                                             VARCHAR2(4000)
 SALARY                                             VARCHAR2(4000)
 COMMISSION_PCT                                     VARCHAR2(4000)
 MANAGER_ID                                         VARCHAR2(4000)
 DEPARTMENT_ID                                      VARCHAR2(4000)

执行插入操作

SQL> insert into test_emp select * from hr.employees log errors into err_emp('test_load1') reject limit 40;

106 rows created.

SQL> insert into test_emp select * from hr.employees log errors into err_emp('test_load1') reject limit 1000;

0 rows created.

SQL> commit;

Commit complete.

查看错误信息

SQL> select * from err_emp;
 
ORA_ERR_NUMBER$ ORA_ERR_MESG$                                                 ORA_ERR_ROWID$   ORA_ERR_OPTYP$ ORA_ERR_TAG$    EMPLOYEE_ID   FIRST_NAME         LAST_NAME            EMAIL                PHONE_NUMBER         HIRE_DATE        JOB_ID           SALARY       COMMISSION_PCT     MANAGER_ID     DEPARTMENT_ID
--------------- ------------------------------------------------------------- ---------------- -------------- --------------- ------------- ------------------ -------------------- -------------------- -------------------- ---------------- ---------------- ------------ ------------------ -------------- ------------------
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load       198           Donald             OConnell             DOCONNEL             650.507.9833         21-JUN-07        SH_CLERK         2600                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      198           Donald             OConnell             DOCONNEL             650.507.9833         21-JUN-07        SH_CLERK         2600                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      199           Douglas            Grant                DGRANT               650.507.9844         13-JAN-08        SH_CLERK         2600                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      200           Jennifer           Whalen               JWHALEN              515.123.4444         17-SEP-03        AD_ASST          4400                            101            10
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      201           Michael            Hartstein            MHARTSTE             515.123.5555         17-FEB-04        MK_MAN           13000                           100            20
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      202           Pat                Fay                  PFAY                 603.123.6666         17-AUG-05        MK_REP           6000                            201            20
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      203           Susan              Mavris               SMAVRIS              515.123.7777         07-JUN-02        HR_REP           6500                            101            40
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      204           Hermann            Baer                 HBAER                515.123.8888         07-JUN-02        PR_REP           10000                           101            70
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      205           Shelley            Higgins              SHIGGINS             515.123.8080         07-JUN-02        AC_MGR           12008                           101            110
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      206           William            Gietz                WGIETZ               515.123.8181         07-JUN-02        AC_ACCOUNT       8300                            205            110
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      100           Steven             King                 SKING                515.123.4567         17-JUN-03        AD_PRES          24000                                          90
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      101           Neena              Kochhar              NKOCHHAR             515.123.4568         21-SEP-05        AD_VP            17000                           100            90
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      102           Lex                De Haan              LDEHAAN              515.123.4569         13-JAN-01        AD_VP            17000                           100            90
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      103           Alexander          Hunold               AHUNOLD              590.423.4567         03-JAN-06        IT_PROG          9000                            102            60
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      104           Bruce              Ernst                BERNST               590.423.4568         21-MAY-07        IT_PROG          6000                            103            60
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      105           David              Austin               DAUSTIN              590.423.4569         25-JUN-05        IT_PROG          4800                            103            60
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      106           Valli              Pataballa            VPATABAL             590.423.4560         05-FEB-06        IT_PROG          4800                            103            60
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      107           Diana              Lorentz              DLORENTZ             590.423.5567         07-FEB-07        IT_PROG          4200                            103            60
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      108           Nancy              Greenberg            NGREENBE             515.124.4569         17-AUG-02        FI_MGR           12008                           101            100
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      109           Daniel             Faviet               DFAVIET              515.124.4169         16-AUG-02        FI_ACCOUNT       9000                            108            100
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      110           John               Chen                 JCHEN                515.124.4269         28-SEP-05        FI_ACCOUNT       8200                            108            100
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      111           Ismael             Sciarra              ISCIARRA             515.124.4369         30-SEP-05        FI_ACCOUNT       7700                            108            100
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      112           Jose Manuel        Urman                JMURMAN              515.124.4469         07-MAR-06        FI_ACCOUNT       7800                            108            100
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      113           Luis               Popp                 LPOPP                515.124.4567         07-DEC-07        FI_ACCOUNT       6900                            108            100
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      114           Den                Raphaely             DRAPHEAL             515.127.4561         07-DEC-02        PU_MAN           11000                           100            30
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      115           Alexander          Khoo                 AKHOO                515.127.4562         18-MAY-03        PU_CLERK         3100                            114            30
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      116           Shelli             Baida                SBAIDA               515.127.4563         24-DEC-05        PU_CLERK         2900                            114            30
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      117           Sigal              Tobias               STOBIAS              515.127.4564         24-JUL-05        PU_CLERK         2800                            114            30
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      118           Guy                Himuro               GHIMURO              515.127.4565         15-NOV-06        PU_CLERK         2600                            114            30
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      119           Karen              Colmenares           KCOLMENA             515.127.4566         10-AUG-07        PU_CLERK         2500                            114            30
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      120           Matthew            Weiss                MWEISS               650.123.1234         18-JUL-04        ST_MAN           8000                            100            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      121           Adam               Fripp                AFRIPP               650.123.2234         10-APR-05        ST_MAN           8200                            100            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      122           Payam              Kaufling             PKAUFLIN             650.123.3234         01-MAY-03        ST_MAN           7900                            100            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      123           Shanta             Vollman              SVOLLMAN             650.123.4234         10-OCT-05        ST_MAN           6500                            100            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      124           Kevin              Mourgos              KMOURGOS             650.123.5234         16-NOV-07        ST_MAN           5800                            100            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      125           Julia              Nayer                JNAYER               650.124.1214         16-JUL-05        ST_CLERK         3200                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      126           Irene              Mikkilineni          IMIKKILI             650.124.1224         28-SEP-06        ST_CLERK         2700                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      127           James              Landry               JLANDRY              650.124.1334         14-JAN-07        ST_CLERK         2400                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      128           Steven             Markle               SMARKLE              650.124.1434         08-MAR-08        ST_CLERK         2200                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      129           Laura              Bissot               LBISSOT              650.124.5234         20-AUG-05        ST_CLERK         3300                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      130           Mozhe              Atkinson             MATKINSO             650.124.6234         30-OCT-05        ST_CLERK         2800                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      131           James              Marlow               JAMRLOW              650.124.7234         16-FEB-05        ST_CLERK         2500                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      132           TJ                 Olson                TJOLSON              650.124.8234         10-APR-07        ST_CLERK         2100                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      133           Jason              Mallin               JMALLIN              650.127.1934         14-JUN-04        ST_CLERK         3300                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      134           Michael            Rogers               MROGERS              650.127.1834         26-AUG-06        ST_CLERK         2900                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      135           Ki                 Gee                  KGEE                 650.127.1734         12-DEC-07        ST_CLERK         2400                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      136           Hazel              Philtanker           HPHILTAN             650.127.1634         06-FEB-08        ST_CLERK         2200                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      137           Renske             Ladwig               RLADWIG              650.121.1234         14-JUL-03        ST_CLERK         3600                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      138           Stephen            Stiles               SSTILES              650.121.2034         26-OCT-05        ST_CLERK         3200                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      139           John               Seo                  JSEO                 650.121.2019         12-FEB-06        ST_CLERK         2700                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      140           Joshua             Patel                JPATEL               650.121.1834         06-APR-06        ST_CLERK         2500                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      141           Trenna             Rajs                 TRAJS                650.121.8009         17-OCT-03        ST_CLERK         3500                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      142           Curtis             Davies               CDAVIES              650.121.2994         29-JAN-05        ST_CLERK         3100                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      143           Randall            Matos                RMATOS               650.121.2874         15-MAR-06        ST_CLERK         2600                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      144           Peter              Vargas               PVARGAS              650.121.2004         09-JUL-06        ST_CLERK         2500                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      145           John               Russell              JRUSSEL              011.44.1344.429268   01-OCT-04        SA_MAN           14000        .4                 100            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      146           Karen              Partners             KPARTNER             011.44.1344.467268   05-JAN-05        SA_MAN           13500        .3                 100            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      147           Alberto            Errazuriz            AERRAZUR             011.44.1344.429278   10-MAR-05        SA_MAN           12000        .3                 100            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      148           Gerald             Cambrault            GCAMBRAU             011.44.1344.619268   15-OCT-07        SA_MAN           11000        .3                 100            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      149           Eleni              Zlotkey              EZLOTKEY             011.44.1344.429018   29-JAN-08        SA_MAN           10500        .2                 100            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      150           Peter              Tucker               PTUCKER              011.44.1344.129268   30-JAN-05        SA_REP           10000        .3                 145            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      151           David              Bernstein            DBERNSTE             011.44.1344.345268   24-MAR-05        SA_REP           9500         .25                145            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      152           Peter              Hall                 PHALL                011.44.1344.478968   20-AUG-05        SA_REP           9000         .25                145            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      153           Christopher        Olsen                COLSEN               011.44.1344.498718   30-MAR-06        SA_REP           8000         .2                 145            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      154           Nanette            Cambrault            NCAMBRAU             011.44.1344.987668   09-DEC-06        SA_REP           7500         .2                 145            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      155           Oliver             Tuvault              OTUVAULT             011.44.1344.486508   23-NOV-07        SA_REP           7000         .15                145            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      156           Janette            King                 JKING                011.44.1345.429268   30-JAN-04        SA_REP           10000        .35                146            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      157           Patrick            Sully                PSULLY               011.44.1345.929268   04-MAR-04        SA_REP           9500         .35                146            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      158           Allan              McEwen               AMCEWEN              011.44.1345.829268   01-AUG-04        SA_REP           9000         .35                146            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      159           Lindsey            Smith                LSMITH               011.44.1345.729268   10-MAR-05        SA_REP           8000         .3                 146            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      160           Louise             Doran                LDORAN               011.44.1345.629268   15-DEC-05        SA_REP           7500         .3                 146            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      161           Sarath             Sewall               SSEWALL              011.44.1345.529268   03-NOV-06        SA_REP           7000         .25                146            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      162           Clara              Vishney              CVISHNEY             011.44.1346.129268   11-NOV-05        SA_REP           10500        .25                147            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      163           Danielle           Greene               DGREENE              011.44.1346.229268   19-MAR-07        SA_REP           9500         .15                147            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      164           Mattea             Marvins              MMARVINS             011.44.1346.329268   24-JAN-08        SA_REP           7200         .1                 147            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      165           David              Lee                  DLEE                 011.44.1346.529268   23-FEB-08        SA_REP           6800         .1                 147            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      166           Sundar             Ande                 SANDE                011.44.1346.629268   24-MAR-08        SA_REP           6400         .1                 147            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      167           Amit               Banda                ABANDA               011.44.1346.729268   21-APR-08        SA_REP           6200         .1                 147            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      168           Lisa               Ozer                 LOZER                011.44.1343.929268   11-MAR-05        SA_REP           11500        .25                148            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      169           Harrison           Bloom                HBLOOM               011.44.1343.829268   23-MAR-06        SA_REP           10000        .2                 148            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      170           Tayler             Fox                  TFOX                 011.44.1343.729268   24-JAN-06        SA_REP           9600         .2                 148            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      171           William            Smith                WSMITH               011.44.1343.629268   23-FEB-07        SA_REP           7400         .15                148            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      172           Elizabeth          Bates                EBATES               011.44.1343.529268   24-MAR-07        SA_REP           7300         .15                148            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      173           Sundita            Kumar                SKUMAR               011.44.1343.329268   21-APR-08        SA_REP           6100         .1                 148            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      174           Ellen              Abel                 EABEL                011.44.1644.429267   11-MAY-04        SA_REP           11000        .3                 149            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      175           Alyssa             Hutton               AHUTTON              011.44.1644.429266   19-MAR-05        SA_REP           8800         .25                149            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      176           Jonathon           Taylor               JTAYLOR              011.44.1644.429265   24-MAR-06        SA_REP           8600         .2                 149            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      177           Jack               Livingston           JLIVINGS             011.44.1644.429264   23-APR-06        SA_REP           8400         .2                 149            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      178           Kimberely          Grant                KGRANT               011.44.1644.429263   24-MAY-07        SA_REP           7000         .15                149            
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      179           Charles            Johnson              CJOHNSON             011.44.1644.429262   04-JAN-08        SA_REP           6200         .1                 149            80
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      180           Winston            Taylor               WTAYLOR              650.507.9876         24-JAN-06        SH_CLERK         3200                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      181           Jean               Fleaur               JFLEAUR              650.507.9877         23-FEB-06        SH_CLERK         3100                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      182           Martha             Sullivan             MSULLIVA             650.507.9878         21-JUN-07        SH_CLERK         2500                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      183           Girard             Geoni                GGEONI               650.507.9879         03-FEB-08        SH_CLERK         2800                            120            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      184           Nandita            Sarchand             NSARCHAN             650.509.1876         27-JAN-04        SH_CLERK         4200                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      185           Alexis             Bull                 ABULL                650.509.2876         20-FEB-05        SH_CLERK         4100                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      186           Julia              Dellinger            JDELLING             650.509.3876         24-JUN-06        SH_CLERK         3400                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      187           Anthony            Cabrio               ACABRIO              650.509.4876         07-FEB-07        SH_CLERK         3000                            121            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      188           Kelly              Chung                KCHUNG               650.505.1876         14-JUN-05        SH_CLERK         3800                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      189           Jennifer           Dilly                JDILLY               650.505.2876         13-AUG-05        SH_CLERK         3600                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      190           Timothy            Gates                TGATES               650.505.3876         11-JUL-06        SH_CLERK         2900                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      191           Randall            Perkins              RPERKINS             650.505.4876         19-DEC-07        SH_CLERK         2500                            122            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      192           Sarah              Bell                 SBELL                650.501.1876         04-FEB-04        SH_CLERK         4000                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      193           Britney            Everett              BEVERETT             650.501.2876         03-MAR-05        SH_CLERK         3900                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      194           Samuel             McCain               SMCCAIN              650.501.3876         01-JUL-06        SH_CLERK         3200                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      195           Vance              Jones                VJONES               650.501.4876         17-MAR-07        SH_CLERK         2800                            123            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      196           Alana              Walsh                AWALSH               650.507.9811         24-APR-06        SH_CLERK         3100                            124            50
              1 ORA-00001: unique constraint (SYS.SYS_C0014361) violated                       I              test_load1      197           Kevin              Feeney               KFEENEY              650.507.9822         23-MAY-06        SH_CLERK         3000                            124            50
 
108 rows selected
 

从err_emp表中的记录可以看到不能插入test_emp的记录的错误信息是因为违反主键约束.

error logging的限制和警告
当执行DML操作时出现以下错误时oracle数据库会进行记录:
.列的值太长
.违反约束(not null,unique,referential,check)
.在触发器执行时触发的错误
.在子查询列与DML表相关列之间类型转换的错误
.分区映射错误
.特定的merge操作错误(ora-30926:Unable to get a stable set of rows for MERGE operation)

有一些错误不会记录且会造成DML操作终止和回滚.

ORA-27102: out of memory Linux-x86_64 Error: 12: Cannot allocate memory的处理

客户的oracle数据库启动报错,操作linux,oracle 11g由于将lock_sga参数设置为true当重启数据库时报错ORA-27102: out of memory

SQL> startup nomount
ORA-27102: out of memory
Linux-x86_64 Error: 12: Cannot allocate memory

原因是因为操作参数没有设置为允许sga所指定大小的内存可以被锁定

[root@jyrac1 ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 16384
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

解决方法有两种
一:ulimit -l unlimited 在启动实例之前执行只对当前会话有效

[root@jyrac1 ~]# ulimit -l unlimited

[root@jyrac1 ~]# su - oracle
[oracle@jyrac1 ~]$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 16384
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[oracle@jyrac1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 6 12:20:26 2014

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  313159680 bytes
Fixed Size                  2212936 bytes
Variable Size             109054904 bytes
Database Buffers          197132288 bytes
Redo Buffers                4759552 bytes

SQL> show parameter lock_sga

NAME                                 TYPE                    VALUE
------------------------------------ ----------------------  ------------------------------
lock_sga                             boolean                 TRUE

二:修改/etc/security/limits.conf加入以下信息
oracle soft memlock 10485760
orcale hard memlock 10485760
允许锁定10G的内存

SQL> startup nomount
ORACLE instance started.

Total System Global Area  730714112 bytes
Fixed Size                  2216944 bytes
Variable Size             524291088 bytes
Database Buffers          197132288 bytes
Redo Buffers                7073792 bytes

还有lock_sga参数设置为true是不能启用自动内存管理的

SQL> show parameter memory

NAME                                 TYPE                      VALUE
------------------------------------ ----------------------    ------------------------------
hi_shared_memory_address             integer                   0
memory_max_target                    big integer               0
memory_target                        big integer               0
shared_memory_address                integer                   0

SQL> alter system set memory_max_target=700M scope=spfile;

System altered.

SQL> alter system set memory_target=600M scope=spfile;

System altered.


SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup nomount
ORA-00847: MEMORY_TARGET/MEMORY_MAX_TARGET and LOCK_SGA cannot be set together

说明lock_sga参数设置为true时是不能启用自动内存管理的

insert语句造成latch:library cache,latch:shared pool争用的问题

某社保系统在业务高峰期间系统响应缓慢.下面出现在这个征状时的awr报告

 1

在16时分钟的运行时间内DB Time;到了300分钟.服务器是2颗(2核的)CPU

2 
3

共享池的大小为9808M,每秒解析次数183次,每秒硬解析43

4

等待事件中latch:library cache,latch:shared pool,latch free是主要的等待事件.这些是与解析相关的.

5
6 

在16分钟的运行时间内latch:library cache总的等待时间为18433秒.latch:shared pool总的等待时间为4330,latch free总的等待时间为3499

7
8
9
 
 10
Cursor_sharing参数为exact
11

最消耗共享池内存和存在高版本游标的是insert语句. 通过version_rpt3_23.sql脚本查看insert语句不能共享的原因是绑定变量丢失.

INSERT INTO KCD4 (AAC001, AAE030, AAE031, AAE117, AAE208, AAE209, AAZ107, AAZ208, AAZ216, AAZ217, AJE001, AKA030, AKA130, AKC228, AKC291, AKE029, AKE030, AKE032, AKE033, AKE034, AKE035, AKE036, AKE037, AKE038, AKE039, AKE040, AKE041, AKE042, AKE043, AKE044, AKE045, AKE046, AKE047, AKE049, AKE050, AKE051, ALC113, ALC136, ALE001, AME001, AKB081, AKC264, AAA027, AKE025, AKE009, AKE011, AKE012, AKE016, AKE018, AKE019, AKE026, AKE071, AKE072, AKE073, AKE074, AKE075, AKE076, AKE077, AKE078, AKE079, PRSENO, BKA001, AAE100, BKA003, AKE083, AKE084, AKE085, AKE086, AKE087, AKE088, AKE089, AKE090/*AKE080*/) VALUES(: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, :37, :38, :39, :40, :41, :42, :43, :44, :45, :46, :47, :48, :49, :50, :51, :52, :53, :54, :55, :56, :57, :58, :59, :60, :61, :62, :63, :64, :65, :66, :67, :68, :69, :70, :71, :72)

上面的语句的形式为
Insert into table(column1, column2, column72) values (:1, :2, :3, …:72)
这种插入语句是通过对象映射工具生成的.其中values子句中存在许多的null值.对于insert into 或者select into可以考虑不要使用绑定变量.对于一个字段很多的表,在insert的时候不要把值为null, 字段允许为空的所有字段都体现在insert语句中.因为当字段为null时,在解析时是没办法判断类型和长度的,当这样的字段太多时sql语句是没办法共享的.对于这种问题修改insert语句的写法是最佳的解决办法.上面的awr报告中的共享池内存在自动管理模式下增长到了9808M,buffer cache为6,528M.可以考虑手工来指定shared pool和buffer cache的大小.

Oracle 连接因式分解(Join Factorization)

连接因式分解(Join Factorization)是优化器处理带union all的目标SQL的一种优化手段,它是指优化器在处理以union all连接的目标SQL的各个分支时,不再原封不动地分别重复执行每个分支,而是会把各个分支中公共的部分提出来作为一个单独的结果集,然后再和原union all中剩下的部分做表连接。连接因式分解在Oracle 11gr2中才被引入,它的好处是显而易见的。如果不把union all中公共的部分提出来,则意味着这些公共部分中所包含的表会在union all的各个分支中被重复访问;而连接因式分解则能够在最大程度上避免这种重复访问现象的产生,当union all的公共部分所包含的表的数据量很大时,减少一次对大表的重复访问,那也意味着执行效率的巨大提升。

我们来看一个连接因式分解的实例。先来看用union all连接的例子:

select t2.prod_id as prod_id
from sales t2,customers t3
where t2.cust_id=t3.cust_id
and t3.cust_gender='MALE'
union all
select t2.prod_id as prod_id
from sales t2,customers t3
where t2.cust_id=t3.cust_id
and t3.cust_gender='FEMALE';

范例SQL的union all的各个分支中仅仅是针对表customers的列cust_gender的限制条件不一样,剩下的部分都是一模一样的,这也意味着表sales就是范例SQL的公共部分。如果这里Oracle不把sales表提出来,不对此SQL做连接因式分解,那就意味着要重复访问表sales两次。

来验证一下。先在Oracle 10gr2中执行范例SQL:

SQL> select t2.prod_id as prod_id
  2  from sales t2,customers t3
  3  where t2.cust_id=t3.cust_id
  4  and t3.cust_gender='MALE'
  5  union all
  6  select t2.prod_id as prod_id
  7  from sales t2,customers t3
  8  where t2.cust_id=t3.cust_id
  9  and t3.cust_gender='FEMALE';

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 4184572088

------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                       | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |                      |  1837K|    28M|  1098  (54)| 00:00:14 |       |       |
|   1 |  UNION-ALL                      |                      |       |       |            |          |       |       |
|*  2 |   HASH JOIN                     |                      |   918K|    14M|   549   (8)| 00:00:07 |       |       |
|*  3 |    VIEW                         | index$_join$_002     | 27236 |   186K|   122   (4)| 00:00:02 |       |       |
|*  4 |     HASH JOIN                   |                      |       |       |            |          |       |       |
|   5 |      BITMAP CONVERSION TO ROWIDS|                      | 27236 |   186K|     2   (0)| 00:00:01 |       |       |
|*  6 |       BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|   7 |      INDEX FAST FULL SCAN       | CUSTOMERS_PK         | 27236 |   186K|   147   (2)| 00:00:02 |       |       |
|   8 |    PARTITION RANGE ALL          |                      |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
|   9 |     TABLE ACCESS FULL           | SALES                |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
|* 10 |   HASH JOIN                     |                      |   918K|    14M|   549   (8)| 00:00:07 |       |       |
|* 11 |    VIEW                         | index$_join$_004     | 27750 |   189K|   122   (4)| 00:00:02 |       |       |
|* 12 |     HASH JOIN                   |                      |       |       |            |          |       |       |
|  13 |      BITMAP CONVERSION TO ROWIDS|                      | 27750 |   189K|     2   (0)| 00:00:01 |       |       |
|* 14 |       BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|  15 |      INDEX FAST FULL SCAN       | CUSTOMERS_PK         | 27750 |   189K|   147   (2)| 00:00:02 |       |       |
|  16 |    PARTITION RANGE ALL          |                      |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
|  17 |     TABLE ACCESS FULL           | SALES                |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("T2"."CUST_ID"="T3"."CUST_ID")
   3 - filter("T3"."CUST_GENDER"='MALE')
   4 - access(ROWID=ROWID)
   6 - access("T3"."CUST_GENDER"='MALE')
  10 - access("T2"."CUST_ID"="T3"."CUST_ID")
  11 - filter("T3"."CUST_GENDER"='FEMALE')
  12 - access(ROWID=ROWID)
  14 - access("T3"."CUST_GENDER"='FEMALE')


Statistics
----------------------------------------------------------
      15453  recursive calls
          0  db block gets
       3297  consistent gets
         96  physical reads
          0  redo size
        276  bytes sent via SQL*Net to client
        389  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
        159  sorts (memory)
          0  sorts (disk)
          0  rows processed

从上述显示内容可以看出,这里Oracle就是原封不动地分别重复执行了范例SQL的每个分支,最后对每个分支的执行结果做了一个union all。注意Id=9和Id=17的执行步骤均为“TABLE ACCESS FULL | SALES”,这说明Oracle对数据量接近100万的表sales重复执行了两次全表扫描,这是不好的。

在Oracle 11gr2中再执行一次范例SQL,看看Oracle 11gr2会如何处理该SQL:

SQL> select t2.prod_id as prod_id
  2  from sales t2,customers t3
  3  where t2.cust_id=t3.cust_id
  4  and t3.cust_gender='MALE'
  5  union all
  6  select t2.prod_id as prod_id
  7  from sales t2,customers t3
  8  where t2.cust_id=t3.cust_id
  9  and t3.cust_gender='FEMALE';

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 576876893

-------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                        | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                 |                      |  1804K|    37M|   764   (2)| 00:00:10 |       |       |
|*  1 |  HASH JOIN                       |                      |  1804K|    37M|   764   (2)| 00:00:10 |       |       |
|   2 |   VIEW                           | VW_JF_SET$0F531EB5   | 17992 |   228K|   235   (1)| 00:00:03 |       |       |
|   3 |    UNION-ALL                     |                      |       |       |            |          |       |       |
|*  4 |     VIEW                         | index$_join$_002     |  8829 | 61803 |   118   (1)| 00:00:02 |       |       |
|*  5 |      HASH JOIN                   |                      |       |       |            |          |       |       |
|   6 |       BITMAP CONVERSION TO ROWIDS|                      |  8829 | 61803 |     1   (0)| 00:00:01 |       |       |
|*  7 |        BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|   8 |       INDEX FAST FULL SCAN       | CUSTOMERS_PK         |  8829 | 61803 |   145   (0)| 00:00:02 |       |       |
|*  9 |     VIEW                         | index$_join$_004     |  9163 | 64141 |   118   (1)| 00:00:02 |       |       |
|* 10 |      HASH JOIN                   |                      |       |       |            |          |       |       |
|  11 |       BITMAP CONVERSION TO ROWIDS|                      |  9163 | 64141 |     1   (0)| 00:00:01 |       |       |
|* 12 |        BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|  13 |       INDEX FAST FULL SCAN       | CUSTOMERS_PK         |  9163 | 64141 |   145   (0)| 00:00:02 |       |       |
|  14 |   PARTITION RANGE ALL            |                      |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
|  15 |    TABLE ACCESS FULL             | SALES                |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
-------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("T2"."CUST_ID"="ITEM_1")
   4 - filter("T3"."CUST_GENDER"='MALE')
   5 - access(ROWID=ROWID)
   7 - access("T3"."CUST_GENDER"='MALE')
   9 - filter("T3"."CUST_GENDER"='FEMALE')
  10 - access(ROWID=ROWID)
  12 - access("T3"."CUST_GENDER"='FEMALE')


Statistics
----------------------------------------------------------
         47  recursive calls
          0  db block gets
        111  consistent gets
          0  physical reads
          0  redo size
        287  bytes sent via SQL*Net to client
        404  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          8  sorts (memory)
          0  sorts (disk)
          0  rows processed

从上述显示内容可以看出,对表sales的全表扫描只在Id=15的执行步骤处出现了一次,这说明同样的SQL在Oracle 11gR2中只需要全表扫描sales一次,另外,Id=2的执行步骤的Operation列的值是“VIEW”,对应的 Name列的值是“VW_JF_SET$0F531EB5”(这里VW_JF_SET$0F531EB5中的关键字是JF是Join Factorization的缩写),同时Id=1的执行步骤的Operation列的值是”HASH JOIN”。种种迹象都说明Oracle已经把范例SQL中union all的公共部分表sales提了出来,然后和union all 剩下的部分所形成的内嵌视图VW_JF_SET$0F531EB5做了一个哈希连接,即Oracle已经对范例SQL做了连接因式分解。

连接因式分解除了能够避免对公共部分中所包含的表做重复访问之外,还可以提供更多的执行路径给优化器做选择,这就增加了走出更高效执行计划的可能性。

创建一个视图view_jf,其视图定义SQL语句就是范例SQL:

SQL> create or replace view view_jf as
  2  select t2.prod_id as prod_id
  3  from sales t2,customers t3
  4  where t2.cust_id=t3.cust_id
  5  and t3.cust_gender='MALE'
  6  union all
  7  select t2.prod_id as prod_id
  8  from sales t2,customers t3
  9  where t2.cust_id=t3.cust_id
 10  and t3.cust_gender='FEMALE';

View created.

然后我们来看如下形式的SQL1:
select t1.prod_id,t1.prod_name
from products t1,view_jf
where t1.prod_id=view_jf.prod_id
and t1.prod_list_price>1000;

在范例SQL1中,表products和视图view_jf做了表连接,而view_jf又是表sales和customers做表连接且做union all的视图。因为view_jf中包含了集合运算符union all,所以Oracle不能对它做视图合并,即Oracle必须将view_jf的定义SQL语句当作一个整体来单独执行,这也就意味着sales必须和customers做表连接,然后才能和表products再做表连接。

在Oracle10gr2中执行范例SQL1:

SQL> select t1.prod_id,t1.prod_name
  2  from products t1,view_jf
  3  where t1.prod_id=view_jf.prod_id
  4  and t1.prod_list_price>1000;

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3095468170

--------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                         | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                  |                      |   426K|    19M|  1128  (10)| 00:00:14 |       |       |
|*  1 |  HASH JOIN                        |                      |   426K|    19M|  1128  (10)| 00:00:14 |       |       |
|*  2 |   TABLE ACCESS FULL               | PRODUCTS             |    17 |   595 |     3   (0)| 00:00:01 |       |       |
|   3 |   VIEW                            | VIEW_JF              |  1837K|    22M|  1098   (8)| 00:00:14 |       |       |
|   4 |    UNION-ALL                      |                      |       |       |            |          |       |       |
|*  5 |     HASH JOIN                     |                      |   918K|    14M|   549   (8)| 00:00:07 |       |       |
|*  6 |      VIEW                         | index$_join$_004     | 27236 |   186K|   122   (4)| 00:00:02 |       |       |
|*  7 |       HASH JOIN                   |                      |       |       |            |          |       |       |
|   8 |        BITMAP CONVERSION TO ROWIDS|                      | 27236 |   186K|     2   (0)| 00:00:01 |       |       |
|*  9 |         BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|  10 |        INDEX FAST FULL SCAN       | CUSTOMERS_PK         | 27236 |   186K|   147   (2)| 00:00:02 |       |       |
|  11 |      PARTITION RANGE ALL          |                      |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
|  12 |       TABLE ACCESS FULL           | SALES                |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
|* 13 |     HASH JOIN                     |                      |   918K|    14M|   549   (8)| 00:00:07 |       |       |
|* 14 |      VIEW                         | index$_join$_006     | 27750 |   189K|   122   (4)| 00:00:02 |       |       |
|* 15 |       HASH JOIN                   |                      |       |       |            |          |       |       |
|  16 |        BITMAP CONVERSION TO ROWIDS|                      | 27750 |   189K|     2   (0)| 00:00:01 |       |       |
|* 17 |         BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|  18 |        INDEX FAST FULL SCAN       | CUSTOMERS_PK         | 27750 |   189K|   147   (2)| 00:00:02 |       |       |
|  19 |      PARTITION RANGE ALL          |                      |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
|  20 |       TABLE ACCESS FULL           | SALES                |   918K|  8075K|   413   (6)| 00:00:05 |     1 |    28 |
--------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("T1"."PROD_ID"="VIEW_JF"."PROD_ID")
   2 - filter("T1"."PROD_LIST_PRICE">1000)
   5 - access("T2"."CUST_ID"="T3"."CUST_ID")
   6 - filter("T3"."CUST_GENDER"='MALE')
   7 - access(ROWID=ROWID)
   9 - access("T3"."CUST_GENDER"='MALE')
  13 - access("T2"."CUST_ID"="T3"."CUST_ID")
  14 - filter("T3"."CUST_GENDER"='FEMALE')
  15 - access(ROWID=ROWID)
  17 - access("T3"."CUST_GENDER"='FEMALE')


Statistics
----------------------------------------------------------
        457  recursive calls
          0  db block gets
        126  consistent gets
          6  physical reads
          0  redo size
        335  bytes sent via SQL*Net to client
        389  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
         18  sorts (memory)
          0  sorts (disk)
          0  rows processed

注意到Id=3的执行步骤的Operation列的值为“VIEW”,对应Name列的值为“VIEW_JF”,这说明Oracle确实没有对范例SQL1中的视图VIEW_JF做视图合并,即Oracle现在还是将VIEW_JF的定义SQL语句当作一个整体来单独执行,所以此时表sales和customers分别做了两次哈希连接,然后Oracle将这两次哈希连接的连接结果做了union all合并后,才和视图VIEW_JF外部的表products再做一次哈希连接。

在Oracle 11gr2中再执行一次范例SQL1,看看在Oracle 11gr2中会如何处理该SQL:

SQL> select t1.prod_id,t1.prod_name
  2  from products t1,view_jf
  3  where t1.prod_id=view_jf.prod_id
  4  and t1.prod_list_price>1000;

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 408077510

----------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                      | 37586 |  2092K|   687   (1)| 00:00:09 |       |       |
|*  1 |  HASH JOIN                          |                      | 37586 |  2092K|   687   (1)| 00:00:09 |       |       |
|   2 |   VIEW                              | VW_JF_SET$7C24F767   | 17992 |   228K|   235   (1)| 00:00:03 |       |       |
|   3 |    UNION-ALL                        |                      |       |       |            |          |       |       |
|*  4 |     VIEW                            | index$_join$_004     |  8829 | 61803 |   118   (1)| 00:00:02 |       |       |
|*  5 |      HASH JOIN                      |                      |       |       |            |          |       |       |
|   6 |       BITMAP CONVERSION TO ROWIDS   |                      |  8829 | 61803 |     1   (0)| 00:00:01 |       |       |
|*  7 |        BITMAP INDEX SINGLE VALUE    | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|   8 |       INDEX FAST FULL SCAN          | CUSTOMERS_PK         |  8829 | 61803 |   145   (0)| 00:00:02 |       |       |
|*  9 |     VIEW                            | index$_join$_006     |  9163 | 64141 |   118   (1)| 00:00:02 |       |       |
|* 10 |      HASH JOIN                      |                      |       |       |            |          |       |       |
|  11 |       BITMAP CONVERSION TO ROWIDS   |                      |  9163 | 64141 |     1   (0)| 00:00:01 |       |       |
|* 12 |        BITMAP INDEX SINGLE VALUE    | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|  13 |       INDEX FAST FULL SCAN          | CUSTOMERS_PK         |  9163 | 64141 |   145   (0)| 00:00:02 |       |       |
|  14 |   NESTED LOOPS                      |                      | 19142 |   822K|   452   (0)| 00:00:06 |       |       |
|  15 |    NESTED LOOPS                     |                      | 19142 |   822K|   452   (0)| 00:00:06 |       |       |
|* 16 |     TABLE ACCESS FULL               | PRODUCTS             |     1 |    35 |     3   (0)| 00:00:01 |       |       |
|  17 |     PARTITION RANGE ALL             |                      |       |       |            |          |     1 |    28 |
|  18 |      BITMAP CONVERSION TO ROWIDS    |                      |       |       |            |          |       |       |
|* 19 |       BITMAP INDEX SINGLE VALUE     | SALES_PROD_BIX       |       |       |            |          |     1 |    28 |
|  20 |    TABLE ACCESS BY LOCAL INDEX ROWID| SALES                | 12762 |   112K|   452   (0)| 00:00:06 |     1 |     1 |
----------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("T2"."CUST_ID"="ITEM_1")
   4 - filter("T3"."CUST_GENDER"='MALE')
   5 - access(ROWID=ROWID)
   7 - access("T3"."CUST_GENDER"='MALE')
   9 - filter("T3"."CUST_GENDER"='FEMALE')
  10 - access(ROWID=ROWID)
  12 - access("T3"."CUST_GENDER"='FEMALE')
  16 - filter("T1"."PROD_LIST_PRICE">1000)
  19 - access("T1"."PROD_ID"="T2"."PROD_ID")


Statistics
----------------------------------------------------------
         12  recursive calls
          0  db block gets
         14  consistent gets
          0  physical reads
          0  redo size
        350  bytes sent via SQL*Net to client
        404  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          4  sorts (memory)
          0  sorts (disk)
          0  rows processed

注意到Id=2的执行步骤的Operation列的值是“VIEW”,其对应的Name列的值是“VW_JF_SET$7C24F767”,和范例SQL一样,
这说明Oracle已经把视图view_jf的定义SQL语句中union all的公共部分表sales提了出来,然后用union all剩下的部分形成了
一个内嵌视图VW_JF_SET$7C24F767,即Oracle已经对范例SQL1做了连接因式分解。

有一条SQL在测试环境中能做连接因式分解,测试环境与生产环境完全全相同,同事说在生产环境中发现不能进行连接因式分解,说帮忙看看原因是因为生产环境中与该SQL相关的三张表原来的数据被清空了,而新导入的数据没有收集统计信息赞成的。下面来模拟测试一下这个问题。

下面的SQL在表sales,customers没有统计信息时不能进行连接因式分解

SQL> select t2.prod_id as prod_id
  2  from sales t2,customers t3
  3  where t2.cust_id=t3.cust_id
  4  and t3.cust_gender='MALE'
  5  union all
  6  select t2.prod_id as prod_id
  7  from sales t2,customers t3
  8  where t2.cust_id=t3.cust_id
  9  and t3.cust_gender='FEMALE';

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 4184572088

------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                       | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |                      |  1837K|    28M|  1290   (2)| 00:00:16 |       |       |
|   1 |  UNION-ALL                      |                      |       |       |            |          |       |       |
|*  2 |   HASH JOIN                     |                      |   918K|    14M|   645   (2)| 00:00:08 |       |       |
|*  3 |    VIEW                         | index$_join$_002     | 26739 |   182K|   119   (1)| 00:00:02 |       |       |
|*  4 |     HASH JOIN                   |                      |       |       |            |          |       |       |
|   5 |      BITMAP CONVERSION TO ROWIDS|                      | 26739 |   182K|     2   (0)| 00:00:01 |       |       |
|*  6 |       BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|   7 |      INDEX FAST FULL SCAN       | CUSTOMERS_PK         | 26739 |   182K|   145   (0)| 00:00:02 |       |       |
|   8 |    PARTITION RANGE ALL          |                      |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
|   9 |     TABLE ACCESS FULL           | SALES                |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
|* 10 |   HASH JOIN                     |                      |   918K|    14M|   645   (2)| 00:00:08 |       |       |
|* 11 |    VIEW                         | index$_join$_004     | 27750 |   189K|   119   (1)| 00:00:02 |       |       |
|* 12 |     HASH JOIN                   |                      |       |       |            |          |       |       |
|  13 |      BITMAP CONVERSION TO ROWIDS|                      | 27750 |   189K|     2   (0)| 00:00:01 |       |       |
|* 14 |       BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|  15 |      INDEX FAST FULL SCAN       | CUSTOMERS_PK         | 27750 |   189K|   145   (0)| 00:00:02 |       |       |
|  16 |    PARTITION RANGE ALL          |                      |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
|  17 |     TABLE ACCESS FULL           | SALES                |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("T2"."CUST_ID"="T3"."CUST_ID")
   3 - filter("T3"."CUST_GENDER"='MALE')
   4 - access(ROWID=ROWID)
   6 - access("T3"."CUST_GENDER"='MALE')
  10 - access("T2"."CUST_ID"="T3"."CUST_ID")
  11 - filter("T3"."CUST_GENDER"='FEMALE')
  12 - access(ROWID=ROWID)
  14 - access("T3"."CUST_GENDER"='FEMALE')


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          0  consistent gets
          0  physical reads
          0  redo size
        287  bytes sent via SQL*Net to client
        404  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed

查询sales,customers表的统计信息发现没有

SQL> select a.table_name,a.num_rows,a.blocks,a.empty_blocks,a.avg_row_len,a.last_analyzed 
  2  from dba_tables a where a.owner='SH' and a.table_name='SALES';

TABLE_NAME                       NUM_ROWS     BLOCKS EMPTY_BLOCKS AVG_ROW_LEN LAST_ANALYZE
------------------------------ ---------- ---------- ------------ ----------- ------------
SALES                            

SQL> select a.table_name,a.num_rows,a.blocks,a.empty_blocks,a.avg_row_len,a.last_analyzed 
  2  from dba_tables a where a.owner='SH' and a.table_name='CUSTOMERS';

TABLE_NAME                       NUM_ROWS     BLOCKS EMPTY_BLOCKS AVG_ROW_LEN LAST_ANALYZE
------------------------------ ---------- ---------- ------------ ----------- ------------
CUSTOMERS

查询sales,customers表的修改记录这里是2014-11-28是最后的修改日期

SQL> select object_name,created,last_ddl_time from dba_objects where owner='SH' and object_name='SALES';

OBJECT_NAME                                                                                                                      CREATED      LAST_DDL_TIM
-------------------------------------------------------------------------------------------------------------------------------- ------------ ------------
SALES                                                                                                                            28-NOV-14    28-NOV-14



SQL> select object_name,created,last_ddl_time from dba_objects where owner='SH' and object_name='CUSTOMERS';

OBJECT_NAME                                                                                                                      CREATED      LAST_DDL_TIM
-------------------------------------------------------------------------------------------------------------------------------- ------------ ------------
CUSTOMERS                                                                                                                        28-NOV-14    28-NOV-14

表sales,customers的统计信息收集时间是2014-11-28

SQL> select * from dba_tab_stats_history where owner='SH' and table_name='SALES';

OWNER                          TABLE_NAME                     PARTITION_NAME                 SUBPARTITION_NAME              STATS_UPDATE_TIME
------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------
SH                             SALES                                                                                        28-NOV-14 01.07.30.055660 PM +08:00


SQL> select * from dba_tab_stats_history where owner='SH' and table_name='CUSTOMERS';

OWNER                          TABLE_NAME                     PARTITION_NAME                 SUBPARTITION_NAME              STATS_UPDATE_TIME
------------------------------ ------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------
SH                             CUSTOMERS                                                                                    28-NOV-14 01.07.37.664982 PM +08:00

在重新导入数据后对表sales,customers收集统计信息

SQL> exec dbms_stats.gather_table_stats(ownname => 'SH',tabname => 'SALES',method_opt => 'for all columns size auto');

PL/SQL procedure successfully completed.

SQL> exec dbms_stats.gather_table_stats(ownname => 'SH',tabname => 'SALES',estimate_percent => 100,method_opt => 'for all columns size auto');

PL/SQL procedure successfully completed.

SQL> exec dbms_stats.gather_table_stats(ownname => 'SH',tabname => 'CUSTOMERS',estimate_percent => 100,method_opt => 'for all columns size auto');

PL/SQL procedure successfully completed.

SQL> select a.table_name,a.num_rows,a.blocks,a.empty_blocks,a.avg_row_len,a.last_analyzed from dba_tables a where a.owner='SH' and a.table_name='CUSTOMERS';

TABLE_NAME                       NUM_ROWS     BLOCKS EMPTY_BLOCKS AVG_ROW_LEN LAST_ANALYZE
------------------------------ ---------- ---------- ------------ ----------- ------------
CUSTOMERS                           55500       1486            0         181 12-DEC-14

SQL> select a.table_name,a.num_rows,a.blocks,a.empty_blocks,a.avg_row_len,a.last_analyzed from dba_tables a where a.owner='SH' and a.table_name='SALES';

TABLE_NAME                       NUM_ROWS     BLOCKS EMPTY_BLOCKS AVG_ROW_LEN LAST_ANALYZE
------------------------------ ---------- ---------- ------------ ----------- ------------
SALES                              918843       1907            0          29 12-DEC-14

收集统计信息后能够正常进行连接因式分解:

SQL> select t2.prod_id as prod_id
  2  from sales t2,customers t3
  3  where t2.cust_id=t3.cust_id
  4  and t3.cust_gender='MALE'
  5  union all
  6  select t2.prod_id as prod_id
  7  from sales t2,customers t3
  8  where t2.cust_id=t3.cust_id
  9  and t3.cust_gender='FEMALE';

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 576876893

-------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                        | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                 |                      |  1804K|    37M|   764   (2)| 00:00:10 |       |       |
|*  1 |  HASH JOIN                       |                      |  1804K|    37M|   764   (2)| 00:00:10 |       |       |
|   2 |   VIEW                           | VW_JF_SET$0F531EB5   | 17992 |   228K|   235   (1)| 00:00:03 |       |       |
|   3 |    UNION-ALL                     |                      |       |       |            |          |       |       |
|*  4 |     VIEW                         | index$_join$_002     |  8829 | 61803 |   118   (1)| 00:00:02 |       |       |
|*  5 |      HASH JOIN                   |                      |       |       |            |          |       |       |
|   6 |       BITMAP CONVERSION TO ROWIDS|                      |  8829 | 61803 |     1   (0)| 00:00:01 |       |       |
|*  7 |        BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|   8 |       INDEX FAST FULL SCAN       | CUSTOMERS_PK         |  8829 | 61803 |   145   (0)| 00:00:02 |       |       |
|*  9 |     VIEW                         | index$_join$_004     |  9163 | 64141 |   118   (1)| 00:00:02 |       |       |
|* 10 |      HASH JOIN                   |                      |       |       |            |          |       |       |
|  11 |       BITMAP CONVERSION TO ROWIDS|                      |  9163 | 64141 |     1   (0)| 00:00:01 |       |       |
|* 12 |        BITMAP INDEX SINGLE VALUE | CUSTOMERS_GENDER_BIX |       |       |            |          |       |       |
|  13 |       INDEX FAST FULL SCAN       | CUSTOMERS_PK         |  9163 | 64141 |   145   (0)| 00:00:02 |       |       |
|  14 |   PARTITION RANGE ALL            |                      |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
|  15 |    TABLE ACCESS FULL             | SALES                |   918K|  8075K|   523   (1)| 00:00:07 |     1 |    28 |
-------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("T2"."CUST_ID"="ITEM_1")
   4 - filter("T3"."CUST_GENDER"='MALE')
   5 - access(ROWID=ROWID)
   7 - access("T3"."CUST_GENDER"='MALE')
   9 - filter("T3"."CUST_GENDER"='FEMALE')
  10 - access(ROWID=ROWID)
  12 - access("T3"."CUST_GENDER"='FEMALE')


Statistics
----------------------------------------------------------
         47  recursive calls
          0  db block gets
        111  consistent gets
          0  physical reads
          0  redo size
        287  bytes sent via SQL*Net to client
        404  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          8  sorts (memory)
          0  sorts (disk)
          0  rows processed


在Oracle 11gr2及其后续的版本中,即使由于在视图定义SQL语句中包含了集合运算符union all而导致 Oracle不能对其做视图合并,Oracle也不一定会把该视图的定义SQL语句当作一个整体来单独执行,因为此时Oracle还可能会对其做连接因式分解。这里需要注意的是,Oracle对包含union all的目标SQL做连接因式分解的前提条件是,连接因式分解后的等价改写SQL和原SQL在语义上完全等价,如果不能满足这一点,那么Oracle就不会做连接因式分解。

参考:
https://blogs.oracle.com/optimizer/entry/optimizer_transformations_join_factorization

ORA-12547: TNS:lost contact故障的处理

redhat 5.4 oracle 10.2.0.5 rac其中一个节点连接实例时报ORA-12547: TNS:lost contact

[oracle@wj2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Wed Nov 26 22:12:42 2014
Copyright (c) 1982, 2010, Oracle. All Rights Reserved. 

ERROR:
ORA-12547: TNS:lost contact 

解决步骤如下:
1.先检查两个节点的操作系统内核参数是否有变化

[root@wj1 bin]# ulimit -a
 core file size (blocks, -c) 0
 data seg size (kbytes, -d) unlimited
 scheduling priority (-e) 0
 file size (blocks, -f) unlimited
 pending signals (-i) 16383
 max locked memory (kbytes, -l) 32
 max memory size (kbytes, -m) unlimited
 open files (-n) 1024
 pipe size (512 bytes, -p) 8
 POSIX message queues (bytes, -q) 819200
 real-time priority (-r) 0
 stack size (kbytes, -s) 10240
 cpu time (seconds, -t) unlimited
 max user processes (-u) 16383
 virtual memory (kbytes, -v) unlimited
 file locks (-x) unlimited 


[root@wj2 bin]# ulimit -a
 core file size (blocks, -c) 0
 data seg size (kbytes, -d) unlimited
 scheduling priority (-e) 0
 file size (blocks, -f) unlimited
 pending signals (-i) 16383
 max locked memory (kbytes, -l) 32
 max memory size (kbytes, -m) unlimited
 open files (-n) 1024
 pipe size (512 bytes, -p) 8
 POSIX message queues (bytes, -q) 819200
 real-time priority (-r) 0
 stack size (kbytes, -s) 10240
 cpu time (seconds, -t) unlimited
 max user processes (-u) 16383
 virtual memory (kbytes, -v) unlimited
 file locks (-x) unlimited 

两个节点一样排除内核参数的原因

2.在主机中安装了10g rac与11g rac所以要确认$ORACLE_HOME/bin/oracle文件权限是否有问题(rac下需要查看$ORACLE_HOME/bin/oracle和$GRID_HOME/bin/oracle)

[oracle@wj1 bin]$ ll $ORACLE_HOME/bin/oracle
 -rwsr-s--x 1 oracle oinstall 98849122 Nov 20 17:23 /u01/app/oracle/product/10.2.0/db/bin/oracle 

[oracle@wj2 bin]$ ll $ORACLE_HOME/bin/oracle
-rwxrwxr-x 1 grid oinstall 98849122 Nov 20 17:23 oracle 


[oracle@wj1 bin]$ ls -lrt $ORACLE_HOME/rdbms/lib/config.o
 -rw-r----- 1 oracle oinstall 816 Nov 20 17:24 /u01/app/oracle/product/10.2.0/db/rdbms/lib/config.o 

[oracle@wj2 bin]$ ls -lrt $ORACLE_HOME/rdbms/lib/config.o
-rwxrwxr-x 1 grid oinstall 816 Nov 20 17:24 /u01/app/oracle/product/10.2.0/db/rdbms/lib/config.o
[root@wj2 bin]# chown -R oracle:oinstall /u01/app/oracle 

很明oracle 10g rac的$ORACLE_HOME/bin/oracle与$ORACLE_HOME/rdbms/lib/config.o文件的所有者变成了grid用户,而grid用户是用来安装oracle 11g rac的。需要修改这两个文件的所有者

[oracle@wj2 bin]# chown -R oracle:oinstall $ORACLE_HOME/bin/oracle 

[oracle@wj2 bin]# chown -R oracle:oinstall $ORACLE_HOME/rdbms/lib/config.o 


[oracle@wj1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 Production on Wed Nov 26 16:45:40 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> 

小结:在同一主机上最好不要安装多个版本的软件,如果确实要安装不要在同一个oracle_base目录下安装不同的版本,很容易造成权限混乱。

对union集合操作理解不足造成的巨大的灾难

朋友和我说发现了oracle union操作的一个bug,他的查询语句如下:

SQL> select sum(a1) a1,sum(a2) a2
  2  from (
  3  select 1 a1,0 a2 from dual
  4  union
  5  select 0 a2, 1 a1 from dual
  6  )
  7  ;

        A1         A2
---------- ----------
         1          1


SQL> select 1 a1,0 a2 from dual
  2  union
  3  select 0 a2, 1 a1 from dual
  4  ;

        A1         A2
---------- ----------
         0          1
         1          0

说结果出错了,应该a2为0,他说别名为 a2的值其实是0,说union不是按别名来进行区别的,一开始我还没反应过来。后面想了一下,union的意思是用来合并两条查询的结果并去重,在oracle关于sql的文档中是说union集合操作中的两个查询中的列的类型和个数要相同。例如将上面两个查询别名为a2的值从0改成’0’再执行union操作就会报错:

SQL> select 1 a1,'0' a2 from dual
  2  union
  3  select '0' a2, 1 a1 from dual
  4  ;

select 1 a1,'0' a2 from dual
union
select '0' a2, 1 a1 from dual

ORA-01790: 表达式必须具有与对应表达式相同的数据类型

从而说明了union其实是按列出现的顺序进行合并的,并不是按别名.对union的意思理解不对危害很大,从上面的列来说他本来的意思是a2应该为0,但因为他的顺序写错了结果变成了1。这种危害太大了,如果这些数字是钱本来应该为0的,结果因为查询中列的顺序写错了,就会造成巨大的损失。而朋友的系统就是这么巧就是money,且软件运行了有些年头了。