行列互換
舊系統中的一條sql在某些情況下無法工作(反應超慢), 此sql是使用關聯進行行列互換, 從執行計劃和重建索引都查不出原因所在, 10G已經對sql不挑剔了, 暈啊(周五晚上的時間就這樣浪費掉) 1
select table2.id,
2
NVL(t1.count, 0) as count1,
3
NVL(t2.count, 0) as count2,
4
NVL(t3.count, 0) as count3,
5
NVL(t4.count, 0) as 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
2

3

4

5

6

7

8

9

10

11

12

13

14

15

只能對sql進行優化, 但一時不知如何解決(本人較笨), 只有發揮copy paste的能力(找google), http://www.oracle.com.cn/viewthread.php?tid=65638










執行時間0.17s(有點興奮, 程序員只有這點好處)
還有通過SP進行行列互換的, 可到itpub上找找
posted on 2005-12-17 01:32 waterye 閱讀(867) 評論(0) 編輯 收藏 所屬分類: oracle