Value lookups by items_id do not use the itemtype index and scan the whole values table

Aperta Adatta ai principianti
#1,310 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@marifex ci sta già lavorando.

Dal 21/10/2026.

  • #1312 di @marifex — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
mariadb, php

Direzione di ricerca

Inizia leggendo PluginFieldsField::prepareHtmlFields() e PluginFieldsContainer::updateFieldsValues(), poi individua le altre chiamate a getFromDBByCrit() menzionate nel percorso di salvataggio. Verifica come ogni query ottiene il tipo di elemento e confronta il piano di query con la riproduzione EXPLAIN segnalata. Il lavoro è completato quando queste query possono usare l’indice composito esistente e viene evitata la scansione completa della tabella grande.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Stale
GLPI Version

11.0.11

Plugin version

1.24.6. The same code is in 1.25.0 and on main.

Bug description

The values table of each container (for example glpi_plugin_fields_ticketticketdetails) has the unique index itemtype_item_container (itemtype, items_id, plugin_fields_containers_id) and no other index on items_id. Several lookups filter on items_id without itemtype, so the index cannot be used and every call reads the whole table:

  • PluginFieldsField::prepareHtmlFields(), $obj->find(['plugin_fields_containers_id' => ..., 'items_id' => ...]), run on every display of an item that has a container.
  • PluginFieldsContainer, getFromDBByCrit(['items_id' => $items_id]) in the save path (4 places, for example in updateFieldsValues()).

With 500,000 tickets and about 290,000 rows in the ticket container table, the first query read about 290,000 rows per call and took 156 ms on average at low load. Under heavy load the average rose to between 3.2 and 5.1 s per call. It was the fourth most expensive statement on the server at low load, and opening a ticket was slowed down by it.

Relevant log output
calls | total ms | avg ms | rows examined | no index | statement
268   | 41881    | 156.3  | 77890984      | 268      | SELECT * FROM `glpi_plugin_fields_ticketticketdetails` WHERE `plugin_fields_containers_id` = ? AND `items_id` = ?
430   | 745460   | 1733.6 | 124974340     | 430      | SELECT `id` FROM `glpi_plugin_fields_ticketticketdetails` WHERE `items_id` = ?

(performance_schema statement digests; the second line is from a step under heavy load)

Steps To reproduce
  1. Create a container on tickets with a few fields.
  2. Have a large number of tickets with values in it (hundreds of thousands).
  3. Open a ticket and run EXPLAIN SELECT * FROM glpi_plugin_fields_ticketticketdetails WHERE plugin_fields_containers_id = 1 AND items_id = 12345;

Expected: the lookup uses the unique index.

Actual: no index is used and the whole table is read.

Your GLPI setup information

Docker, PHP 8.x with Apache prefork, MariaDB 10.11 with an 8 GB buffer pool.

Anything else?

Each values table holds a single itemtype, so adding 'itemtype' => $item->getType() (or the known itemtype) to these criteria lets the existing unique index be used. An index on items_id would also work.

Lingua principale
PHP
Stelle
122
Fork
85
Merge medio
1g 15h
PR unite (30g)
20

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pluginsGLPI/fields

Tutte le issue di pluginsGLPI/fields

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.