Closed dfabulich closed 6 months ago
Two options:
(title, author, desc, tags)
fulltext index to search more than we need, but still filter the results for the LIKE
to run on less records. (Assuming the execution plan selects the fulltext index.)Here's the second approach. Explain says it's using the index, but I didn't measure if it's actually faster: https://github.com/iftechfoundation/ifdb/compare/main...salty-horse:ifdb:author_search_optimization?expand=1
Even though we have a new fulltext index for the author
column, the query still isn't using it, because it still has the RLIKE
clause.
select sql_calc_found_rows
games.id as id,
games.title as title,
games.author as author,
games.tags as tags,
games.moddate as moddate,
games.system as devsys,
if (time(games.published) = '00:00:00',
date_format(games.published, '%Y'),
date_format(games.published, '%M %e, %Y'))
as pubfmt,
if (time(games.published) = '00:00:00',
date_format(games.published, '%Y'),
date_format(games.published, '%Y-%m-%d'))
as published,
date_format(games.published, '%Y') as pubyear,
(games.coverart is not null) as hasart,
avgRating as avgrating,
numRatingsInAvg as ratingcnt,
stdDevRating as ratingdev,
numRatingsTotal,
numMemberReviews,
games.sort_title as sort_title,
games.sort_author as sort_author,
ifnull(games.published, '9999-12-31') as sort_pub,
games.flags
from
games
left join gameRatingsSandbox0_mv on games.id = gameid
where
( match (author) against ('Gray Manichean') or author rlike '[[:<:]]G.*[[:space:]]+Manichean[[:>:]]')
order by
starsort desc
limit 0, 20;
Analyze says it's doing a full table scan:
+------+-------------+------------------------+--------+---------------+---------+---------+---------------+-------+----------+----------+------------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | r_rows | filtered | r_filtered | Extra |
+------+-------------+------------------------+--------+---------------+---------+---------+---------------+-------+----------+----------+------------+----------------------------------------------+
| 1 | SIMPLE | games | ALL | NULL | NULL | NULL | NULL | 12987 | 12987.00 | 100.00 | 0.12 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | gameRatingsSandbox0_mv | eq_ref | PRIMARY | PRIMARY | 34 | ifdb.games.id | 1 | 0.56 | 100.00 | 100.00 | |
+------+-------------+------------------------+--------+---------------+---------+---------+---------------+-------+----------+----------+------------+----------------------------------------------+
But ever since we rolled out our other changes, this query hasn't show up in the slow query log, so it may not be such a big deal any more.
Furthermore, https://github.com/iftechfoundation/ifdb/pull/277 appears to have caused https://github.com/iftechfoundation/ifdb-suggestion-tracker/issues/436 so I'm going to roll it back.
I'm not sure what we could do about this… Some kinda full-text search index?