Avoid subqueries when purging the search index (see #7201)