mysql left join 加where条线查询很慢

我有个sql查询语句:
select count(1)
from task_basic tb
left join task_catalog tc on tb.CATALOG_ID = tc.CATALOG_ID
and tc.is_del = 0
where tb.is_del = 0
and IFNULL(tb.YWCODE,'0' ) != '0'
-- and (tc.BUSINESSCODES = 'SJ')

图片说明
图片说明

此时查询时间是3秒多,当在下面注释的条件放开时,查询时间就变成将近20秒了,索引也都加了

图片说明
图片说明
图片说明

求大神帮忙看看要怎么优化,感激不尽

调整了Mysql内存,问题解决

条件都放在on后面试试

explain一下查询,截图放出来图片说明

计算满足条件的条数,可用in或者exists。
select count(1)
from task_basic tb
where tb.is_del = 0 and tb.ywcode is not null and exists (select * from task_catalog tc where tb.CATALOG_ID = tc.CATALOG_ID and tc.is_del = 0)