我有一個查詢,需要幾分鐘來執行一個小的數據集,有什麼問題?這裏是解釋輸出:Mysql錯誤的查詢性能與許多聯接
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE BT_CALL_CLASS.. const PRIMARY PRIMARY 4 const 1 Using index; Using temporary; Using filesort
1 SIMPLE BT_FLAGS_FLAGS const PRIMARY PRIMARY 4 const 1 Using index
1 SIMPLE BT_DIRECTORY... range PRIMARY PRIMARY 4 NULL 308 Using where; Using index
1 SIMPLE BT_CALL_FLAGS.. ref PRIMARY,FKDF68A2ED9F150002 FKDF68A2ED9F150002 4 const 49 Using where; Using index
1 SIMPLE BT_DEPARTMENT.. index PRIMARY FK1F3A276188DDBD3 5 NULL 27 Using where; Using index; Using join buffer
1 SIMPLE BT_USERS_USER.. index PRIMARY FK6A68E086C27A155 5 NULL 233 Using where; Using index; Using join buffer
1 SIMPLE BT_FCT_CALLS.. eq_ref PRIMARY,FKDF68A2ED4F28.. PRIMARY 8 ...call_id 1 Using where
查詢
desc SELECT DISTINCT
BT_FCT_CALLS_FCT_CALLS.start_time AS COL0
,BT_FCT_CALLS_FCT_CALLS.calling_number AS COL1
,BT_FCT_CALLS_FCT_CALLS.called_number AS COL2
,BT_FCT_CALLS_FCT_CALLS.response AS COL3
FROM departments BT_DEPARTMENTS_DEPARTMENTS_3 LEFT OUTER JOIN
(
directory_numbers BT_DIRECTORY_NUMBERS_DIRECTORY_NUMBERS LEFT OUTER JOIN
(
users BT_USERS_USERS_2 JOIN
(
call_classification_dim BT_CALL_CLASSIFICATION_DIM_CALL_CLASSIFICATION_DIM JOIN
(
flags BT_FLAGS_FLAGS JOIN
(
fct_calls BT_FCT_CALLS_FCT_CALLS JOIN call_flags BT_CALL_FLAGS_CALL_FLAGS
ON (BT_FCT_CALLS_FCT_CALLS.id = BT_CALL_FLAGS_CALL_FLAGS.call_id)
)
ON (BT_CALL_FLAGS_CALL_FLAGS.flag = BT_FLAGS_FLAGS.id AND ( BT_FLAGS_FLAGS.id = 1) )
)
ON (BT_FCT_CALLS_FCT_CALLS.call_direction_id = BT_CALL_CLASSIFICATION_DIM_CALL_CLASSIFICATION_DIM.id AND ( BT_CALL_CLASSIFICATION_DIM_CALL_CLASSIFICATION_DIM.id = 2) )
)
ON (((BT_FCT_CALLS_FCT_CALLS.on_network_called_user_id = BT_USERS_USERS_2.id) OR (BT_FCT_CALLS_FCT_CALLS.on_network_calling_user_id = BT_USERS_USERS_2.id)) AND TRUE )
)
ON (((BT_FCT_CALLS_FCT_CALLS.on_network_called_ext_id = BT_DIRECTORY_NUMBERS_DIRECTORY_NUMBERS.id) OR (BT_FCT_CALLS_FCT_CALLS.on_network_calling_ext_id = BT_DIRECTORY_NUMBERS_DIRECTORY_NUMBERS.id)) AND TRUE)
)
ON (((BT_FCT_CALLS_FCT_CALLS.on_network_called_department_id = BT_DEPARTMENTS_DEPARTMENTS_3.id) OR (BT_FCT_CALLS_FCT_CALLS.on_network_calling_department_id = BT_DEPARTMENTS_DEPARTMENTS_3.id)) AND TRUE)
WHERE
(
(
NOT(BT_DEPARTMENTS_DEPARTMENTS_3.id IN (1))
)
AND (
NOT(BT_DIRECTORY_NUMBERS_DIRECTORY_NUMBERS.id IN (1))
)
AND (
NOT(BT_USERS_USERS_2.id IN (1))
)
)
ORDER BY
COL0
可能有很多解釋(索引,連接,...),並且很難說不查看查詢。即使這樣可能會很棘手...... –
什麼是查詢? – davey
問題是我們沒有查詢。 – Mihai