我有38k行的表,我使用这个查询来比较项目表中的项目标识与来自posting_domains表的项目标识。Mysql长执行查询
select * from `items`
where `items`.`source_id` = 2 and `items`.`source_id` is not null
and not exists (select *
from `posted_domains`
where `posted_domains`.`item_id` = `items`.`id` and `domain_id` = 1)
order by `item_created_at` asc limit 1
这个查询了787-8。我不知道我的查询是否有问题,或者我的mysql配置不当。由Laravel关系产生像
$items->doesntHave('posted', 'and', function ($q) use ($domain) {
$q->where('domain_id', $domain->id);
});
哪些列在您的表中有索引? – Webeng
只是在每个表上的id列 – user3233336
我在张贴的表上添加了索引,现在比156ms快得多。谢谢! – user3233336