You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2018-02-15 16:11:45

Thalyn
Member
Registered: 2018-02-15
Posts: 1

Requête lente

Bonjour,

La requête ci-dessous est lente (Duration 5 sec environ / Fetch 57 sec environ) :

SELECT
glpi_computers.name,
glpi_computers.serial AS Serial,
CONVERT(glpi_computers.comment, CHAR (50)),
glpi_infocoms.warranty_date,
glpi_infocoms.warranty_duration
FROM glpi_computers
LEFT JOIN glpi_infocoms ON (glpi_computers.id = glpi_infocoms.items_id AND glpi_computers.entities_id = glpi_infocoms.entities_id)
WHERE glpi_computers.is_deleted = 0;


Pour information :

SELECT COUNT(*) from glpi_computers; >> 3275
SELECT COUNT(*) from glpi_infocoms; >> 99053

SHOW INDEX FROM glpi_infocoms;
# Table, Non_unique, Key_name, Seq_in_index, Column_name, Collation, Cardinality, Sub_part, Packed, Null, Index_type, Comment, Index_comment
'glpi_infocoms', '0', 'PRIMARY', '1', 'id', 'A', '99053', NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '0', 'unicity', '1', 'itemtype', 'A', NULL, NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '0', 'unicity', '2', 'items_id', 'A', '99053', NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '1', 'buy_date', '1', 'buy_date', 'A', '99053', NULL, NULL, 'YES', 'BTREE', '', ''
'glpi_infocoms', '1', 'alert', '1', 'alert', 'A', '1', NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '1', 'budgets_id', '1', 'budgets_id', 'A', '1', NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '1', 'suppliers_id', '1', 'suppliers_id', 'A', '4', NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '1', 'entities_id', '1', 'entities_id', 'A', '20', NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '1', 'is_recursive', '1', 'is_recursive', 'A', '1', NULL, NULL, '', 'BTREE', '', ''
'glpi_infocoms', '1', 'date_mod', '1', 'date_mod', 'A', '33017', NULL, NULL, 'YES', 'BTREE', '', ''
'glpi_infocoms', '1', 'date_creation', '1', 'date_creation', 'A', '49526', NULL, NULL, 'YES', 'BTREE', '', ''


EXPLAIN + requête;
# id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
'1', 'SIMPLE', 'glpi_computers', 'ref', 'is_deleted', 'is_deleted', '1', 'const', '2024', ''
'1', 'SIMPLE', 'glpi_infocoms', 'ref', 'entities_id', 'entities_id', '4', 'glpi.glpi_computers.entities_id', '4717', ''



Après analyse et dans le but d'optimiser ma requête, j'ajoute un index sur la table glpi_infocoms sur l'environnement de TEST :
ALTER TABLE glpi_infocoms ADD INDEX items_id (items_id);

Le SHOW INDEX m'affiche bien le nouvel index et l'EXPLAIN m'indique bien l'utilisation de celui-ci :
EXPLAIN + requête;
# id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
'1', 'SIMPLE', 'glpi_computers', 'ref', 'is_deleted', 'is_deleted', '1', 'const', '2024', ''
'1', 'SIMPLE', 'glpi_infocoms', 'ref', 'entities_id,items_id', 'items_id', '4', 'glpi.glpi_computers.id', '2', ''

L'exécution de ma requête est bien plus rapide suite à la modification : Duration 0 sec / Fetch 0.030 sec.


Mes questions sont les suivantes :
- l'ajout de cet index peut-il créer un effet de bord dans l'utilisation de GLPI ?
- peut-il avoir un impact lors d'une MAJ de GLPI ?
- faudra t-il ajouter l'index après chaque MAJ ?
- existe t-il un autre moyen d'améliorer le traitement de la requête sans toucher au fonctionnel ? (modification dans PHP, MySQL, autre ?)

Merci par avance pour votre aide.

Last edited by Thalyn (2018-02-15 16:14:58)

Offline

Board footer

Powered by FluxBB