数据库
隔壁敲代码的王先生
不积跬步无以至千里,不积小流无以成江海。
展开
-
优化 count 去重 语句查询从一分30秒到500ms
待优化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 ='Y.原创 2020-09-03 17:19:06 · 394 阅读 · 0 评论 -
postgresql count(distinct) 优化实践
描述:业务需要查表,该表大约不到四个G,总行数900w条,一个简单的去重的条件查询需要一分钟四十秒,这是不能忍受的。原语句:耗时1m40sselect count(DISTINCT sip) from mining_machine where mining_pool='YES';优化措施:1:首先想到加索引,索引顺序也很重要,根据sql解析顺序 where 解析在前。create index count_sip on public.mining_machine(mining_pool原创 2020-07-09 17:34:44 · 2610 阅读 · 0 评论