Mysql 我正在努力提高这个查询的性能,有人能在这个查询上帮助我吗 查询

Mysql 我正在努力提高这个查询的性能,有人能在这个查询上帮助我吗 查询,mysql,sql,Mysql,Sql,首先,在不使用distinct的情况下重写查询,并修复数据,使状态具有统一的大小写: select DISTINCT subscriber_data.* from subscriber_data, entities where entities.id in ( 2,3,4,5,6,7,8,9,10,11,12,13,14, 15,16,17,18,19,20,21,22,23,24,25, 26,27,28,29,30,31,32,33,34,35,36,37,38,39,

首先,在不使用
distinct
的情况下重写查询,并修复数据,使
状态具有统一的大小写:

select DISTINCT subscriber_data.* 
from subscriber_data, entities
where entities.id in 
(
   2,3,4,5,6,7,8,9,10,11,12,13,14,
   15,16,17,18,19,20,21,22,23,24,25,
   26,27,28,29,30,31,32,33,34,35,36,37,38,39,1
) 
and Lower( subscriber_data.status) in ( 'active','expired')
and (subscriber_data.entity_uid = entities.channel_uid 
and subscriber_data.channel_id = entities.channel_id) 
and Lower( subscriber_data.status) in ( 'active','expired')
order by subscriber_data.land_size desc LIMIT 0,10

然后添加以下索引:
订户数据(状态、土地大小、实体uid、频道id)
实体(频道uid、频道id、id)

是否会降低性能?你为什么要这样做?编辑你的问题并正确对齐代码。这是一个后端查询,我需要优化上面的查询。我已经添加了索引。SQL错误(1064):你的SQL语法有错误;请检查与MySQL服务器版本对应的平均值,以了解在第11行的“sd.status in('active',expired')order by sd.land_size desc LIMIT 0,10”附近使用的正确语法*/请在此查询中提供帮助您希望我添加唯一键索引或普通键吗index@SRI . . . 如果它们是唯一的,则可以添加唯一索引。但常规索引就可以了。不添加子查询是另一种优化方法
select sd.* 
from subscriber_data sd
where exists (select 1
              from entities e
              where e.id in (2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,
                             26,27,28,29,30,31,32,33,34,35,36,37,38,39,1
                            ) and 
                   sd.entity_uid = e.channel_uid  and
                   sd.channel_id = e.channel_id
             ) and
      sd.status in ( 'active', 'expired')
order by sd.land_size desc
LIMIT 0, 10;