Database attachments query slow (System Files) #208
-
So, I have almost 2 million records in my Is there a way to better optimize the indexes or something? Because I noticed it is only using the system_files_field_index and MySQL still ends up needing to filter through 908975 rows Here's the query that is generated by Laravel: select *
from `system_files`
where `system_files`.`attachment_id` = 100962
and `system_files`.`attachment_type` = 'Mrelevance\RealEstate\Models\Listing'
and `field` = 'images'
order by `sort_order` ASC Here's the SQL EXPLAIN output:
It seems like generating a compound index definitely helps speed up the query, but still isn't as fast as I would like: create index system_files_field_attachment_type_attachment_id_index
on system_files (field, attachment_type, attachment_id); EDIT: create index system_files_index
on system_files (field, sort_order, attachment_type, attachment_id); Any ideas on how to further optimize this? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I think a big part of the problem for system_files performance with large number of records is the fact that the attachment_id column is a VARCHAR instead of an unsigned integer in order to support records with string keys, so you could try changing the column type. |
Beta Was this translation helpful? Give feedback.
I think a big part of the problem for system_files performance with large number of records is the fact that the attachment_id column is a VARCHAR instead of an unsigned integer in order to support records with string keys, so you could try changing the column type.