我有這樣一個查詢:慢SQL腳本優化
select row_number() over(order by m_time desc) as row, m.m_id, m_time, m_log_id
(case when exists(select 1 from t_approved_phonenumber where phone_number = m.c_phone_number) then 1 else 0 end) as approved,
(case when exists(select 1 from t_log log where log.c_id < m.m_log_id and log.phone_number = m.phone_number) then 'N' else 'Y' end) as is_first_time
from t_message m
所有表t_approved_phonenumber,t_message和t_log有很多的記錄。並且所有的ID都是主鍵,phone_number列有索引。有時候我的查詢很慢。有什麼方法可以加速嗎?
感謝,
你忘了提,運行此查詢的SQL產品。另外,當詢問優化時,請考慮添加當前版本查詢的查詢計劃。 –