I have an SQL query that I think is not optimized enough. I timed it, and it sometimes take 1.5 seconds to complete, which seems a little high, no?
anyway this is the query:
SELECT id, link, feed, category, description, title, GROUP_CONCAT( tag ) as t, published
FROM items
LEFT JOIN tags ON items.id = tags.item_id
WHERE id NOT IN (
SELECT item_id
FROM tags, sinunim
WHERE tag = name
AND op = '1'
AND user = '$user_cookie'
) AND id NOT IN (
SELECT id
FROM sinunim
WHERE id <> 0
AND user = '$user_cookie'
) AND id NOT IN (
SELECT i.id
FROM sinunim s, items i
WHERE s.type = 'category'
AND s.name = i.category
AND s.op = '1'
AND s.user = '$user_cookie'
) AND id NOT IN (
SELECT i.id
FROM `sinunim` s, items i
WHERE s.name = i.feed
AND s.op = '1'
AND s.user = '$user_cookie'
)
GROUP BY items.title
ORDER BY items.published DESC
LIMIT 0 , 50
EXPLAINresults on display. ) And yes, joining by nested queries doesn't seem quite right.EXPLAIN, it would be nice to see what the table definitions are and what indexes are in place as well