Drupal instance with over 5000 bean blocks and when a block is saved it calls block_flush_cache() which calls _block_rehash(). The query created by the _block_rehash() continues to show up in the mysqld-slow.log and may have been the catalyst for an outage.
As a result this patch transforms the query produced by the _block_rehash() function.
We’re changing the query from:
SELECT b.*
FROM
block b
WHERE (( (module = 'block')
AND (delta = '7') )OR( (module = 'webform')
AND (delta = 'client-block-268123') )OR( (module = 'webform')
AND (delta = 'client-block-268129') )OR( (module = 'webform')
AND (delta = 'client-block-292063') )OR( (module = 'apachesolr_search')
AND (delta = 'mlt-001') )OR( (module = 'apachesolr_search')
AND (delta = 'article_related_articles') )OR( (module = 'apachesolr_search')
AND (delta = 'topic_related_topics')
…
to:
SELECT b.*
FROM.
block b
WHERE (( (module = 'block')
AND (delta IN ('7')) )OR( (module = 'webform')
AND (delta IN ('client-block-268129', 'client-block-292063')) )OR( (module = 'apachesolr_search')
…
Comments
Comment #1
chaunceyt commentedComment #2
chaunceyt commentedThe initial patch wouldn't patch core via drush make. Re-did the patch.
Comment #3
dcam commentedThanks for your contribution! Just a couple of notes for the future:
1. Setting the issue status to Needs review will automatically trigger our Testbot to test any patches that you've submitted.
2. When you submit a patch for testing, make sure the Version is set to the current dev branch.
We'll see what Testbot says about your patch now.
Comment #4
bogdan1988 commentedHi, I've been enhancing performance of one of our sites with devel query log, and found that _block_rehash() provides heavy query. We are using beans on our website. There are 2100 beans in query. Before implementing patch query takes 112ms after applying patch 13.8ms. Most probably results are not very precise but it seems to me that it is very good performance raise.
Thank you
Comment #5
danepowell commentedWe've seen a significant performance boost as a result of this patch, on a site with ~10,000 bean blocks.
Although I would highly recommend anyone in this same situation also consider: #2577095: Move Block table integration to a submodule. Obviously it's only useful if you aren't already using beans as blocks.
Comment #6
David_Rothstein commentedCommitted to 7.x - thanks!