With the current index, this needs to sort the results with filesort:
When we also add hit_count to the index, the filesort is not necessary anymore but filtering and sorting gets fully covered by the index:
This results in better performance.
There is no drawback for other queries which only filter by term_id as MySQL in this case can also use the index prefix (in this case only the column term_id).
Currently there is this index: https://github.com/teamtnt/tntsearch/blob/a763e66ca1bdebf1fab8f9ed10ec4bdbe2682bb0/src/Engines/MysqlEngine.php#L74
For retrieving all documents for a certain term the following query gets used: https://github.com/teamtnt/tntsearch/blob/a763e66ca1bdebf1fab8f9ed10ec4bdbe2682bb0/src/Engines/MysqlEngine.php#L385
With the current index, this needs to sort the results with
filesort
:When we also add
hit_count
to the index, thefilesort
is not necessary anymore but filtering and sorting gets fully covered by the index:This results in better performance.
There is no drawback for other queries which only filter by
term_id
as MySQL in this case can also use the index prefix (in this case only the columnterm_id
).