今天写了一个统计sql,在一个近亿条数据的表上执行,200s都查不出结果.SQL如下: select customer,count(1) c from upv_** where created between "2015-07-06" and "2015-07-07" group by customer having c > 20 order by c desc 执行explain,发现这个sql扫描了8000W条记录到磁盘上.然后再进行筛选.type=ind…
[转自:https://blog.csdn.net/bruce128/article/details/46777567]并进行总结 今天写了一个统计sql,在一个近亿条数据的表上执行,200s都查不出结果.SQL如下: ) c from upv_** where created between "2015-07-06" and "2015-07-07" group by customer having c > order by c desc 执行explain…
本文转自http://www.dataguru.cn/article-3302-1.html oracle数据库管理优化必备语句: 1. SELECT T.START_TIME,T.USED_UBLK,S.USERNAME,R.SEGMENET_NAME FROM V$TRANSACTION T,V$SESSION S,V$DBA_ROLLBACK_SEGS R WHERE T.SES_ADDR=S.SADDR AND T.XIDUSN=R.SEGMENT_ID运行的是无数,用户,保护的撤销段,…
[问题现象] 线上mysql数据库爆出一个慢查询,DBA观察发现,查询时服务器IO飙升,IO占用率达到100%, 执行时间长达7s左右.SQL语句如下:SELECT DISTINCT g.*, cp.name AS cp_name, c.name AS category_name, t.name AS type_name FROMgm_game g LEFT JOIN gm_cp cp ON cp.id = g.cp_id AND cp.deleted = 0 LEFT JOIN gm_cate…
转自:http://www.51testing.com/html/01/n-867201-2.html [问题现象] 线上mysql数据库爆出一个慢查询,DBA观察发现,查询时服务器IO飙升,IO占用率达到100%, 执行时间长达7s左右. SQL语句如下: SELECT DISTINCT g.*, cp.name AS cp_name, c.name AS category_name, t.name AS type_name FROMgm_game g LEFT JOIN gm_cp cp O…
一.优化SQL语句的一般步骤 1. 通过show status命令了解各种SQL的执行频率 mysqladmin extended-status 或: show [session|global]status 参数解析: session表示当前连接的统计结果,global表示自数据库上次启动至今的统计结果.默认为session. 例如,查看当前session中所有统计参数的值: show status like 'Com_%'; Com_xxx表示每个xxx语句执行的次数,比如,Com_selec…