MySQL Forums
Forum List  »  Performance

How should I optimize this query?
Posted by: Gianfranco Fedele
Date: February 12, 2011 11:30AM

I have to optimize this query:

SELECT COUNT(*)
FROM (SELECT DISTINCT( node.nid ) AS nid,
node.TYPE AS node_type,
node.vid AS node_vid,
node_data_field_codice_web.field_codice_web_value AS
node_data_field_codice_web_field_codice_web_value,
node.LANGUAGE AS node_language,
node.title AS node_title,
node_revisions.teaser AS node_revisions_teaser,
node_revisions.FORMAT AS
node_revisions_format,
node_data_field_codice_web.field_indirizzo_value AS
node_data_field_codice_web_field_indirizzo_value,
node_data_field_codice_web.field_vani_value AS
node_data_field_codice_web_field_vani_value,
node.created AS node_created,
node_data_field_codice_web.field_trattativa_value AS
node_data_field_codice_web_field_trattativa_value,
users.name AS users_name,
users.uid AS users_uid,
users.picture AS users_picture,
users.mail AS users_mail,
node_data_field_codice_web.field_prezzo_value AS
node_data_field_codice_web_field_prezzo_value,
node_data_field_indirizzo.field_indirizzo_value AS
node_data_field_indirizzo_field_indirizzo_value,
node_data_field_indirizzo.field_prezzo_value AS
node_data_field_indirizzo_field_prezzo_value,
node_data_field_indirizzo.field_vani_value AS
node_data_field_indirizzo_field_vani_value
FROM node node
INNER JOIN term_node term_node_value_0
ON node.vid = term_node_value_0.vid
AND term_node_value_0.tid = 57
LEFT JOIN content_type_annuncio_immobiliare
node_data_field_codice_web
ON node.vid = node_data_field_codice_web.vid
LEFT JOIN node_revisions node_revisions
ON node.vid = node_revisions.vid
INNER JOIN users users
ON node.uid = users.uid
LEFT JOIN content_type_annuncio_immobiliare
node_data_field_indirizzo
ON node.vid = node_data_field_indirizzo.vid
WHERE ( term_node_value_0.tid = 57 )
AND ( node.status <> 0 )
AND ( node.TYPE IN ( 'thetype' ) )
AND ( node.LANGUAGE IN ( 'en' ) )
GROUP BY nid
ORDER BY node_data_field_indirizzo_field_indirizzo_value ASC,
node_data_field_indirizzo_field_prezzo_value ASC,
node_data_field_indirizzo_field_vani_value ASC) count_alias

EXPLAIN command gives me:

+----+-------------+----------------------------+--------+---------------------------------------------+-----------+---------+-------------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------------------------+--------+---------------------------------------------+-----------+---------+-------------------+------+----------------------------------------------+
| 1 | PRIMARY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
| 2 | DERIVED | node | ref | vid,node_status_type,node_type,uid,language | node_type | 14 | | 1 | Using where; Using temporary; Using filesort |
| 2 | DERIVED | users | eq_ref | PRIMARY | PRIMARY | 4 | rbdrupal.node.uid | 1 | Using where |
| 2 | DERIVED | term_node_value_0 | eq_ref | PRIMARY,vid | PRIMARY | 8 | rbdrupal.node.vid | 1 | |
| 2 | DERIVED | node_data_field_codice_web | eq_ref | PRIMARY | PRIMARY | 4 | rbdrupal.node.vid | 1 | |
| 2 | DERIVED | node_data_field_indirizzo | eq_ref | PRIMARY | PRIMARY | 4 | rbdrupal.node.vid | 1 | |
| 2 | DERIVED | node_revisions | eq_ref | PRIMARY | PRIMARY | 4 | rbdrupal.node.vid | 1 | |
+----+-------------+----------------------------+--------+---------------------------------------------+-----------+---------+-------------------+------+----------------------------------------------+

I'm going crazy! What should I do?

Thanks everybody.

Options: ReplyQuote


Subject
Views
Written By
Posted
How should I optimize this query?
1784
February 12, 2011 11:30AM
925
February 13, 2011 06:22PM
803
February 15, 2011 10:52AM
763
February 16, 2011 12:51AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.