我的数据库中的表“业务”有100 000条记录。 我的数据库的表“类别”有900条记录。 当我运行查询
SELECT * FROM businesses b WHERE
((b.name LIKE '%Fake%'
AND (b.is_deleted = 0 || ISNULL(b.is_deleted)))
OR EXISTS (SELECT * FROM categories c
WHERE c.`name` LIKE '%Fake%'
AND c.is_deleted = 0 AND b.is_deleted = 0
AND b.`categories_ids` LIKE CONCAT('%|', c.id, '|%')))
group by b.id ORDER BY b.`name` ASC LIMIT 0, 20;
返回结果只需0.06秒。 但是当我运行查询
时SELECT * FROM businesses b WHERE
((b.name LIKE '%Fake u%'
AND (b.is_deleted = 0 || ISNULL(b.is_deleted)))
OR EXISTS (SELECT * FROM categories c
WHERE c.`name` LIKE '%Fake u%'
AND c.is_deleted = 0 AND b.is_deleted = 0
AND b.`categories_ids` LIKE CONCAT('%|', c.id, '|%')))
group by b.id ORDER BY b.`name` ASC LIMIT 0, 20
它只是搜索字符串中的多个字符,但需要114才能返回结果。
为什么查询后花了太多时间???