我測試MySQL查詢響應時間,我已經注意到了,有一次我只添加一個文本類型字段選擇語句,查詢減慢幾乎10+倍。由於MySQL不支持FULL OUTER JOIN語句,因此我使用以下解決方法:爲什麼選擇文本會減慢FULL連接查詢這麼多?
select
a.idACCOUNT,p.idPROJECT,p.projectName,t.TRAINING_idPROJECT,t.idTRAINING,t.trainingName,m.MODULE_idTRAINING,m.idMODULE,m.moduleName,c.idCONTENT,c.contentName,
s.idSUBCONTENT
from ACCOUNT as a
left outer join PROJECT as p on a.idACCOUNT = p.PROJECT_idACCOUNT
left outer join TRAINING as t on a.idACCOUNT = t.TRAINING_idACCOUNT AND p.idPROJECT = t.TRAINING_idPROJECT
left outer join MODULE as m on a.idACCOUNT = m.MODULE_idACCOUNT AND p.idPROJECT = m.MODULE_idPROJECT AND t.idTRAINING = m.MODULE_idTRAINING
left outer join CONTENT as c on a.idACCOUNT = c.CONTENT_idACCOUNT AND p.idPROJECT = c.CONTENT_idPROJECT AND t.idTRAINING = c.CONTENT_idTRAINING AND
m.idMODULE = c.CONTENT_idMODULE
left outer join SUBCONTENT as s on a.idACCOUNT = s.SUBCONTENT_idACCOUNT AND p.idPROJECT = s.SUBCONTENT_idPROJECT AND t.idTRAINING = s.SUBCONTENT_idTRAINING
AND m.idMODULE = s.SUBCONTENT_idMODULE AND c.idCONTENT = s.SUBCONTENT_idCONTENT
WHERE a.idACCOUNT='1'
union all
select
a.idACCOUNT,p.idPROJECT,p.projectName,t.TRAINING_idPROJECT,t.idTRAINING,t.trainingName,m.MODULE_idTRAINING,m.idMODULE,m.moduleName,c.idCONTENT,c.contentName,
s.idSUBCONTEN
from ACCOUNT as a
right outer join PROJECT as p on a.idACCOUNT = p.PROJECT_idACCOUNT
right outer join TRAINING as t on a.idACCOUNT = t.TRAINING_idACCOUNT AND p.idPROJECT = t.TRAINING_idPROJECT
right outer join MODULE as m on a.idACCOUNT = m.MODULE_idACCOUNT AND p.idPROJECT = m.MODULE_idPROJECT AND t.idTRAINING = m.MODULE_idTRAINING
right outer join CONTENT as c on a.idACCOUNT = c.CONTENT_idACCOUNT AND p.idPROJECT = c.CONTENT_idPROJECT AND t.idTRAINING = c.CONTENT_idTRAINING AND
m.idMODULE = c.CONTENT_idMODULE
right outer join SUBCONTENT as s on a.idACCOUNT = s.SUBCONTENT_idACCOUNT AND p.idPROJECT = s.SUBCONTENT_idPROJECT AND t.idTRAINING =
s.SUBCONTENT_idTRAINING AND m.idMODULE = s.SUBCONTENT_idMODULE AND c.idCONTENT = s.SUBCONTENT_idCONTENT
WHERE a.idACCOUNT is null;
上面的查詢只包含VARCHAR處理多達255個和INT 11場,這個查詢返回的結果與速度:查詢花費0.0010秒。
現在,如果我將添加到選擇部分至少一個文本字段查詢時間跳轉到0.0337秒,單測試somtimes甚至達到0.1秒
它不但是運行文本字段單獨的查詢是非常重要的速度更快:查詢花了0.0004秒。
這在我看來,這將是更快地分離兩個查詢,並具有文本字段,如意見和VARCHAR處理等各項指標單獨的查詢特定的查詢。
現在我的問題是爲什麼它會影響查詢時間那麼多添加在選擇部分申請只有一個文本?爲什麼單獨的查詢在預期的時間框架內運行?
預先感謝您的時間和幫助。
你是什麼意思與「添加在租賃一個文本提交選擇」? – hol
a.idACCOUNT和所有其他列是varchars和INT類型。添加一個文本類型效果減慢的列 –