0

很难理解为什么相对较小的表的附加排序会导致如此糟糕的性能。以下查询在 ORDER BY 语句中没有 u.list_priority 时执行得非常好。该列已编入索引。

SELECT l.*, u.list_desc
FROM iq_99990022.tbl_vpd_campaign_leads l
INNER JOIN intelliqueue_globalcatalog.tbl_vpd_uploaded_lists u ON l.list_id = u.list_id
WHERE u.campaign_id IN (60238,60241)
AND IFNULL(u.list_state, 'ACTIVE') = 'ACTIVE'
AND l.lead_state = 'READY'
AND l.next_dial_time <= now()
AND l.lead_passes < max_passes
ORDER BY u.list_priority, l.lead_passes ASC
LIMIT 100

这是两张桌子的钥匙...

u : PRIMARY KEY  (`list_id`),
  KEY `list_priority` (`list_priority`)

l :   PRIMARY KEY  (`lead_id`),
  UNIQUE KEY `campaign_id` (`campaign_id`,`lead_phone`,`dupe_key_override`),
  KEY `next_dial_time` (`next_dial_time`),
  KEY `ix_state` (`state`),
  KEY `lead_state` (`lead_state`,`campaign_id`,`lead_passes`)

这是没有 ORDER BY 中的列的 EXPLAIN 结果...

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  l   ref next_dial_time,lead_state   lead_state  63  const   15131   Using where; Using filesort
1   SIMPLE  u   eq_ref  PRIMARY PRIMARY 4   iq_99990022.l.list_id   1   Using where

与...

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  l   ref next_dial_time,lead_state   lead_state  63  const   15131   Using where; Using temporary; Using filesort
1   SIMPLE  u   eq_ref  PRIMARY PRIMARY 4   iq_99990022.l.list_id   1   Using where

是否有可能跨不同数据库的连接会阻止索引被使用?

4

0 回答 0