优化 count 去重 语句查询从一分30秒到500ms

tech2023-12-24  79

 待优化sql:

select count(DISTINCT sip) from mining_machine where mining_pool='YES';

sql 优化: 1:建立非聚集联合索引create index count_sip on public.mining_machine(mining_pool,sip); 2:优化后sql;

select count(*) from (select sip from mining_machine where mining_pool ='YES' group by sip ) t ;

结果:建立索引sql查询由1m36s 缩短为17s;sql优化后,查询返回时间535ms,保证一秒内返回结果。

最新回复(0)