待优化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,保证一秒内返回结果。