M
M
Maxim2012-02-23 16:12:22
MySQL
Maxim, 2012-02-23 16:12:22

mysql fetch optimization

Please tell me the difference in the speed of processing such a request: Or faster like this: It seems like the second one is executed exactly twice as fast. And how does it affect if you add monog conditions. I would be glad if you tell me what sensible materials on sql optimization
SELECT wt.title, wt.url_title, wt.entry_date, wd.field_id_2 AS body,
IF(ft.thread_total, ft.thread_total, 0) AS thread_total
FROM exp_weblog_titles AS wt
LEFT JOIN exp_weblog_data AS wd ON wd.entry_id = wt.entry_id
LEFT JOIN exp_forum_topics AS ft ON ft.topic_id = wt.forum_topic_id
WHERE wt.weblog_id = 2


SELECT wt.title, wt.url_title, wt.entry_date, wd.field_id_2 AS body,
IF(ft.thread_total, ft.thread_total, 0) AS thread_total
FROM exp_weblog_titles AS wt, exp_weblog_data AS wd, exp_forum_topics AS ft
WHERE wt.weblog_id = 2 AND wd.entry_id = wt.entry_id AND ft.topic_id = wt.forum_topic_id


Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly, 2012-02-23
@taliban

The conditions in this case indirectly affect the speed, it is your speed that is affected by the type of table joins, the first LEFT JOIN the second INNER JOIN. After reading about these types of connections, you will find out the difference in speed and which option is more preferable when.

A
AlexeyK, 2012-02-23
@AlexeyK

Use EXPLAIN SELECT.

S
SwampRunner, 2012-02-23
@SwampRunner

explain select and see if the index is used in the selection

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question