
sql和執行計劃如圖。
uj5u.com熱心網友回復:
用了好幾個not in ,當用戶的not_enjoy 或enjoy資料很大時,查詢就比較慢了(比如該用戶not_enjoy的資料有1w條時)。uj5u.com熱心網友回復:
csdn已經沒人了么?uj5u.com熱心網友回復:
not in優化select * from A where ID not in (select ID from B)
替換為
select * from A left join B on A.ID=B.ID where B.ID is null
uj5u.com熱心網友回復:
在上面的sql中,幫忙用這個優化規則改一下呢,我寫出來查詢結果不對
uj5u.com熱心網友回復:
關鍵部分就好uj5u.com熱心網友回復:
......left join enjoy e on lc.user_id=e.other_id and e.isrevoke=0 and e.user_id=xxx
left join not_enjoy ne on lc.user_id=ne.other_id and ne.isrevoke=0 and ne.user_id=xxx
left join black_list ne on lc.user_id=b.other_id and b.isrevoke=0 and b.user_id=xxx
......
where ......
and e.other_id is null
and ne.other_id is null
and b.other_id is null
uj5u.com熱心網友回復:
后面的and 1065362 not in ...改掉1=1去掉
like concat ('d','%')換成 'd%'
timestampdiff函式換掉
這個sql寫的好亂,能不能拆開
uj5u.com熱心網友回復:


這里根據你的提示,改了sql,多余的條件先去掉,只關聯not_enjoy enjoy black_list 這三張表,但是結果應該沒對
uj5u.com熱心網友回復:
查詢結果好像不一樣了,沒有過濾掉
uj5u.com熱心網友回復:
下面改成這樣就對了where ......
and e.id is null
and ne.id is null
and b.id is null
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/23168.html
標籤:MySQL
