→ MOONRAKER: 聽起來你在SQL裡面寫迴圈 是這樣嗎 218.161.46.90 05/31 18:13
→ smallyou1988: 不是,是在外面寫迴圈 182.235.82.125 05/31 18:15
→ MOONRAKER: 那你使用SQL如何比對 218.161.46.90 05/31 18:49
大大您好
我sql比對寫法是包在shell內,內容大意如下:
for迴圈
do
db語法 << EOF
create temp table aa(...省略 ) with no log;
load from 檔案 insert into aa;
unload to mydata.txt
select 所需欄位 from aa a, XXXtable b, outer XXXtable c
where b.id=a.id
and b.id=c.id
and (...這裡下的一堆條件都是按照資料庫現有index順序下的)
group by 欄位
EOF
done
其實就是這樣而已,並沒有甚麼特別之處
但是就是很慢
不管是條件順序或是temp table的index我都調過或加過
DB不只我程式會執行 還有其他人程式也會去做其他作業
不曉得大大覺得哪邊可以調整呢? :D
※ 編輯: smallyou1988 (182.235.82.125), 05/31/2015 22:25:19
※ 編輯: smallyou1988 (182.235.82.125), 05/31/2015 22:27:01
→ MOONRAKER: 研究一下join 應該只需要用一次inner 218.161.46.90 05/31 22:52
→ MOONRAKER: join就可得到所有特定欄位相同的列 218.161.46.90 05/31 22:53
→ smallyou1988: 改用left join, 刪減不必要select 111.81.73.108 06/02 20:29
→ smallyou1988: 的欄位了 111.81.73.108 06/02 20:29
→ n3oanderson: 確認一下table是在那個space建立. 111.243.94.63 06/03 07:15
→ n3oanderson: script看能不能拆開用parallel執行. 111.243.94.63 06/03 07:16
→ n3oanderson: 跑profiler察一下效能瓶頸. 111.243.94.63 06/03 07:18
→ n3oanderson: 為何要把檔案讀進資料庫在比對? 111.243.94.63 06/03 07:47
→ n3oanderson: 不能直接在script裡面比? 111.243.94.63 06/03 07:48
→ n3oanderson: 用PK撈出來的資料量會很大? 111.243.94.63 06/03 07:49
→ MOONRAKER: 既然用join應該就把所有資料合成一張大 61.221.51.43 06/05 17:25
→ MOONRAKER: 表 join一次就有全部結果了 61.221.51.43 06/05 17:25