gpt4 book ai didi

mysql - 提高这个慢查询的性能

转载 作者:行者123 更新时间:2023-11-29 22:11:41 25 4
gpt4 key购买 nike

我想调整此查询以获得更好的性能。

查询:

SELECT `DeviceRawUsage`.`duration`, `DeviceRawUsage`.`current` 
FROM `epowerg`.`device_raw_usages` AS `DeviceRawUsage`
WHERE `DeviceRawUsage`.`device_id` = 1 AND
`DeviceRawUsage`.`outlet_id` = 1 AND
`DeviceRawUsage`.`duration` >= '2015-06-01 00:00:00' AND
`DeviceRawUsage`.`duration` <= '2015-06-30 23:59:59';

最佳答案

CREATE TABLE `device_raw_usages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`device_id` int(11) DEFAULT NULL,
`outlet_id` int(11) NOT NULL,
`duration` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`current` float(11,4) DEFAULT NULL,
`voltage` float(11,4) NOT NULL,
`kw_used` float NOT NULL,
`outlet_total_kwh` float(11,4) DEFAULT NULL,
`outlet_kwh_demand_15` float(11,4) DEFAULT NULL,
`outlet_kw_demand_peak` float(11,4) DEFAULT NULL,
`submeter_real_kw` float(11,4) DEFAULT NULL,
`submeter_total_kwh` float(11,4) DEFAULT NULL,
`submeter_kwh_demand_15` float(11,4) DEFAULT NULL,
`submeter_kw_demand_peak` float(11,4) DEFAULT NULL,
`peak_voltage` float(11,2) DEFAULT NULL,
`peak_current` float(11,2) DEFAULT NULL,
`demand` float(11,2) DEFAULT NULL,
`inst_demand` float(11,2) DEFAULT NULL,
`hist_peek_demand` float(11,2) DEFAULT NULL,
`power_factor` float(11,2) DEFAULT NULL,
`crest_factor` float(11,2) DEFAULT NULL,
`frequency` varchar(20) DEFAULT NULL,
`app_power` float(11,2) DEFAULT NULL,
`tot_app_energy` float(11,2) DEFAULT NULL,
`tot_har_dist_vol` float(11,2) DEFAULT NULL,
`tot_har_dist_curr` float(11,2) DEFAULT NULL,
`har_x_dist_v` float(11,2) DEFAULT NULL,
`har_y_dist_v` float(11,2) DEFAULT NULL,
`har_z_dist_v` float(11,2) DEFAULT NULL,
`har_x_dist_c` float(11,2) DEFAULT NULL,
`har_y_dist_c` float(11,2) DEFAULT NULL,
`har_z_dist_c` float(11,2) DEFAULT NULL,
`interval` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1136511 DEFAULT CHARSET=latin1 |

关于mysql - 提高这个慢查询的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31583482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com