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

Đang mở Phù hợp với người mới
#1,310 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@marifex đang làm issue này rồi.

Từ ngày 21/10/2026.

  • #1312 của @marifex — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
mariadb, php
Lĩnh vực
database, performance

Hướng nghiên cứu

Bắt đầu bằng cách đọc PluginFieldsField::prepareHtmlFields() và PluginFieldsContainer::updateFieldsValues(), sau đó tìm các lời gọi getFromDBByCrit() khác được nhắc đến trong luồng lưu. Kiểm tra cách mỗi truy vấn lấy loại mục và so sánh kế hoạch truy vấn với ví dụ tái hiện EXPLAIN đã được báo cáo. Công việc hoàn tất khi các truy vấn này có thể sử dụng chỉ mục ghép hiện có và tránh được việc quét toàn bộ bảng lớn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
PHP
Star
122
Fork
85
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pluginsGLPI/fields

Tất cả issue của pluginsGLPI/fields

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.