I have approx. 200K rows in the tb_post table, and every 5 minutes it has approx. 10 new inserts.
I use the following query to retrieve strings -
SELECT tb_post.ID, tb_post.USER_ID, tb_post.TEXT, tb_post.RATING, tb_post.CREATED_AT, tb_user.ID, tb_user.NAME FROM tb_post, tb_user WHERE tb_post.USER_ID=tb_user.ID ORDER BY tb_post.RATING DESC LIMIT 30
It takes more than 10 seconds to sort all rows in a sorted way.
The following is an EXPLAIN request report:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tb_user ALL PRIMARY NULL NULL NULL 20950 Using temporary; Using filesort
1 SIMPLE tb_post ref tb_post_FI_1 tb_post_FI_1 4 tb_user.id 4
Multiple Inputs:
tb_post.RATING - type Float- There is an index on
tb_post.USER_ID
Can someone offer me some guidance on how I can optimize this query and improve its reading performance?
PS: I am new to database scaling issues. Therefore, any suggestions would be useful for this request.
source share