I have 3 tables:
t1 approx 500.000rows t2 1.600rows t3 50.000rows
My SQL query takes (around) 15sec to display results in phpmyadmin.
SELECT *
FROM (
SELECT NULL AS post_subject, t1.id_rec, t1.name, t1.id_cat, t1.date_of_record
FROM records AS t1
INNER JOIN categories AS t3 ON t1.id_cat = t3.id_cat AND t3.private =0
UNION
SELECT post_subject, NULL , NULL , NULL , post_time
FROM posts
ORDER BY date_of_record DESC
LIMIT 10
) a
And indexes are:
records (t1):
id_rec = PRIMARY
name = INDEX
id_cat = INDEX
categories (t3):
id_cat = PRIMARY
posts:
post_subject = INDEX
The goal is to get 10rows which are ordered based on DATE_OF_RECORD && POST_TIME. Table of records and posts are not connected and they represent different data. I am trying to get some kind of "log" from my data... (t1&&t3),(posts).... as it goes in time...
Could you help me please with optimization?