我有一个看起来像这样的联接:
LEFT JOIN abc__emails.my208 my3
ON my3.eid = my.eid
AND (
my3.my_id = 417
AND my3.data = 'AB Deleted Account'
)
此查询是bordeline runnable。我试图保存每一块内存。我的问题是:
LEFT JOIN abc__emails.my208 my3
ON my3.eid = my.eid
AND my3.data = 'AB Deleted Account'
我删除了my3.my_id = 417
部分。
记录my_id = 417包括' AB已删除帐户'还有其他几个字符串。我把它包括在内是因为我认为我可以帮助SQL缩小范围。这是错的吗?
我真的只想让联接成为my3.data = 'AB Deleted Account'.
最好添加尽可能多的"过滤器"尽可能多地删除?
eid已经成为两个牌桌上的关键。
以下反馈是EXPLAIN的输出
1 SIMPLE co ALL 198784 Using temporary; Using filesort
1 SIMPLE my eq_ref PRIMARY PRIMARY 8 abc_emails.co.id,const 1
1 SIMPLE my1 eq_ref PRIMARY PRIMARY 8 abc_emails.my.eid,const 1
1 SIMPLE my2 eq_ref PRIMARY PRIMARY 8 abc_emails.my.eid,const 1
1 SIMPLE my3 ref ver_eid ver_eid 4 abc_emails.my.eid 246
1 SIMPLE i ref eid_iid eid_iid 10 abc_emails.my.eid,const 1 Using where; Using index
1 SIMPLE nvk eq_ref PRIMARY PRIMARY 4 abc_emails.co.id 1
以下是查询本身
SELECT
co.id AS ID_Eid,
co.email,
def.def_medium AS def_Medium_def208,
co.created AS Contact_Create_Date,
my1.data AS PAW_ID,
my.data AS Trial_Date,
my2.data AS Upgrade_Date,
MIN(my3.lastmod) AS Cancel_Date
FROM
abc_emails.cid208 co
LEFT JOIN abc_emails.my208 my ON my.eid = co.id AND my.my_id = 581
LEFT JOIN abc_emails.my208 my1 ON my1.eid = my.eid AND my1.my_id = 2765
LEFT JOIN abc_emails.my208 my2 ON my2.eid = my.eid AND my2.my_id = 3347
LEFT JOIN abc__emails.my208 my3 ON my3.eid = my.eid AND (my3.my_id = 417 AND my3.data = 'AB Deleted Account')
LEFT JOIN abc_emails.i208 i ON i.eid = my.eid AND i.iid = 22467
LEFT JOIN abc_emails.def208 def ON def.eid = co.id
WHERE i.iid IS NULL
GROUP BY ID_Eid, email, def_Medium_def208, Contact_Create_Date, PAW_ID, Upgrade_Date