1
완료하려면 3 초가 걸리는이 선택 요청의 실행 시간을 개선하려고합니다. Mesure_capteur 테이블에는 2 백만 개의 행과 Capteur 400이 있습니다. Capteur.nom_capteur 및 Mesure_Capteur.id_capteur에 대한 인덱스를 추가했습니다. 이 작업을 수행하기까지는 10 초가 걸렸지 만 이후에해야 할 일을 알고 있습니다. 당신의 도움에 대한postgre SQL select 요청 실행 시간 개선
'Sort (cost=352931.30..352931.30 rows=1 width=25) (actual time=3147.592..3147.625 rows=494 loops=1)'
' Sort Key: mc.horodateur DESC'
' Sort Method: quicksort Memory: 51kB'
' -> Nested Loop (cost=3361.03..352931.29 rows=1 width=25) (actual time=1485.653..3147.419 rows=494 loops=1)'
' -> Index Scan using capteur_nom_capteur_index on capteur c (cost=0.27..8.29 rows=1 width=22) (actual time=0.045..0.047 rows=1 loops=1)'
' Index Cond: ((nom_capteur)::text = 'ENEEANABatterie005'::text)'
' -> Bitmap Heap Scan on mesure_capteur mc (cost=3360.76..352922.99 rows=1 width=11) (actual time=1485.598..3147.304 rows=494 loops=1)'
' Recheck Cond: (id_capteur = c.id_capteur)'
' Rows Removed by Index Recheck: 17942069'
' Filter: ((horodateur >= '2017-10-15 00:00:00+02'::abstime) AND (horodateur <= '2017-10-15 01:00:00+02'::abstime))'
' Rows Removed by Filter: 181360'
' Heap Blocks: exact=45030 lossy=99772'
' -> Bitmap Index Scan on mesure_capteur_id_capteur_index (cost=0.00..3360.76 rows=181359 width=0) (actual time=63.333..63.333 rows=181854 loops=1)'
' Index Cond: (id_capteur = c.id_capteur)'
'Planning time: 0.367 ms'
'Execution time: 3148.039 ms'
감사 :
create table Mesure_capteur(
id_mesure_capteur serial PRIMARY KEY,
valeur_mesure_capteur NUMERIC(20,2),
id_capteur int,
FOREIGN KEY (id_capteur) REFERENCES Capteur(id_capteur),
horodateur abstime
);
여기에 분석 설명을의 -
create table Capteur(
id_capteur int primary key,
nom_capteur varchar(180),
description_capteur varchar(100),
id_sous_systeme int,
description_unite varchar(50),
unite varchar(10),
seuil_min real,
seuil_max real,
FOREIGN KEY (id_sous_systeme) REFERENCES Sous_systeme(id_sous_systeme)
);
가 : 여기
SELECT C.nom_capteur, mC.horodateur, mC.valeur_mesure_capteur
FROM Mesure_Capteur mC INNER JOIN Capteur C
ON mC.id_capteur = C.id_capteur
WHERE C.nom_capteur = 'ENEEANABatterie005'
AND mC.horodateur between '2017-10-15 00:00:00' and '2017-10-15 01:00:00'
ORDER BY mC.horodateur DESC
내 두 테이블입니다. 이 쿼리
대단히 감사합니다. 실행 시간은 이제 ~ 15ms입니다. 인덱스가있는 실행 시간을 향상시키는 방법을 배울 수있는 좋은 링크가 있습니까 (시간이있을 때 읽으려는 경우). 삽입 요청의 실행 시간이 많이 걸리는가? 나는 ~ 400row/s를 Mesure_capteur 테이블에 삽입한다. –
@JoelMP. . . 나는 주제 (https://dev.mysql.com/doc/refman/5.7/en/multiple-column-indexes.html)에 MySQL 설명서를 실제로 좋아한다. 인덱스는 데이터베이스마다 다르지만 기본 사항은 매우 유사합니다. –