zoukankan      html  css  js  c++  java
  • String Aggregation: varchar VS clob

    在Oracle11.2中实现string aggregation,主要有以下几种方法:

    - LISTAGG 函数

    - COLLECT 函数 + 自定义的TO_STRING函数

    - 自定义实现ODCI的聚集函数

    几种实现方式最优的是LISTAGG,毕竟是Oracle内置函数,其次是COLLECT+自定义TO_STRING函数。有篇文章对这几种方法的效率进行了详细的比较,参见http://www.oracle-developer.net/display.php?id=515

    本文自然就不在赘述,但是需要注意的是上面提到的那篇文章主要都是基于最后拼成的字符串的长度不超过4000个byte (SELECT 语句中只能支持最多4000个byte长度的字符串,超过就会报错了)。

    如下所示...

    select rpad('a', 400000000, 'a') || 'a'
    from dual
    
    
    ORA-01489: result of string concatenation is too long


    注意测试的时候不能简单用RPAD来拼貌似超过4000个字符的字符串,因为超过4000也会被“截断”成4000个字符。如下。。。

    select length( rpad('a', 400000000, 'a'))
    from dual


    LENGTH(RPAD('A',400000000,'A'))
    -------------------------------
    4000
    1 row selected.


    注意到LISTAGG也只能支持最多4000个字符...

    select listagg('a') within group(order by null)
    from dual
    connect by level <=4001

    ORA-01489: result of string concatenation is too long

    但是有时候我们可能遇到的情况就是最后的字符串超过这个长度,那么点训呢?需要实现一个函数返回类型为CLOB才行。但是一旦引入CLOB,性能就会大幅度降低。测试如下...

    SQL> show array
    arraysize 15

    SQL> select count(*) from user_tables;

    COUNT(*)
    ----------
    957

    select arg_table_to_string(collect(collect(table_name) as t_v4000_table))
    from user_tables
    group by table_name;

    Elapsed: 00:00:01.93


    select arg_table_to_clob3(collect(collect(table_name) as t_v4000_table))
    from user_tables
    group by table_name;

    Elapsed: 00:00:04.14

    返回957条记录,arg_table_to_string用了1.93s, 但是arg_table_to_clob3却用了4.14秒!那么时间究竟花在什么地方了呢?(关于arg_table_to_clob3函数,参见http://www.cnblogs.com/fangwenyu/archive/2011/12/08/2281219.html

    现在看下trace 文件....

    (1) ARG_TABLE_TO_STRING

    PARSING IN CURSOR #508005072 len=107 dep=0 uid=84 oct=3 lid=84 tim=637157061317 hv=3124265229 ad='56fcaecf0' sqlid='846wfm2x3j08d'
    select arg_table_to_string(cast(collect(table_name) as t_v4000_table))
    from user_tables
    group by table_name
    END OF STMT
    PARSE #508005072:c=328125,e=326508,p=0,cr=80,cu=0,mis=1,r=0,dep=0,og=1,plh=354837137,tim=637157061314
    EXEC #508005072:c=0,e=160,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=354837137,tim=637157061804
    WAIT #508005072: nam='SQL*Net message to client' ela= 13 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157061981
    WAIT #508005072: nam='asynch descriptor resize' ela= 8 outstanding #aio=0 current aio limit=4294967295 new aio limit=325 obj#=-1 tim=637157206695
    WAIT #508005072: nam='asynch descriptor resize' ela= 1 outstanding #aio=0 current aio limit=4294967295 new aio limit=260 obj#=-1 tim=637157206913
    WAIT #508005072: nam='asynch descriptor resize' ela= 5 outstanding #aio=0 current aio limit=4294967295 new aio limit=260 obj#=-1 tim=637157227867
    WAIT #508005072: nam='asynch descriptor resize' ela= 4 outstanding #aio=0 current aio limit=4294967295 new aio limit=195 obj#=-1 tim=637157250807
    WAIT #508005072: nam='asynch descriptor resize' ela= 2 outstanding #aio=0 current aio limit=4294967295 new aio limit=130 obj#=-1 tim=637157250914
    FETCH #508005072:c=187500,e=189243,p=0,cr=4085,cu=0,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637157251310
    WAIT #508005072: nam='SQL*Net message from client' ela= 674 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157253874
    WAIT #508005072: nam='SQL*Net message to client' ela= 11 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157254499
    FETCH #508005072:c=0,e=1613,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157255636
    WAIT #508005072: nam='SQL*Net message from client' ela= 23275 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157279270
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157279741
    FETCH #508005072:c=0,e=1394,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157280851
    WAIT #508005072: nam='SQL*Net message from client' ela= 18436 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157299494
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157299928
    FETCH #508005072:c=0,e=1355,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157301009
    WAIT #508005072: nam='SQL*Net message from client' ela= 21602 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157322814
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157323244
    FETCH #508005072:c=0,e=1357,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157324330
    WAIT #508005072: nam='SQL*Net message from client' ela= 18281 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157342814
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157343271
    FETCH #508005072:c=0,e=1382,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157344354
    WAIT #508005072: nam='SQL*Net message from client' ela= 18144 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157362700
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157363132
    FETCH #508005072:c=0,e=1358,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157364218
    WAIT #508005072: nam='SQL*Net message from client' ela= 21362 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157385782
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157386212
    FETCH #508005072:c=15625,e=1353,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157387294
    WAIT #508005072: nam='SQL*Net message from client' ela= 18422 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157405973
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157406407
    FETCH #508005072:c=0,e=1356,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157407492
    WAIT #508005072: nam='SQL*Net message from client' ela= 18511 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157426205
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157426637
    FETCH #508005072:c=0,e=1357,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157427724
    WAIT #508005072: nam='SQL*Net message from client' ela= 21823 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157449748
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157450182
    FETCH #508005072:c=0,e=1384,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157451295
    WAIT #508005072: nam='SQL*Net message from client' ela= 18446 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157469946
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157470378
    FETCH #508005072:c=0,e=1354,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157471459
    WAIT #508005072: nam='SQL*Net message from client' ela= 18879 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157490540
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157490971
    FETCH #508005072:c=0,e=1355,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157492054
    WAIT #508005072: nam='SQL*Net message from client' ela= 21677 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157513932
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157514359
    FETCH #508005072:c=0,e=1349,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157515439
    WAIT #508005072: nam='SQL*Net message from client' ela= 18829 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157534470
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157534912
    FETCH #508005072:c=0,e=1352,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157535993
    WAIT #508005072: nam='SQL*Net message from client' ela= 21557 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157557769
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157558195
    FETCH #508005072:c=15625,e=1359,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157559285
    WAIT #508005072: nam='SQL*Net message from client' ela= 18182 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157577724
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157578152
    FETCH #508005072:c=0,e=1378,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157579259
    WAIT #508005072: nam='SQL*Net message from client' ela= 18197 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157597662
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157598272
    FETCH #508005072:c=0,e=1357,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157599358
    WAIT #508005072: nam='SQL*Net message from client' ela= 21985 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157621545
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157621930
    FETCH #508005072:c=0,e=1352,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157623009
    WAIT #508005072: nam='SQL*Net message from client' ela= 18441 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157641654
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157642035
    FETCH #508005072:c=0,e=1348,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157643113
    WAIT #508005072: nam='SQL*Net message from client' ela= 19066 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157662379
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157662760
    FETCH #508005072:c=0,e=1345,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157663836
    WAIT #508005072: nam='SQL*Net message from client' ela= 21500 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157685538
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157685926
    FETCH #508005072:c=0,e=1384,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157687036
    WAIT #508005072: nam='SQL*Net message from client' ela= 18262 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157705504
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157705887
    FETCH #508005072:c=0,e=1346,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157706965
    WAIT #508005072: nam='SQL*Net message from client' ela= 18415 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157725581
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157725959
    FETCH #508005072:c=0,e=1346,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157727038
    WAIT #508005072: nam='SQL*Net message from client' ela= 21739 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157748978
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157749363
    FETCH #508005072:c=0,e=1354,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157750445
    WAIT #508005072: nam='SQL*Net message from client' ela= 18639 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157769286
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157769664
    FETCH #508005072:c=0,e=1345,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157770742
    WAIT #508005072: nam='SQL*Net message from client' ela= 21754 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157792697
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157793084
    FETCH #508005072:c=15625,e=1394,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157794203
    WAIT #508005072: nam='SQL*Net message from client' ela= 19221 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157813660
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157814043
    FETCH #508005072:c=0,e=1351,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157815124
    WAIT #508005072: nam='SQL*Net message from client' ela= 18511 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157833836
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157834216
    FETCH #508005072:c=0,e=1350,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157835298
    WAIT #508005072: nam='SQL*Net message from client' ela= 21641 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157857140
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157857518
    FETCH #508005072:c=0,e=1350,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157858601
    WAIT #508005072: nam='SQL*Net message from client' ela= 18233 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157877033
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157877411
    FETCH #508005072:c=0,e=1342,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157878487
    WAIT #508005072: nam='SQL*Net message from client' ela= 19247 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157897933
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157898311
    FETCH #508005072:c=0,e=1344,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157899389
    WAIT #508005072: nam='SQL*Net message from client' ela= 21303 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157920893
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157921276
    FETCH #508005072:c=0,e=1374,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157922380
    WAIT #508005072: nam='SQL*Net message from client' ela= 19142 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157941724
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157942106
    FETCH #508005072:c=0,e=1348,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157943184
    WAIT #508005072: nam='SQL*Net message from client' ela= 18634 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157962018
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157962400
    FETCH #508005072:c=0,e=1343,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157963475
    WAIT #508005072: nam='SQL*Net message from client' ela= 21723 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157985397
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637157985775
    FETCH #508005072:c=0,e=1351,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637157986860
    WAIT #508005072: nam='SQL*Net message from client' ela= 18336 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158005396
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158005779
    FETCH #508005072:c=0,e=1350,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158006859
    WAIT #508005072: nam='SQL*Net message from client' ela= 22288 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158029347
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158029734
    FETCH #508005072:c=0,e=1386,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158030847
    WAIT #508005072: nam='SQL*Net message from client' ela= 18441 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158049491
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158049875
    FETCH #508005072:c=0,e=1348,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158050951
    WAIT #508005072: nam='SQL*Net message from client' ela= 18386 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158069538
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158069932
    FETCH #508005072:c=0,e=1349,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158071013
    WAIT #508005072: nam='SQL*Net message from client' ela= 21605 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158092817
    WAIT #508005072: nam='SQL*Net message to client' ela= 6 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158093219
    FETCH #508005072:c=0,e=1351,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158094299
    WAIT #508005072: nam='SQL*Net message from client' ela= 18854 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158113352
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158113731
    FETCH #508005072:c=0,e=1348,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158114812
    WAIT #508005072: nam='SQL*Net message from client' ela= 18467 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158133480
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158133862
    FETCH #508005072:c=0,e=1352,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158134944
    WAIT #508005072: nam='SQL*Net message from client' ela= 22123 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158157266
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158157647
    FETCH #508005072:c=0,e=1376,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158158754
    WAIT #508005072: nam='SQL*Net message from client' ela= 18473 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158177430
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158177809
    FETCH #508005072:c=0,e=1351,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158178893
    WAIT #508005072: nam='SQL*Net message from client' ela= 18525 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158197618
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158198006
    FETCH #508005072:c=0,e=1355,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158199086
    WAIT #508005072: nam='SQL*Net message from client' ela= 22000 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158221498
    WAIT #508005072: nam='SQL*Net message to client' ela= 6 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158221877
    FETCH #508005072:c=0,e=1344,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158222954
    WAIT #508005072: nam='SQL*Net message from client' ela= 19153 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158242306
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158242692
    FETCH #508005072:c=0,e=1349,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158243768
    WAIT #508005072: nam='SQL*Net message from client' ela= 21791 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158265760
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158266139
    FETCH #508005072:c=0,e=1379,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158267250
    WAIT #508005072: nam='SQL*Net message from client' ela= 18451 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158285901
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158286280
    FETCH #508005072:c=0,e=1345,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158287357
    WAIT #508005072: nam='SQL*Net message from client' ela= 18739 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158306294
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158306672
    FETCH #508005072:c=0,e=1346,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158307751
    WAIT #508005072: nam='SQL*Net message from client' ela= 21055 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158329003
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158329397
    FETCH #508005072:c=0,e=1346,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158330475
    WAIT #508005072: nam='SQL*Net message from client' ela= 18155 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158348830
    WAIT #508005072: nam='SQL*Net message to client' ela= 6 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158349213
    FETCH #508005072:c=0,e=1345,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158350288
    WAIT #508005072: nam='SQL*Net message from client' ela= 18539 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158369026
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158369404
    FETCH #508005072:c=0,e=1343,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158370480
    WAIT #508005072: nam='SQL*Net message from client' ela= 21127 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158391805
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158392207
    FETCH #508005072:c=0,e=1372,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158393288
    WAIT #508005072: nam='SQL*Net message from client' ela= 18798 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158412285
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158412663
    FETCH #508005072:c=0,e=1340,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158413737
    WAIT #508005072: nam='SQL*Net message from client' ela= 18341 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158432276
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158432654
    FETCH #508005072:c=0,e=1345,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158433732
    WAIT #508005072: nam='SQL*Net message from client' ela= 21825 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158455754
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158456137
    FETCH #508005072:c=0,e=1347,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158457216
    WAIT #508005072: nam='SQL*Net message from client' ela= 23675 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158481089
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158481470
    FETCH #508005072:c=0,e=1350,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158482552
    WAIT #508005072: nam='SQL*Net message from client' ela= 28011 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158510762
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158511141
    FETCH #508005072:c=15625,e=1377,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158512251
    WAIT #508005072: nam='SQL*Net message from client' ela= 28070 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158540533
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158540927
    FETCH #508005072:c=0,e=1351,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158542007
    WAIT #508005072: nam='SQL*Net message from client' ela= 24999 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158567204
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158567586
    FETCH #508005072:c=0,e=1349,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158568664
    WAIT #508005072: nam='SQL*Net message from client' ela= 27751 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158596614
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158596993
    FETCH #508005072:c=0,e=1347,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158598073
    WAIT #508005072: nam='SQL*Net message from client' ela= 23772 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158622045
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158622426
    FETCH #508005072:c=0,e=1396,p=0,cr=0,cu=0,mis=0,r=15,dep=0,og=1,plh=354837137,tim=637158623553
    WAIT #508005072: nam='SQL*Net message from client' ela= 26175 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158649930
    WAIT #508005072: nam='SQL*Net message to client' ela= 7 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637158650309
    FETCH #508005072:c=0,e=1138,p=0,cr=0,cu=0,mis=0,r=11,dep=0,og=1,plh=354837137,tim=637158651180
    STAT #508005072 id=1 cnt=957 pid=0 pos=1 obj=0 op='SORT GROUP BY (cr=4085 pr=0 pw=0 time=229469 us cost=660 size=157905 card=957)'
    STAT #508005072 id=2 cnt=957 pid=1 pos=1 obj=0 op='HASH JOIN RIGHT OUTER (cr=4085 pr=0 pw=0 time=184801 us cost=659 size=575520 card=3488)'
    STAT #508005072 id=3 cnt=7276 pid=2 pos=1 obj=14 op='TABLE ACCESS FULL SEG$ (cr=215 pr=0 pw=0 time=7650 us cost=59 size=80938 card=7358)'
    STAT #508005072 id=4 cnt=957 pid=2 pos=2 obj=0 op='HASH JOIN RIGHT OUTER (cr=3870 pr=0 pw=0 time=169815 us cost=599 size=498190 card=3235)'
    STAT #508005072 id=5 cnt=103 pid=4 pos=1 obj=47 op='INDEX FULL SCAN I_USER2 (cr=1 pr=0 pw=0 time=144 us cost=1 size=412 card=103)'
    STAT #508005072 id=6 cnt=957 pid=4 pos=2 obj=0 op='HASH JOIN OUTER (cr=3869 pr=0 pw=0 time=165817 us cost=598 size=485250 card=3235)'
    STAT #508005072 id=7 cnt=957 pid=6 pos=1 obj=0 op='HASH JOIN OUTER (cr=3616 pr=0 pw=0 time=147210 us cost=529 size=459370 card=3235)'
    STAT #508005072 id=8 cnt=957 pid=7 pos=1 obj=0 op='HASH JOIN (cr=3363 pr=0 pw=0 time=114188 us cost=460 size=443195 card=3235)'
    STAT #508005072 id=9 cnt=10 pid=8 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=14 pr=0 pw=0 time=262 us cost=5 size=30 card=10)'
    STAT #508005072 id=10 cnt=957 pid=8 pos=2 obj=0 op='NESTED LOOPS (cr=3349 pr=0 pw=0 time=108492 us cost=454 size=433490 card=3235)'
    STAT #508005072 id=11 cnt=5648 pid=10 pos=1 obj=0 op='MERGE JOIN CARTESIAN (cr=1009 pr=0 pw=0 time=90545 us cost=278 size=336440 card=3235)'
    STAT #508005072 id=12 cnt=1 pid=11 pos=1 obj=0 op='HASH JOIN (cr=0 pr=0 pw=0 time=9649 us cost=1 size=68 card=1)'
    STAT #508005072 id=13 cnt=1 pid=12 pos=1 obj=0 op='FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=4000 us cost=0 size=55 card=1)'
    STAT #508005072 id=14 cnt=2649 pid=12 pos=2 obj=0 op='FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=5440 us cost=0 size=1300 card=100)'
    STAT #508005072 id=15 cnt=5648 pid=11 pos=2 obj=0 op='BUFFER SORT (cr=1009 pr=0 pw=0 time=76507 us cost=278 size=116460 card=3235)'
    STAT #508005072 id=16 cnt=5648 pid=15 pos=1 obj=18 op='TABLE ACCESS FULL OBJ$ (cr=1009 pr=0 pw=0 time=21283 us cost=277 size=116460 card=3235)'
    STAT #508005072 id=17 cnt=957 pid=10 pos=2 obj=4 op='TABLE ACCESS CLUSTER TAB$ (cr=2340 pr=0 pw=0 time=31517 us cost=1 size=30 card=1)'
    STAT #508005072 id=18 cnt=1407 pid=17 pos=1 obj=3 op='INDEX UNIQUE SCAN I_OBJ# (cr=42 pr=0 pw=0 time=10877 us cost=0 size=0 card=1)'
    STAT #508005072 id=19 cnt=81035 pid=7 pos=2 obj=36 op='INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=21513 us cost=68 size=405595 card=81119)'
    STAT #508005072 id=20 cnt=81035 pid=6 pos=2 obj=36 op='INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=17795 us cost=68 size=648952 card=81119)'
    WAIT #508005072: nam='SQL*Net message from client' ela= 25489341 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184143021
    CLOSE #508005072:c=0,e=55,dep=0,type=0,tim=637184143275

    从trace文件中可以看出fetch一共执行了65次,因为一共是957条记录,array size是15,因此 ceil(957/15) + 1 = 65。 因为每两次fetch之间都会产生"SQL*Netmessage from client" 和“SQL*Net message to client”等待事件,因此浪费了不少事件。如果把array size提高,响应时间会有所提高。

    现在再来看arg_table_to_clob的trace文件。

    (2) ARG_TABLE_TO_CLOB3

    PARSING IN CURSOR #508005072 len=106 dep=0 uid=84 oct=3 lid=84 tim=637184469255 hv=1736356860 ad='56d5951c8' sqlid='czgqv7tmrxczw'
    select arg_table_to_clob3(cast(collect(table_name) as t_v4000_table))
    from user_tables
    group by table_name
    END OF STMT
    PARSE #508005072:c=328125,e=325750,p=0,cr=56,cu=0,mis=1,r=0,dep=0,og=1,plh=354837137,tim=637184469252
    EXEC #508005072:c=0,e=153,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=354837137,tim=637184469656
    WAIT #508005072: nam='SQL*Net message to client' ela= 13 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184469830
    WAIT #508005072: nam='SQL*Net message from client' ela= 595 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184473307
    WAIT #508005072: nam='asynch descriptor resize' ela= 10 outstanding #aio=0 current aio limit=4294967295 new aio limit=325 obj#=-1 tim=637184627068
    WAIT #508005072: nam='asynch descriptor resize' ela= 4 outstanding #aio=0 current aio limit=4294967295 new aio limit=260 obj#=-1 tim=637184627333
    WAIT #508005072: nam='asynch descriptor resize' ela= 10 outstanding #aio=0 current aio limit=4294967295 new aio limit=260 obj#=-1 tim=637184683858
    WAIT #508005072: nam='asynch descriptor resize' ela= 5 outstanding #aio=0 current aio limit=4294967295 new aio limit=195 obj#=-1 tim=637184717905
    WAIT #508005072: nam='asynch descriptor resize' ela= 2 outstanding #aio=0 current aio limit=4294967295 new aio limit=130 obj#=-1 tim=637184717994
    WAIT #508005072: nam='Disk file operations I/O' ela= 221 FileOperation=2 fileno=201 filetype=2 obj#=-1 tim=637184718943
    WAIT #508005072: nam='SQL*Net message to client' ela= 4 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184719303
    FETCH #508005072:c=250000,e=245898,p=0,cr=4085,cu=17,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184719345
    WAIT #508005072: nam='SQL*Net message from client' ela= 517 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184720256
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184720346
    LOBREAD: c=0,e=55,p=0,cr=1,cu=0,tim=637184720367
    WAIT #0: nam='SQL*Net message from client' ela= 24277 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184744671
    LOBTMPFRE: c=0,e=12,p=0,cr=0,cu=0,tim=637184744731
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184744753
    WAIT #0: nam='SQL*Net message from client' ela= 344 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184745114
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184745478
    FETCH #508005072:c=0,e=358,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184745513
    WAIT #508005072: nam='SQL*Net message from client' ela= 261 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184745864
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184745929
    LOBREAD: c=0,e=42,p=0,cr=1,cu=0,tim=637184745946
    WAIT #0: nam='SQL*Net message from client' ela= 1367 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184747336
    LOBTMPFRE: c=0,e=8,p=0,cr=0,cu=0,tim=637184747383
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184747403
    WAIT #0: nam='SQL*Net message from client' ela= 350 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184747770
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184748093
    FETCH #508005072:c=0,e=315,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184748127
    WAIT #508005072: nam='SQL*Net message from client' ela= 240 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184748453
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184748527
    LOBREAD: c=0,e=39,p=0,cr=1,cu=0,tim=637184748544
    WAIT #0: nam='SQL*Net message from client' ela= 1309 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184749876
    LOBTMPFRE: c=0,e=8,p=0,cr=0,cu=0,tim=637184749923
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184749943
    WAIT #0: nam='SQL*Net message from client' ela= 336 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184750296
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184750609
    FETCH #508005072:c=0,e=309,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184750642
    WAIT #508005072: nam='SQL*Net message from client' ela= 270 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184750999
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184751062
    LOBREAD: c=0,e=41,p=0,cr=1,cu=0,tim=637184751079
    WAIT #0: nam='SQL*Net message from client' ela= 1340 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184752442
    LOBTMPFRE: c=0,e=7,p=0,cr=0,cu=0,tim=637184752488
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184752508
    WAIT #0: nam='SQL*Net message from client' ela= 333 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184752858
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184753160
    FETCH #508005072:c=0,e=299,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184753193
    WAIT #508005072: nam='SQL*Net message from client' ela= 258 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184753535
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184753596
    LOBREAD: c=0,e=37,p=0,cr=1,cu=0,tim=637184753612
    WAIT #0: nam='SQL*Net message from client' ela= 1317 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184754953
    LOBTMPFRE: c=0,e=7,p=0,cr=0,cu=0,tim=637184754999
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184755019
    WAIT #0: nam='SQL*Net message from client' ela= 331 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184755367
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184755671
    FETCH #508005072:c=0,e=300,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184755704
    WAIT #508005072: nam='SQL*Net message from client' ela= 254 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184756041
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184756104
    LOBREAD: c=0,e=39,p=0,cr=1,cu=0,tim=637184756120
    WAIT #0: nam='SQL*Net message from client' ela= 1357 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184757500
    LOBTMPFRE: c=0,e=8,p=0,cr=0,cu=0,tim=637184757546
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184757566
    WAIT #0: nam='SQL*Net message from client' ela= 339 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184757921
    WAIT #508005072: nam='SQL*Net message to client' ela= 4 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184758219
    FETCH #508005072:c=0,e=292,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184758250
    WAIT #508005072: nam='SQL*Net message from client' ela= 254 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184758588
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184758650
    LOBREAD: c=0,e=38,p=0,cr=1,cu=0,tim=637184758666
    WAIT #0: nam='SQL*Net message from client' ela= 1352 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184760041
    LOBTMPFRE: c=0,e=7,p=0,cr=0,cu=0,tim=637184760086
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184760106
    WAIT #0: nam='SQL*Net message from client' ela= 331 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184760454
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184760762
    FETCH #508005072:c=0,e=297,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184760795
    WAIT #508005072: nam='SQL*Net message from client' ela= 252 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184761129
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184761192
    LOBREAD: c=0,e=40,p=0,cr=1,cu=0,tim=637184761209
    WAIT #0: nam='SQL*Net message from client' ela= 1353 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184762584
    LOBTMPFRE: c=0,e=8,p=0,cr=0,cu=0,tim=637184762630
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184762649
    WAIT #0: nam='SQL*Net message from client' ela= 332 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184762998
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184763315
    FETCH #508005072:c=15625,e=313,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184763348
    WAIT #508005072: nam='SQL*Net message from client' ela= 257 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184763696
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184763756
    LOBREAD: c=0,e=38,p=0,cr=1,cu=0,tim=637184763773
    WAIT #0: nam='SQL*Net message from client' ela= 1348 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184765144
    LOBTMPFRE: c=0,e=7,p=0,cr=0,cu=0,tim=637184765190
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184765210
    WAIT #0: nam='SQL*Net message from client' ela= 331 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184765558
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184765859
    FETCH #508005072:c=0,e=296,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184765891
    WAIT #508005072: nam='SQL*Net message from client' ela= 255 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184766229
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184766291
    LOBREAD: c=0,e=39,p=0,cr=1,cu=0,tim=637184766308
    WAIT #0: nam='SQL*Net message from client' ela= 1351 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184767682
    LOBTMPFRE: c=0,e=8,p=0,cr=0,cu=0,tim=637184767728
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184767748
    WAIT #0: nam='SQL*Net message from client' ela= 336 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184768100
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184768398
    FETCH #508005072:c=0,e=294,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184768430
    WAIT #508005072: nam='SQL*Net message from client' ela= 256 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184768769
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184768829
    LOBREAD: c=0,e=38,p=0,cr=1,cu=0,tim=637184768846
    WAIT #0: nam='SQL*Net message from client' ela= 1354 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184770223
    LOBTMPFRE: c=0,e=7,p=0,cr=0,cu=0,tim=637184770269
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184770289
    WAIT #0: nam='SQL*Net message from client' ela= 336 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184770642
    WAIT #508005072: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184770942
    FETCH #508005072:c=0,e=296,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184770975
    WAIT #508005072: nam='SQL*Net message from client' ela= 254 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184771312
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184771375
    LOBREAD: c=0,e=40,p=0,cr=1,cu=0,tim=637184771392
    WAIT #0: nam='SQL*Net message from client' ela= 4609 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184776024
    LOBTMPFRE: c=0,e=8,p=0,cr=0,cu=0,tim=637184776157
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184776178
    WAIT #0: nam='SQL*Net message from client' ela= 325 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184776520
    WAIT #508005072: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184776818
    FETCH #508005072:c=0,e=293,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184776850
    WAIT #508005072: nam='SQL*Net message from client' ela= 257 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184777190
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184777251
    LOBREAD: c=0,e=37,p=0,cr=1,cu=0,tim=637184777267
    WAIT #0: nam='SQL*Net message from client' ela= 1353 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184778643
    LOBTMPFRE: c=0,e=7,p=0,cr=0,cu=0,tim=637184778689
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184778709
    WAIT #0: nam='SQL*Net message from client' ela= 300 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184779026
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184779859
    FETCH #508005072:c=0,e=796,p=0,cr=0,cu=12,mis=0,r=1,dep=0,og=1,plh=354837137,tim=637184779945
    WAIT #508005072: nam='SQL*Net message from client' ela= 241 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184780405
    WAIT #0: nam='SQL*Net message to client' ela= 3 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184780478
    LOBREAD: c=0,e=43,p=0,cr=1,cu=0,tim=637184780495
    WAIT #0: nam='SQL*Net message from client' ela= 1304 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637184781822
    LOBTMPFRE: c=0,e=8,p=0,cr=0,cu=0,tim=637184781870

    <omit some lines....>

    FETCH #508005072:c=0,e=82,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=354837137,tim=637188269743
    STAT #508005072 id=1 cnt=957 pid=0 pos=1 obj=0 op='SORT GROUP BY (cr=4085 pr=0 pw=0 time=331604 us cost=660 size=157905 card=957)'
    STAT #508005072 id=2 cnt=957 pid=1 pos=1 obj=0 op='HASH JOIN RIGHT OUTER (cr=4085 pr=0 pw=0 time=240425 us cost=659 size=575520 card=3488)'
    STAT #508005072 id=3 cnt=7276 pid=2 pos=1 obj=14 op='TABLE ACCESS FULL SEG$ (cr=215 pr=0 pw=0 time=7645 us cost=59 size=80938 card=7358)'
    STAT #508005072 id=4 cnt=957 pid=2 pos=2 obj=0 op='HASH JOIN RIGHT OUTER (cr=3870 pr=0 pw=0 time=227203 us cost=599 size=498190 card=3235)'
    STAT #508005072 id=5 cnt=103 pid=4 pos=1 obj=47 op='INDEX FULL SCAN I_USER2 (cr=1 pr=0 pw=0 time=248 us cost=1 size=412 card=103)'
    STAT #508005072 id=6 cnt=957 pid=4 pos=2 obj=0 op='HASH JOIN OUTER (cr=3869 pr=0 pw=0 time=223805 us cost=598 size=485250 card=3235)'
    STAT #508005072 id=7 cnt=957 pid=6 pos=1 obj=0 op='HASH JOIN OUTER (cr=3616 pr=0 pw=0 time=190919 us cost=529 size=459370 card=3235)'
    STAT #508005072 id=8 cnt=957 pid=7 pos=1 obj=0 op='HASH JOIN (cr=3363 pr=0 pw=0 time=117519 us cost=460 size=443195 card=3235)'
    STAT #508005072 id=9 cnt=10 pid=8 pos=1 obj=16 op='TABLE ACCESS FULL TS$ (cr=14 pr=0 pw=0 time=250 us cost=5 size=30 card=10)'
    STAT #508005072 id=10 cnt=957 pid=8 pos=2 obj=0 op='NESTED LOOPS (cr=3349 pr=0 pw=0 time=112477 us cost=454 size=433490 card=3235)'
    STAT #508005072 id=11 cnt=5648 pid=10 pos=1 obj=0 op='MERGE JOIN CARTESIAN (cr=1009 pr=0 pw=0 time=92610 us cost=278 size=336440 card=3235)'
    STAT #508005072 id=12 cnt=1 pid=11 pos=1 obj=0 op='HASH JOIN (cr=0 pr=0 pw=0 time=10071 us cost=1 size=68 card=1)'
    STAT #508005072 id=13 cnt=1 pid=12 pos=1 obj=0 op='FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=4132 us cost=0 size=55 card=1)'
    STAT #508005072 id=14 cnt=2649 pid=12 pos=2 obj=0 op='FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=5567 us cost=0 size=1300 card=100)'
    STAT #508005072 id=15 cnt=5648 pid=11 pos=2 obj=0 op='BUFFER SORT (cr=1009 pr=0 pw=0 time=78100 us cost=278 size=116460 card=3235)'
    STAT #508005072 id=16 cnt=5648 pid=15 pos=1 obj=18 op='TABLE ACCESS FULL OBJ$ (cr=1009 pr=0 pw=0 time=21297 us cost=277 size=116460 card=3235)'
    STAT #508005072 id=17 cnt=957 pid=10 pos=2 obj=4 op='TABLE ACCESS CLUSTER TAB$ (cr=2340 pr=0 pw=0 time=40137 us cost=1 size=30 card=1)'
    STAT #508005072 id=18 cnt=1407 pid=17 pos=1 obj=3 op='INDEX UNIQUE SCAN I_OBJ# (cr=42 pr=0 pw=0 time=14409 us cost=0 size=0 card=1)'
    STAT #508005072 id=19 cnt=81035 pid=7 pos=2 obj=36 op='INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=55027 us cost=68 size=405595 card=81119)'
    STAT #508005072 id=20 cnt=81035 pid=6 pos=2 obj=36 op='INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=29837 us cost=68 size=648952 card=81119)'
    WAIT #508005072: nam='SQL*Net message to client' ela= 8 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637188272102
    WAIT #508005072: nam='SQL*Net message from client' ela= 21985496 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=637210257663
    CLOSE #508005072:c=0,e=70,dep=0,type=0,tim=637210257942


    ARG_TABLE_TO_CLOB3产生的trace文件非常多,所以我省略了很多。这次查一下里面的fetch数,发现是958次 = 957 + 1, 也就是说每返回一条记录, fetch就执行了一次,虽然array size是15!!!很显然,大量的时间会发在"sql*net"等待时事件上!

    同时从trace文件还可以看出每一次fetch都会伴随LOBREAD和LOBTMPFRE操作,这就是是用CLOB的代价!

    LOBREAD: c=0,e=93,p=0,cr=1,cu=0,tim=637188267582

    LOBTMPFRE: c=0,e=18,p=0,cr=0,cu=0,tim=637188269121

    现在看下TKPROF的结果....

    select arg_table_to_string(cast(collect(table_name) as t_v4000_table))
    from user_tables
    group by table_name

    call count cpu elapsed disk query current rows
    ------- ------ -------- ---------- ---------- ---------- ---------- ----------
    Parse 1 0.31 0.32 0 72 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 65 0.25 0.27 0 4085 0 957
    ------- ------ -------- ---------- ---------- ---------- ---------- ----------
    total 67 0.56 0.60 0 4157 0 957

    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 84
    Number of plan statistics captured: 1

    Rows (1st) Rows (avg) Rows (max) Row Source Operation
    ---------- ---------- ---------- ---------------------------------------------------
    957 957 957 SORT GROUP BY (cr=4085 pr=0 pw=0 time=229469 us cost=660 size=157905 card=957)
    957 957 957 HASH JOIN RIGHT OUTER (cr=4085 pr=0 pw=0 time=184801 us cost=659 size=575520 card=3488)
    7276 7276 7276 TABLE ACCESS FULL SEG$ (cr=215 pr=0 pw=0 time=7650 us cost=59 size=80938 card=7358)
    957 957 957 HASH JOIN RIGHT OUTER (cr=3870 pr=0 pw=0 time=169815 us cost=599 size=498190 card=3235)
    103 103 103 INDEX FULL SCAN I_USER2 (cr=1 pr=0 pw=0 time=144 us cost=1 size=412 card=103)(object id 47)
    957 957 957 HASH JOIN OUTER (cr=3869 pr=0 pw=0 time=165817 us cost=598 size=485250 card=3235)
    957 957 957 HASH JOIN OUTER (cr=3616 pr=0 pw=0 time=147210 us cost=529 size=459370 card=3235)
    957 957 957 HASH JOIN (cr=3363 pr=0 pw=0 time=114188 us cost=460 size=443195 card=3235)
    10 10 10 TABLE ACCESS FULL TS$ (cr=14 pr=0 pw=0 time=262 us cost=5 size=30 card=10)
    957 957 957 NESTED LOOPS (cr=3349 pr=0 pw=0 time=108492 us cost=454 size=433490 card=3235)
    5648 5648 5648 MERGE JOIN CARTESIAN (cr=1009 pr=0 pw=0 time=90545 us cost=278 size=336440 card=3235)
    1 1 1 HASH JOIN (cr=0 pr=0 pw=0 time=9649 us cost=1 size=68 card=1)
    1 1 1 FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=4000 us cost=0 size=55 card=1)
    2649 2649 2649 FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=5440 us cost=0 size=1300 card=100)
    5648 5648 5648 BUFFER SORT (cr=1009 pr=0 pw=0 time=76507 us cost=278 size=116460 card=3235)
    5648 5648 5648 TABLE ACCESS FULL OBJ$ (cr=1009 pr=0 pw=0 time=21283 us cost=277 size=116460 card=3235)
    957 957 957 TABLE ACCESS CLUSTER TAB$ (cr=2340 pr=0 pw=0 time=31517 us cost=1 size=30 card=1)
    1407 1407 1407 INDEX UNIQUE SCAN I_OBJ# (cr=42 pr=0 pw=0 time=10877 us cost=0 size=0 card=1)(object id 3)
    81035 81035 81035 INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=21513 us cost=68 size=405595 card=81119)(object id 36)
    81035 81035 81035 INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=17795 us cost=68 size=648952 card=81119)(object id 36)


    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    SQL*Net message to client 65 0.00 0.00
    asynch descriptor resize 5 0.00 0.00
    SQL*Net message from client 65 25.48 26.77
    ********************************************************************************

    select arg_table_to_clob3(cast(collect(table_name) as t_v4000_table))
    from user_tables
    group by table_name

    call count cpu elapsed disk query current rows
    ------- ------ -------- ---------- ---------- ---------- ---------- ----------
    Parse 1 0.32 0.32 0 48 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 958 1.00 0.92 0 4085 11489 957
    ------- ------ -------- ---------- ---------- ---------- ---------- ----------
    total 960 1.32 1.24 0 4133 11489 957

    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 84
    Number of plan statistics captured: 1

    Rows (1st) Rows (avg) Rows (max) Row Source Operation
    ---------- ---------- ---------- ---------------------------------------------------
    957 957 957 SORT GROUP BY (cr=4085 pr=0 pw=0 time=331604 us cost=660 size=157905 card=957)
    957 957 957 HASH JOIN RIGHT OUTER (cr=4085 pr=0 pw=0 time=240425 us cost=659 size=575520 card=3488)
    7276 7276 7276 TABLE ACCESS FULL SEG$ (cr=215 pr=0 pw=0 time=7645 us cost=59 size=80938 card=7358)
    957 957 957 HASH JOIN RIGHT OUTER (cr=3870 pr=0 pw=0 time=227203 us cost=599 size=498190 card=3235)
    103 103 103 INDEX FULL SCAN I_USER2 (cr=1 pr=0 pw=0 time=248 us cost=1 size=412 card=103)(object id 47)
    957 957 957 HASH JOIN OUTER (cr=3869 pr=0 pw=0 time=223805 us cost=598 size=485250 card=3235)
    957 957 957 HASH JOIN OUTER (cr=3616 pr=0 pw=0 time=190919 us cost=529 size=459370 card=3235)
    957 957 957 HASH JOIN (cr=3363 pr=0 pw=0 time=117519 us cost=460 size=443195 card=3235)
    10 10 10 TABLE ACCESS FULL TS$ (cr=14 pr=0 pw=0 time=250 us cost=5 size=30 card=10)
    957 957 957 NESTED LOOPS (cr=3349 pr=0 pw=0 time=112477 us cost=454 size=433490 card=3235)
    5648 5648 5648 MERGE JOIN CARTESIAN (cr=1009 pr=0 pw=0 time=92610 us cost=278 size=336440 card=3235)
    1 1 1 HASH JOIN (cr=0 pr=0 pw=0 time=10071 us cost=1 size=68 card=1)
    1 1 1 FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=4132 us cost=0 size=55 card=1)
    2649 2649 2649 FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=5567 us cost=0 size=1300 card=100)
    5648 5648 5648 BUFFER SORT (cr=1009 pr=0 pw=0 time=78100 us cost=278 size=116460 card=3235)
    5648 5648 5648 TABLE ACCESS FULL OBJ$ (cr=1009 pr=0 pw=0 time=21297 us cost=277 size=116460 card=3235)
    957 957 957 TABLE ACCESS CLUSTER TAB$ (cr=2340 pr=0 pw=0 time=40137 us cost=1 size=30 card=1)
    1407 1407 1407 INDEX UNIQUE SCAN I_OBJ# (cr=42 pr=0 pw=0 time=14409 us cost=0 size=0 card=1)(object id 3)
    81035 81035 81035 INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=55027 us cost=68 size=405595 card=81119)(object id 36)
    81035 81035 81035 INDEX FAST FULL SCAN I_OBJ1 (cr=253 pr=0 pw=0 time=29837 us cost=68 size=648952 card=81119)(object id 36)


    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    SQL*Net message to client 961 0.00 0.00
    SQL*Net message from client 961 21.98 41.20
    asynch descriptor resize 5 0.00 0.00
    Disk file operations I/O 1 0.00 0.00
    SQL*Net break/reset to client 4 0.00 0.00
    ********************************************************************************

    注意到除了fetch次数的差别,arg_table_to_clob3的current read次数居然高达11489, 而arg_table_to_string为0!

    因此在SQL语句中用到返回值为CLOB的函数的时候,要多加小心,不要让CLOB拖垮了程序!

  • 相关阅读:
    【HDU】4092 Nice boat(多校第四场1006) ——线段树 懒惰标记 Prime
    【POJ】2528 Mayor's posters ——离散化+线段树 Prime
    【HDU】1754 I hate it ——线段树 单点更新 区间最值 Prime
    C语言 linux环境基于socket的简易即时通信程序 Prime
    Java异常处理
    重载和重写的区别与联系
    SQL Server的优点与缺点
    Servlet基础
    C语言图形编程
    socket通讯,TCP,UDP,HTTP的区别
  • 原文地址:https://www.cnblogs.com/fangwenyu/p/2283434.html
Copyright © 2011-2022 走看看