This is a Magento bug, which has been around since Magento 1.7.
When reindexing the catalogsearch_fulltext index, a transaction is started which does the following, for each store in succession:
- Rebuild the
catalogsearch_fulltext
table
- Reset search results: update the
catalogsearch_query
table (set is_processed to 0) and clear the catalogsearch_result
table
From the moment when the catalogsearch_query
query is executed, all searches in the frontend should wait until the complete indexing process has finished (they also cause writes to the catalogsearch_query
and catalogsearch_result
tables). For a large catalog with multiple store views, this can take quite a while, resulting in a "lock wait timeout exceeded" error.
I have reported this to Magento via the Bug tracker: http://www.magentocommerce.com/bug-tracking/issue/index/id/933
I think it shouldn't be necessary to store search results in the database; instead, they should be stored in the registry, such that they can be referenced multiple times during a single request. Then it isn't necessary anymore to reset search results during reindexing. Also, the need for a transaction disappears.
I did not implement this solution, as we mostly use ElasticSearch nowadays.