我有很多查询,例如以下查询。我如何优化它们-
SELECT DISTINCT
n.nid AS nid, n.title AS title, n.created AS created, n.changed AS changed,
n.type AS type, n.status AS status, n.uid AS uid, u.name AS name,
fit.field_item_topic_tid AS field_item_topic_tid,
fui.field_upload_item_fid AS field_upload_item_fid,
fist.field_item_sub_topic_tid AS field_item_sub_topic_tid,
asid.field_item_asset_id_value AS field_item_asset_id_value,
fur.field_item_urgent_value AS field_item_urgent_value,
scrubbing.field_item_scrubbing_value AS field_item_scrubbing_value,
wsts.field_item_workflow_status_value AS field_item_workflow_status_value,
wfs.state AS state
FROM
node n
LEFT OUTER JOIN field_data_field_item_topic fit ON n.nid=fit.entity_id
LEFT OUTER JOIN field_data_field_upload_item fui ON fui.entity_id= n.nid
LEFT OUTER JOIN field_data_field_item_sub_topic fist ON n.nid=fist.entity_id
LEFT OUTER JOIN field_data_field_item_asset_id asid ON n.nid=asid.entity_id
LEFT OUTER JOIN field_data_field_item_urgent fur ON fur.entity_id= n.nid
LEFT OUTER JOIN field_data_field_item_scrubbing scrubbing ON scrubbing.entity_id= n.nid
LEFT OUTER JOIN field_data_field_item_workflow_status wsts ON wsts.entity_id = n.nid
LEFT OUTER JOIN workflow_states wfs ON wfs.sid = wsts.field_item_workflow_status_value
LEFT OUTER JOIN users u ON u.uid = n.uid
WHERE ( (n.type = 'item') )
AND( (wsts.field_item_workflow_status_value IN ('All', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10')) )
AND( (fit.field_item_topic_tid IN ('NULL', '46', '47', '48', '52', '73', '90', '118', '142', '150', '154', '175', '196', '362', '363', '366', '367', '383', '403', '406', '533', '535', '543'))
OR (fist.field_item_sub_topic_tid IN ('NULL', '50', '51', '66', '67', '70', '71', '74', '75', '76', '93', '143', '151', '197', '198', '206', '211', '304', '364', '368', '384', '404', '407', '534', '536'))
)
ORDER BY n.changed desc
LIMIT 20 OFFSET 0
EXPLAIN-
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE wsts range entity_id,field_item_workflow_status_value field_item_workflow_status_value 5 NULL 1708 Using where; Using temporary; Using filesort
1 SIMPLE wfs eq_ref PRIMARY PRIMARY 4 lightening1.wsts.field_item_workflow_status_value 1
1 SIMPLE n eq_ref PRIMARY,node_type,nid PRIMARY 4 lightening1.wsts.entity_id 1 Using where
1 SIMPLE u eq_ref PRIMARY PRIMARY 4 lightening1.n.uid 1
1 SIMPLE fit ref entity_id entity_id 4 lightening1.wsts.entity_id 1
1 SIMPLE fui ref entity_id entity_id 4 lightening1.wsts.entity_id 1
1 SIMPLE fist ref entity_id entity_id 4 lightening1.n.nid 1 Using where
1 SIMPLE asid ref entity_id entity_id 4 lightening1.wsts.entity_id 1
1 SIMPLE fur ref entity_id entity_id 4 lightening1.wsts.entity_id 1
1 SIMPLE scrubbing ref entity_id entity_id 4 lightening1.n.nid 1