I've 2 tables:
POSTS (about 2000 rows)
ID title
and
ELEMENTS (about 60000 rows)
postID (fK) elementfield
Basically I would like to return the ID if the searchterm is in posts.title or in elements.elementname. I use the following query:
SELECT SQL_CALC_FOUND_ROWS posts.ID
FROM posts
LEFT JOIN elements
ON posts.ID = elements.postID
WHERE (
posts.post_title LIKE '%searchterm%'
OR elements.elementfield LIKE '%searchterm%'
)
It works, but it's very very slow (about 40 seconds!).
I believed it was the size of the elements table (over 60.000 rows) but if I run the same query with only one WHERE clause
WHERE elements.elementfield LIKE '%searchterm%'
it returns the find in a fraction of second...
I'm not a DB expert, but this looks very basic... What am I doing wrong? Thanks for your help!
EDIT @Solarflare Run EXPLAIN I have something like this:
id select_type table type possible_keys rows Extra
1 SIMPLE posts eq_ref PRIMARY,type_ 1 Using
status_date Where
1 SIMPLE elements ALL NULL 67774 Using
where;
Using
join
buffer
(Block Nested Loop)