java mysql max_Complex Max Statement MySQL

I've a single query to get 10 Maximum value from MySQL database. It's returned a correct value, but the problem is, it took long time to get the value

This value is CPU data from a device. So, from a single device have about 6 Module Type. From each Module Type have about 120 Module Number. From each Module Number have 2 Slot (active and standby). Module Number places in a subrack. I need to get 10 Module Number which has highest value.

I've tried using my own query, it returned correct value, but the slot is incorrect. Then I found a query from stack overflow (MySQL query, MAX() + GROUP BY)

This is my table structure :

Create Table: CREATE TABLE `Router_Modul_CPU` (

`date_id` date NOT NULL,

`hour_id` time NOT NULL,

`NE` varchar(50) NOT NULL,

`modul_number` int(11) NOT NULL,

`modul_type` varchar(50) NOT NULL,

`slot` int(11) NOT NULL,

`subrack` int(11) DEFAULT NULL,

`mean_memory` float DEFAULT NULL,

`peak_memory` float DEFAULT NULL,

PRIMARY KEY (`date_id`,`hour_id`,`NE`,`modul_number`,`modul_type`,`slot`),

KEY `index_key` (`date_id`,`hour_id`,`NE`,`modul_number`,`modul_type`,`slot`,`subrack`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1

This is my query :

select

Router_Modul_CPU.NE,

Router_Modul_CPU.modul_number,

Router_Modul_CPU.slot,

Router_Modul_CPU.subrack

from Router_Modul_CPU

inner join

(

select modul_number, max(peak_memory) as maks

from `Router_Modul_CPU`

group by modul_number, NE, subrack

) maxt on

(Router_Modul_CPU.modul_number = maxt.modul_number and

Router_Modul_CPU.peak_memory = maxt.maks)

where modul_type='SPU' and NE='R-D5-SBT' and date_id='2019-02-14'

limit 10

It took about 40-50 seconds to get the data, and those query only for one device

All this data were inserted every 5 minutes to this table. Now this table have about 25 million row.

Is there any tuning to my table or any suggestion for my query to make more efficient?

Thanks

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值