I am writing a SQL query which requires highly optimized solution, so as to not timeout. But I have got no idea of how to continuously optimize the following SQL query:
select distinct j.job,f.path,p.path
from fixes f, jobs j, paths p where f.job=j.id and p.id =f.path
and (p.path like '//Tools/Web/%' or p.path = '//Tools/Web');
I have created indexes on the following fields(essentially everything):
- jobs.id
- jobs.job
- paths.path
- paths.id
- fixes.job
- fixes.path
In each of the "fixes", "jobs", "paths" table there are ~50,000 rows, and current timeout is 6 min
The 'explain' command shows the following information, try to deciphering
1 SIMPLE j index PRIMARY job 62 (null) 73226 Using index; Using temporary
1 SIMPLE f ref path,job job 8 j.id 825
1 SIMPLE p eq_ref PRIMARY,path PRIMARY 8 f.path 1 Using where
The table creation statements for the 'paths' table:
CREATE TABLE `paths` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`path` varchar(250) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `path` (`path`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLEstatements for the 3 tables?DISTINCT?