I am facing performance issue, while running a SQL query that uses MyISAM database.
To brief this, I have 3 tables:
Table: A (Engine MyISAM. Total Records: 1847)
Table: B (Engine MyISAM. Total Records: 1110)
Table: C (Engine MyISAM. Total Records: 57867)
Now the query I am running is taking 623 seconds to get execute and sometime it happens that connection from server(same is the case with localhost) gets aborted.
Below is the query I am executing:
SELECT MATCH(A.title, A.description) AGAINST('Computer Graphic Artist') AS 'Score',
A.code AS 'Code',
B.cluster AS 'Cluster',
B.pathway AS 'Pathway',
A.title AS 'Role',
A.description AS 'Description'
FROM B
INNER JOIN A ON B.code = A.code
INNER JOIN C ON B.code = C.code
WHERE MATCH(A.title, A.description) AGAINST('Computer Graphic Artist')
OR MATCH(B.cluster, B.pathway, B.descripton) AGAINST('Computer Graphic Artist')
OR MATCH(C.title) AGAINST('Computer Graphic Artist')
ORDER BY Score DESC, B.cluster ASC
You can also refer to Pastie (if you feel trouble seeing this SQL). I have added FULLTEXT property wherever it is applicable.
NOTE: Table A, B and C have few duplicate records as well.
Please let me know, how I can optimize this SQLfor fast output.
The first thing to do is to make sure that you have a FULLTEXT index in place on the exact set of columns you are querying from each table:
Then I would recommend rewriting your query to use UNION instead of OR. I’ve gotten much better performance from FULLTEXT searches in particular in MySQL using this approach.
Here’s an example using your query: