hi,
I’m noob but still lerning so can you help me with this?
I have res_item table with articles (about 200k rows), fa_user table with authors, notes (users can vote for articles, note is sum( no_note ) and comments table (I want to show number of comments count( co_id )).
Aricles have to be ordered by it_id DESC.
My query:
SELECT i . * , note_sum, comments_count, u.user_nameFROM (res_item
i)INNER JOIN fa_user
u ON i.it_us_id = u.idLEFT JOIN (SELECT no_it_id, sum( no_note ) AS note_sumFROM notesGROUP BY no_it_id)n ON n.no_it_id = i.it_idLEFT JOIN (SELECT co_it_id, count( co_id ) AS comments_countFROM commentsGROUP BY co_it_id)co ON co.co_it_id = i.it_idORDER BY it_id DESCLIMIT 10
92.0550 s (
The query EXPLAIN
id select_type table type possible_keys key key_len ref rows Extra1 PRIMARY i ALL NULL NULL NULL NULL 182850 Using temporary; Using filesort1 PRIMARY u eq_ref PRIMARY PRIMARY 4 podajcegle_2.i.it_us_id 1 Using where1 PRIMARY ALL NULL NULL NULL NULL 2 1 PRIMARY ALL NULL NULL NULL NULL 1 3 DERIVED comments ALL NULL NULL NULL NULL 4 Using temporary; Using filesort2 DERIVED notes ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
without ORDER BY everything is good, 0.27s