[英]Optimize a query with LEFT JOIN with multiple WHERE Clauses
Is it at all possible to optimize the query below, which was produced today: 是否有可能优化今天产生的以下查询:
SELECT DISTINCT a.*,country,c.id
id_employer,c.comp_name,c.show_comp_name,comp_type,b.id countryid,if(now()
<a.hotjob_expire, true, false) is_hot
FROM j5xap_jbjobs_job a
LEFT JOIN j5xap_jbjobs_country b ON a.id_country = b.id
LEFT JOIN j5xap_jbjobs_employer c ON a.employer_id = c.user_id
LEFT JOIN j5xap_jbjobs_custom_field_value cv ON cv.jobid=a.id
LEFT JOIN j5xap_jbjobs_comp_type d ON c.id_comp_type = d.id
WHERE (a.job_title LIKE '%Web developer%'
OR a.state LIKE '%Web developer%'
OR a.city LIKE '%Web developer%'
OR b.country LIKE '%Web developer%'
OR c.comp_name LIKE '%Web developer%'
OR cv.value LIKE '%Web developer%'
OR cv.valuetext LIKE '%Web developer%'
OR a.short_desc LIKE '%Web developer%'
OR a.long_desc LIKE '%Web developer%')
OR (a.job_title LIKE '%kannur%'
OR a.state LIKE '%kannur%'
OR a.city LIKE '%kannur%'
OR b.country LIKE '%kannur%'
OR c.comp_name LIKE '%kannur%'
OR cv.value LIKE '%kannur%'
OR cv.valuetext LIKE '%kannur%'
OR a.short_desc LIKE '%kannur%'
OR a.long_desc LIKE '%kannur%')
AND a.id_job_spec =441 AND a.id_job_spec
IN (SELECT id FROM j5xap_jbjobs_job_spec WHERE id_category='63')
AND
a.is_active='y' AND a.publish_date <= '2017-07-07 00:00:00'
AND
expire_date >= '2017-07-07 00:00:00'
AND
expire_date <> '0000-00-00 00:00:00'
ORDER BY is_hot DESC, a.is_featured DESC, a.publish_date DESC, a.id
DESC LIMIT 0, 10;
I have been looking at it extensively but I am a little out of ideas. 我一直在广泛地看它,但是我有点想法不对。 Left Joins have to be used in this context.
在这种情况下,必须使用左联接。 I have included multi column indexes on the tables and on the fields that are being retrieved from the SELECT clause.
我在要从SELECT子句中检索的表和字段中包括了多列索引。
Are there any ideas? 有什么想法吗? Thank you.
谢谢。
I would start with an index on: j5xap_jbjobs_job(id_job_spec, is_active, publish_date, is_expire)
. 我将从以下索引开始:
j5xap_jbjobs_job(id_job_spec, is_active, publish_date, is_expire)
。 For all the other tables, you need an index on the join keys. 对于所有其他表,您需要在连接键上建立索引。
This should allow the filtering to take place using an index, which should be a win for performance. 这应该允许使用索引进行过滤,这应该是性能的胜利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.