Ceci est SQL:optimize table mysql, deux colonnes avec datetime comparer
SELECT
f_collect_time
FROM
t_ov_meterorigvalue_a98ea7cee0b1111e48e0800163e002d36 a98ea7cee0b1111e48e0800163e002d36
WHERE
f_collect_time < '2017-05-05 00:00:00'
AND f_meter_id = 320679
ORDER BY
f_collect_time DESC,
f_meter_id
LIMIT 1
mon temps de recherche est 38S +
lignes de table est 19093806
the index of my table is below:
the fields of my table is below
afficher montrer le résultat du tableau:
CREATE TABLE `t_ov_meterorigvalue_a98ea7cee0b1111e48e0800163e002d36` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`calc_time` datetime DEFAULT NULL,
`f_coding` varchar(30) DEFAULT NULL,
`f_collect_time` datetime DEFAULT NULL,
`f_data` double DEFAULT NULL,
`f_data_collection_info_id` int(11) DEFAULT NULL,
`f_orig_value` varchar(50) DEFAULT NULL,
`f_orig_valueid` varchar(32) DEFAULT NULL,
`rate` double DEFAULT NULL,
`receive_time` datetime DEFAULT NULL,
`f_state` varchar(1) DEFAULT '0',
`f_build_id` int(11) DEFAULT NULL,
`f_meter_id` int(11) DEFAULT NULL,
`f_meter_change_id` int(11) DEFAULT NULL,
`f_meter_param_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `buildid_collecttime` (`f_build_id`,`f_collect_time`),
KEY `meterid_collecttime_asc` (`f_collect_time`,`f_meter_id`,`f_meter_param_id`),
KEY `meterid_collecttime_desc` (`f_collect_time`,`f_meter_id`,`f_meter_param_id`),
KEY `meterid_meterparamid` (`f_meter_id`,`f_meter_param_id`),
KEY `f_meter_id` (`f_collect_time`,`f_meter_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=19152255 DEFAULT CHARSET=utf8
s'il vous plaît aidez-moi, comment puis-je optimiser cette terrible requête
Le moteur de table mysql est innodb, le format des lignes est compact. – simpleman
Pourriez-vous éventuellement ajouter une sortie EXPLAIN de cette requête? –
Il n'y a pas de "meter_id" dans le lien du schéma que vous avez fourni! –