How many records do you have? 25 million? If it's just a couple of thousand, it shouldn't take anything more than 1 second. Make sure that the id field is indexed. If it's a primary key already, then no indexing is needed.
And now to something more serious. you have included this:
WHERE kw.keyword like '%test%' OR wm.title like '%test%'
This is bad. It will definitely slow your queries even if you had a thousand records. One improvement is to do this:
WHERE kw.keyword like 'test%' OR wm.title like 'test%'
In the above, we are looking for words starting with test. And now you can go one step further by indexing the columns title and keyword.
But the above will not meet your requirement if you wanted to search within the keywords and titles.
for this I have two suggestions.
- Create a separate table with single keywords and titles, and link them to the current tables. This is what I'd do but it's a little extra work.
- The eaiser way (but i don't still like this) is to setup full text searches. This has some restrictions - please check the documentation.