waterye

          行列互換

          舊系統中的一條sql在某些情況下無法工作(反應超慢), 此sql是使用關聯進行行列互換, 從執行計劃和重建索引都查不出原因所在, 10G已經對sql不挑剔了, 暈啊(周五晚上的時間就這樣浪費掉)
           1select table2.id, 
           2       NVL(t1.count0as count1, 
           3       NVL(t2.count0as count2, 
           4       NVL(t3.count0as count3, 
           5       NVL(t4.count0as count4
           6 from table1 t1, table1 t2, table1 t3, table1 t4, table2 
           7 where t1.shop_id = ? and t1.type = 'a'
           8   and t2.shop_id = ? and t2.type = 'b'
           9   and t3.shop_id = ? and t3.type = 'c'
          10   and t4.shop_id = ? and t4.type = 'd'
          11   and table2.id = t1.id
          12   and table2.id = t2.id
          13   and table2.id = t3.id
          14   and table2.id = t4.id
          15 order by table2.code
          shop_id = 1386時很快(0.3s), shop_id = 1404時超慢(15s以上), 時間是在pl/sql developer執行時計算的, 不知是否oracle的bug

          只能對sql進行優化, 但一時不知如何解決(本人較笨), 只有發揮copy paste的能力(找google), http://www.oracle.com.cn/viewthread.php?tid=65638
          select t1.id, 
                 
          sum(decode(t1.type, 'a'count0)) count1, 
                 
          sum(decode(t1.type, 'b'count0)) count2,
                 
          sum(decode(t1.type, 'c'count0)) count3,
                 
          sum(decode(t1.type, 'd'count0)) count4
            
          from table1 t1, table2 t2
           
          where t1.id = t2.id
             
          and t1.shop_id = ?
           
          group by t1.id
           
          order by max(t2.code)

          執行時間0.17s(有點興奮, 程序員只有這點好處)

          還有通過SP進行行列互換的, 可到itpub上找找

          posted on 2005-12-17 01:32 waterye 閱讀(867) 評論(0)  編輯  收藏 所屬分類: oracle

          主站蜘蛛池模板: 襄城县| 二连浩特市| 临汾市| 湟源县| 云龙县| 遂昌县| 航空| 玛沁县| 台前县| 唐河县| 星座| 宁波市| 定陶县| 丁青县| 砚山县| 蓝田县| 宣威市| 汝州市| 宁夏| 杭锦旗| 滨海县| 牡丹江市| 临江市| 屏南县| 泽州县| 福海县| 谢通门县| 安阳市| 西乌珠穆沁旗| 广饶县| 庄浪县| 于都县| 西和县| 建阳市| 万山特区| 安吉县| 南充市| 旬邑县| 广平县| 谷城县| 称多县|