流量统计优化sql查询速度

This commit is contained in:
zhanghongqing
2018-10-26 14:41:27 +08:00
parent f35ca05c0c
commit 2f73a5799b
15 changed files with 395 additions and 249 deletions

View File

@@ -15,20 +15,24 @@
stat_id, web_type, web_id, c2s_pkt_num, s2c_pkt_num, c2s_byte_len, s2c_byte_len,
stat_time
</sql>
<!-- 获取最近时间并且有效 -->
<select id="getMaxStatTime" resultType="com.nis.domain.restful.dashboard.TrafficHttpStatistic">
SELECT MAX(stat_time) statTime FROM galaxy.traffic_http_statistic WHERE web_id != 0
</select>
<!-- 根据服务网站将域名分类 网站列表-->
<select id="getDomainByWebsiteList" resultType="com.nis.domain.restful.dashboard.TrafficHttpStatistic">
<select id="getDomainByWebsiteList" resultType="com.nis.domain.restful.dashboard.TrafficHttpStatistic">
SELECT t.stat_time statTime,SUM(link_num) count, IFNULL( website_service_id, 268435455 ) websiteServiceId
FROM galaxy.TRAFFIC_HTTP_STATISTIC t
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id = u.id
where t.web_id!=0
where t.web_id!=0
and t.stat_time = #{statTime}
GROUP BY u.website_service_id ORDER BY count desc limit 0,10
</select>
<!-- 根据主题将域名分类 主题列表 最近五分钟top10-->
<!-- 根据主题将域名分类 主题列表 最近五分钟top10-->
<select id="getDomainByTopicList" resultType="java.util.HashMap">
SELECT SUM(link_num) count, IFNULL( topic_id, 268435455 ) topicId
FROM galaxy.TRAFFIC_HTTP_STATISTIC t
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id = u.id
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id = u.id
where t.web_id!=0
and t.stat_time =#{statTime}
GROUP BY u.topic_id ORDER BY count desc limit 0,10
@@ -37,37 +41,37 @@
<!--获取上个时间段该网站站域名流量的数据量 -->
<select id="preWebsiteListCount" resultType="java.lang.Integer">
SELECT SUM(link_num) count FROM galaxy.traffic_http_statistic t
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id = u.id
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id = u.id
WHERE u.website_service_id=#{websiteServiceId}
and stat_time = DATE_SUB(#{statTime},INTERVAL 5 MINUTE)
</select>
<!--获取网站列表列表 -->
<!--获取网站列表列表 -->
<!-- <select id="websiteList" resultMap="BaseResultMap">
SELECT web_id webId, (SUM(c2s_pkt_num)+SUM(s2c_pkt_num)+SUM(c2s_byte_len)+SUM(s2c_byte_len)) count FROM galaxy.traffic_http_statistic
WHERE web_id !=0 and stat_time >= DATE_SUB((SELECT MAX(stat_time) FROM galaxy.traffic_http_statistic),INTERVAL 5 MINUTE)
GROUP BY web_id ORDER BY count DESC limit 0,10
</select> -->
<!-- 根据网站分组获取子域名 -->
</select> -->
<!-- 根据网站分组获取子域名 -->
<select id="getDomainByWebsiteServiceId" resultType="java.util.HashMap">
SELECT web_id webId,SUM(link_num) count
FROM galaxy.traffic_http_statistic t
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id=u.id
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id=u.id
where u.website_service_id=#{websiteServiceId}
and t.stat_time =#{statTime}
GROUP BY t.web_id ORDER BY count desc limit 0,10
</select>
<!-- 根据主题分组获取子域名 -->
<!-- 根据主题分组获取子域名 -->
<select id="getDomainByTopicId" resultType="java.util.HashMap">
SELECT web_id webId,SUM(link_num) count
FROM galaxy.traffic_http_statistic t
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id=u.id
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id=u.id
where u.topic_id=#{topicId}
and t.stat_time = #{statTime}
GROUP BY t.web_id ORDER BY count desc limit 0,10
</select>
<!-- 指定网站下的TOP10之外为others -->
<!-- 指定网站下的TOP10之外为others -->
<select id="websiteDomainOthers" resultType="java.util.HashMap">
SELECT SUM(link_num) count FROM galaxy.traffic_http_statistic t
LEFT JOIN galaxy.ui_website_domain_topic u ON t.web_id=u.id
@@ -77,6 +81,6 @@
and t.web_id not in
<foreach collection="webIdList" item="singleType" index="index" open="(" close=")" separator=",">
#{singleType}
</foreach>
</foreach>
</if>
and stat_time =#{statTime}