为什么左连接在MySQL中需要花费这么多时间?

时间:2017-03-16 08:57:35

标签: mysql sql left-join

我创建了两个临时表:

create temporary table temp.PromoCust (
    CustId int(10)
);

create temporary table temp.Inv (
    CustId int(10),
    InvId int(10)
);

插入一些数据:

insert into temp.PromoCust
select pl.CustomerId
from promoline pl
where pl.PromoId = 3008;

select * from temp.PromoCust; -- count is 234.995 customers

insert into temp.Inv
select i.CustomerId, i.InvoiceId
from invoice i
where i.InvoiceDate between '2016-12-21' and '2017-01-03';

select * from temp.Inv; -- count is 86.684 customers and invoices

最后我运行左连接查询:

select pc.CustId, i.InvId
from temp.PromoCust pc left join temp.Inv i
    on pc.CustId = i.CustId;

出于某种原因,这需要永远。这个查询有问题吗?我无法从中得到任何结果。

0 个答案:

没有答案