0

我有 2 个 MySql 表有一些类似的列(存储相同类型的数据)

例如 ,如果tableA有一些字段为email, phone, cellphone,id tableB也有email, phone, mobile,id

我想从 tableA 中选择所有用户where email = email or phone=phone or mobile=cellphone or id=id

但是这两个表中的数据都太大了> 100万条记录每个表

我们能得到的最好的 Sql Query 是什么?

我正在使用的是

SELECT LN.LEADS360ID ,LN.fundingDate,LN.closedDate  
FROM fsbcorploan.loan  LN inner JOIN fsbcorponline.leads360leads LD ON   
LD.RefId  = LN.LEADS360ID  OR  
LD.Email  = LN.borrower_email OR   
LD.CellPhone = LN.borrower_home_phone OR  
LD.CellPhone = LN.borrower_cell_phone OR  
LD.DayPhone = LN.borrower_home_phone OR  
LD.DayPhone = LN.borrower_cell_phone OR  
LD.EveningPhone = LN.borrower_home_phone OR  
LD.EveningPhone = LN.borrower_cell_phone  
WHERE  dateAdded between '11/01/2012 05:10:00' and '12/11/2012 05:10:00'

执行需要 13-15 秒

4

1 回答 1

1

试试这是否更快......可能不是但值得一试。

SELECT LN.LEADS360ID ,LN.fundingDate,LN.closedDate  
FROM fsbcorploan.loan  LN 
where dateAdded between '11/01/2012 05:10:00' and '12/11/2012 05:10:00'
and exists (
  select 1 from fsbcorponline.leads360leads LD
  where LD.RefId  = LN.LEADS360ID
    OR LD.Email  = LN.borrower_email
    OR LD.CellPhone = LN.borrower_home_phone
    OR LD.CellPhone = LN.borrower_cell_phone 
    OR LD.DayPhone = LN.borrower_home_phone
    OR LD.DayPhone = LN.borrower_cell_phone
    OR LD.EveningPhone = LN.borrower_home_phone
    OR LD.EveningPhone = LN.borrower_cell_phone)

如果真的没有办法解决它,您可以拥有某种可以预先计算的“找到匹配”计算列。您将如何执行此操作将取决于此数据更改的频率。

于 2012-12-11T22:04:39.890 回答