par
moogli » 22 nov. 2016, 12:35
salut,
il y a un index sur tnw_event_control_test_mark.event_control_test_id ? si ce n'est pas le cas c'est la première chose à faire.
idem pour les clefs étrangères.
si tu n'utilises pas les autres table c'est plus rapide ?
sinon il n'y a pas beaucoup d'axe d'amélioration.
C'est quoi le sgbd ?
avec oracle (et peut être postgresql) tu peux, peut être, voir avec la clause with pour limiter les enregistrements sur lequel tu travailles.
Dans tous les cas je dirais qu'il faut faire les jointures en dernier une fois que les données sont triées afin de limiter les calculs et le volume de données (la tu joins les tables et ensuite tu limites le jeux de données.
pour oracle je tenterais cela
WITH tnw_event AS
(SELECT tnw_event_control_test_mark.id,
tnw_event_control_test_mark.event_control_test_id,
tnw_event_control_test_mark.job_description_control_test_mark_id,
tnw_event_control_test_mark.checked,
tnw_event_control_test_mark.corrected,
tnw_event_control_test_mark.correction_date,
tnw_event_control_test_mark.comment
FROM tnw_event_control_test_mark
WHERE tnw_event_control_test_mark.event_control_test_id BETWEEN 3621 AND 3722
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 4081 AND 4475
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5199 AND 5657
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5952 AND 9623
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 9793 AND 9950
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 10808 AND 10935
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14686 AND 14896
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 19567 AND 19976
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14897 AND 15254
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 17139 AND 18358
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 18527 AND 18702
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 20365 AND 21293
)
SELECT tnw_event.id,
tnw_event.event_control_test_id,
tnw_event.job_description_control_test_mark_id,
tnw_event.checked,
tnw_event.corrected,
tnw_event.correction_date,
tnw_event.comment,
tnw_room_control_test_mark.coefficient,
tnw_room_control_test_mark.position,
tnw_control_test_mark.name
FROM tnw_event
LEFT JOIN tnw_job_description_control_test_mark
ON tnw_event.job_description_control_test_mark_id = tnw_job_description_control_test_mark.id
LEFT JOIN tnw_room_control_test_mark
ON tnw_job_description_control_test_mark.room_control_test_mark_id = tnw_room_control_test_mark.id
LEFT JOIN tnw_control_test_mark
ON tnw_room_control_test_mark.control_test_mark_id = tnw_control_test_mark.id
ORDER BY tnw_room_control_test_mark.position ASC;
pour mysql
SELECT tnw_event.id,
tnw_event.event_control_test_id,
tnw_event.job_description_control_test_mark_id,
tnw_event.checked,
tnw_event.corrected,
tnw_event.correction_date,
tnw_event.comment,
tnw_room_control_test_mark.coefficient,
tnw_room_control_test_mark.position,
tnw_control_test_mark.name
FROM
(SELECT tnw_event_control_test_mark.id,
tnw_event_control_test_mark.event_control_test_id,
tnw_event_control_test_mark.job_description_control_test_mark_id,
tnw_event_control_test_mark.checked,
tnw_event_control_test_mark.corrected,
tnw_event_control_test_mark.correction_date,
tnw_event_control_test_mark.comment
FROM tnw_event_control_test_mark
WHERE tnw_event_control_test_mark.event_control_test_id BETWEEN 3621 AND 3722
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 4081 AND 4475
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5199 AND 5657
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5952 AND 9623
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 9793 AND 9950
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 10808 AND 10935
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14686 AND 14896
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 19567 AND 19976
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14897 AND 15254
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 17139 AND 18358
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 18527 AND 18702
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 20365 AND 21293
) tnw_event
LEFT JOIN tnw_job_description_control_test_mark
ON tnw_event.job_description_control_test_mark_id = tnw_job_description_control_test_mark.id
LEFT JOIN tnw_room_control_test_mark
ON tnw_job_description_control_test_mark.room_control_test_mark_id = tnw_room_control_test_mark.id
LEFT JOIN tnw_control_test_mark
ON tnw_room_control_test_mark.control_test_mark_id = tnw_control_test_mark.id
ORDER BY tnw_room_control_test_mark.position ASC;
bien entendu l'index sur la colonne event_control_test_id est obligatoire pour aider la chose
@+
salut,
il y a un index sur tnw_event_control_test_mark.event_control_test_id ? si ce n'est pas le cas c'est la première chose à faire.
idem pour les clefs étrangères.
si tu n'utilises pas les autres table c'est plus rapide ?
sinon il n'y a pas beaucoup d'axe d'amélioration.
C'est quoi le sgbd ?
avec oracle (et peut être postgresql) tu peux, peut être, voir avec la clause with pour limiter les enregistrements sur lequel tu travailles.
Dans tous les cas je dirais qu'il faut faire les jointures en dernier une fois que les données sont triées afin de limiter les calculs et le volume de données (la tu joins les tables et ensuite tu limites le jeux de données.
pour oracle je tenterais cela
[sql]WITH tnw_event AS
(SELECT tnw_event_control_test_mark.id,
tnw_event_control_test_mark.event_control_test_id,
tnw_event_control_test_mark.job_description_control_test_mark_id,
tnw_event_control_test_mark.checked,
tnw_event_control_test_mark.corrected,
tnw_event_control_test_mark.correction_date,
tnw_event_control_test_mark.comment
FROM tnw_event_control_test_mark
WHERE tnw_event_control_test_mark.event_control_test_id BETWEEN 3621 AND 3722
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 4081 AND 4475
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5199 AND 5657
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5952 AND 9623
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 9793 AND 9950
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 10808 AND 10935
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14686 AND 14896
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 19567 AND 19976
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14897 AND 15254
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 17139 AND 18358
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 18527 AND 18702
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 20365 AND 21293
)
SELECT tnw_event.id,
tnw_event.event_control_test_id,
tnw_event.job_description_control_test_mark_id,
tnw_event.checked,
tnw_event.corrected,
tnw_event.correction_date,
tnw_event.comment,
tnw_room_control_test_mark.coefficient,
tnw_room_control_test_mark.position,
tnw_control_test_mark.name
FROM tnw_event
LEFT JOIN tnw_job_description_control_test_mark
ON tnw_event.job_description_control_test_mark_id = tnw_job_description_control_test_mark.id
LEFT JOIN tnw_room_control_test_mark
ON tnw_job_description_control_test_mark.room_control_test_mark_id = tnw_room_control_test_mark.id
LEFT JOIN tnw_control_test_mark
ON tnw_room_control_test_mark.control_test_mark_id = tnw_control_test_mark.id
ORDER BY tnw_room_control_test_mark.position ASC;[/sql]
pour mysql
[sql]SELECT tnw_event.id,
tnw_event.event_control_test_id,
tnw_event.job_description_control_test_mark_id,
tnw_event.checked,
tnw_event.corrected,
tnw_event.correction_date,
tnw_event.comment,
tnw_room_control_test_mark.coefficient,
tnw_room_control_test_mark.position,
tnw_control_test_mark.name
FROM
(SELECT tnw_event_control_test_mark.id,
tnw_event_control_test_mark.event_control_test_id,
tnw_event_control_test_mark.job_description_control_test_mark_id,
tnw_event_control_test_mark.checked,
tnw_event_control_test_mark.corrected,
tnw_event_control_test_mark.correction_date,
tnw_event_control_test_mark.comment
FROM tnw_event_control_test_mark
WHERE tnw_event_control_test_mark.event_control_test_id BETWEEN 3621 AND 3722
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 4081 AND 4475
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5199 AND 5657
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 5952 AND 9623
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 9793 AND 9950
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 10808 AND 10935
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14686 AND 14896
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 19567 AND 19976
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 14897 AND 15254
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 17139 AND 18358
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 18527 AND 18702
OR tnw_event_control_test_mark.event_control_test_id BETWEEN 20365 AND 21293
) tnw_event
LEFT JOIN tnw_job_description_control_test_mark
ON tnw_event.job_description_control_test_mark_id = tnw_job_description_control_test_mark.id
LEFT JOIN tnw_room_control_test_mark
ON tnw_job_description_control_test_mark.room_control_test_mark_id = tnw_room_control_test_mark.id
LEFT JOIN tnw_control_test_mark
ON tnw_room_control_test_mark.control_test_mark_id = tnw_control_test_mark.id
ORDER BY tnw_room_control_test_mark.position ASC;[/sql]
bien entendu l'index sur la colonne event_control_test_id est obligatoire pour aider la chose ;)
@+