誰能幫我優化這條sql,這邊公司查詢要十秒,這樣使用者體現太慢了

時間 2022-09-03 17:55:07

1樓:

你這個東西去除索引的因素,最大的問題是在高層使用了distinct。我不知道你的表結構是什麼樣子的。不過基本思路是這樣的。

select distinct t3.sys_user_name procman, t2.send_file_num,t2.

year,t2.num, t2.title,t2.

write_file_date,t2.plan_unit,t2.plan_person, t2.

pre_recv_file_date,t2.sub_unit_num,t2.is_over,t2.

mid, t2.come_missive_unit, t2.come_file_time,t2.

jbr_id, t2.missive_type,t2.reply_date,t2.

notice_man,t2.urgent_level, t2.receive_missive_date,t2.

is_flow 這些個欄位裡面肯定有一兩個會決定其他重複記錄的出現。找到它,把它往下移動。也就是在join的時候就篩選好。

然後你查一下你要找到這些個欄位哪一個在該表裡面沒有索引。尤其是大段文字的。加一下索引。

基本也就優化到頭了。

2樓:今宵酒醒何處

select distinct t3.sys_user_name procman, t2.send_file_num,t2.

year,t2.num, t2.title,t2.

write_file_date,t2.plan_unit,t2.plan_person, t2.

pre_recv_file_date,t2.sub_unit_num,t2.is_over,t2.

mid, t2.come_missive_unit, t2.come_file_time,t2.

jbr_id, t2.missive_type,t2.reply_date,t2.

notice_man,t2.urgent_level, t2.receive_missive_date,t2.

is_flow

from oa_missive_register t2

left join oa_flow_record t1 on t2.mid=t1.mid

left join sys_users t3 on t1.to_user_id=t3.id

where not exists

(select null

from oa_missive_register t5

left join oa_flow_record t4 on t5.mid=t4.mid

where

and t5.mid =t2.mid

and t4.to_node_id is not null

and t5.is_pigeonhole !='1'

and t4.is_take_back !='1'

and t4.unit_id='260'

and t4.is_deal_with='0'

and t4.from_user_id='350'

and t4.fid='2'

)and (t2.doc_type !='takeback' or t2.doc_type is null)

and (t2.out_missive_state !='000' or t2.out_missive_state is null)

and t1.is_take_back !='1'

and t2.is_pigeonhole !='1'

and t2.out_reply_is_open is null

and t1.is_deal_with='0'

and t1.to_user_id='350'

and t1.unit_id='260'

and t1.fid='2'

在同為=或同為!=時

你判斷一下,那一條更能確定你的目標,有索引的,把他放到右邊

執行的時候是從右邊開始的

3樓:匿名使用者

儘量將條件裡和連線用到的欄位建立索引

誰能幫我寫關於物流配送系統優化的文章啊

畢業 這樣的事情 建議自己寫 真的!五 配送戰略 一 配送部門制度 1 準時上下班遲到十分鐘內扣10元工資,遲到半個小時內扣30元工資。曠工一天扣全天工資,並記小過。2 如有事,必須請假,否則視為無故曠工,扣除兩天工資。3 不準在上班時間使用配送部門配送車,做與工作無關的事情。4 配送途中,不是因為...

誰能幫我把電腦系統優化下!我剛重新安裝

微軟的xp系統預設已經都是最佳優化設定了,所以你也沒必要去優化了,最多就用個優化大師自動優化一下就可以了 裝完系統後,怎麼正確優化電腦 win10可嘗試通過以下方式進行系統的優化 1 可以直接搜尋 服務 或右擊 此電腦 選擇 管理 選擇 服務和應用程式 雙擊 服務 在右側找到並雙擊 ip helpe...

誰能幫我翻譯一下下面sql語句的大概意思

select deptid from es dept where path like 2.4.5.在es dept 表中查處相應的deptid 欄位 where path like 2.4.5.為條件 like的意思就是模糊查詢 如果以上查出來資料 取個別名叫 table select userna...