i have 3 table
1)files: files main data
2)user_files : user info
3)file_pages : each page of the file have a row in this table and have a field as page_content with FULLTEXT
index
for search i wrote this query
SELECT * FROM files
right join file_pages on files.id = file_pages.doc_id
right join user_files on files.id = user_files.file_id
WHERE (files.status='C' or files.status='L') and (
(user_files.description LIKE '%space%')
or
(user_files.title LIKE '%space%')
or
(file_pages.page_content LIKE '%space%' ) group by files.id
this query result : Showing rows 0 - 24 (399 total, Query took 6.9195 seconds.)
but when i search without join
SELECT * FROM `file_pages` WHERE `page_content` LIKE '%space%'
the result is : Showing rows 0 - 24 (7973 total, Query took 0.0026 seconds.)
with join my query take 7 second but the main part of query just need 0.002 second to execute
now my file_pages table is small and have about 10k row , but when it grow and got 100k row my search time increased to 120 seconds
how can i get a better speed?
Update: it seems this is not related to using “like” and wildcards
because when i remove a part of my joins
SELECT * FROM files
right join file_pages on files.id = file_pages.doc_id
WHERE (files.status='C' or files.status='L') and
( file_pages.page_content LIKE '%space%' ) group by files.id
this took Showing rows 0 - 24 (399 total, Query took 0.7110 seconds.)
compare with first query!