I've been optimising MySQL on a server that is only running one Drupal site. Accordingly, I've been able to pick up when mysqltuner flags that there are queries running that do not have indices on columns that are JOINed.

One query that I was seeing in my logs is this one:

SELECT twitter.twitter_id AS twitter_id, twitter_account.followers_count AS twitter_account_followers_count, twitter_account.name AS twitter_account_name, twitter_account.screen_name AS twitter_account_screen_name, twitter.created_time AS twitter_created_time FROM twitter twitter
LEFT JOIN twitter_account twitter_account ON twitter.screen_name = twitter_account.screen_name
WHERE (( (twitter_account.protected = '0') )) ORDER BY twitter_created_time DESC

Both columns in the JOIN seemed to be indexed already. But the sort on twitter_created_time was not on an indexed column. That query was generated from the Views component that displays the recent tweets.So adding an index to twitter.created_time would help that query to run more efficiently.

I'm happy to write a patch that adds an _update_70xx function to the install file which adds the index. But I haven't time at the moment - so I thought I'd create an issue anyway. Since adding the index, this query has dropped out of my logs, so I'm in danger of forgetting my discovery that this column needs indexing. And, who knows, someone else may find time to write the patch before I get to it.

Comments

damienmckenna’s picture

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new909 bytes

This adds an index on that field.

damienmckenna’s picture

Version: 7.x-5.x-dev » 6.x-5.x-dev
StatusFileSize
new782 bytes

Ported to 6.x-5.x.

damienmckenna’s picture

Version: 6.x-5.x-dev » 7.x-6.x-dev
StatusFileSize
new858 bytes

Ported to 7.x-6.x.

Status: Needs review » Needs work

The last submitted patch, 4: twitter-n2214867-4-7.x-6.x.patch, failed testing.

  • DamienMcKenna committed 8f8c093 on 7.x-5.x
    Issue #2214867 by DamienMcKenna: Added index on {twitter}.created_time.
    

  • DamienMcKenna committed 689461e on 6.x-5.x
    Issue #2214867 by DamienMcKenna: Added index on {twitter}.created_time.
    
damienmckenna’s picture

Status: Needs work » Fixed

Committed.

  • DamienMcKenna committed b8dca79 on 7.x-6.x
    Issue #2214867 by DamienMcKenna: Added index on {twitter}.created_time.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.