This is very borderline, since the slow query is from privatemsg_index, I'd be fine moving the issue over there but I'm not sure if there are any remotely similar queries elsewhere that might benefit.


  $query  = 'SELECT DISTINCT(pmi.thread_id) FROM {pm_index} pmi';
  $query .=  ' WHERE pmi.mid IN (' . db_placeholders($mids) . ')'; 

This creates a very big temporary table and scans hundreds of thousands of rows on the site I'm working on.

If you do ALTER TABLE pm_index ADD index mid_thread_id (mid, thread_id); then it's able to use the index on thread_id and only needs to scan four rows.

I'll do a patch for this if it seems worth adding just in case, if not happy to have this moved to privatemsg_views which could hook_schema_alter() / db_add_index() it in itself.

Comments

berdir’s picture

Hm.

Are you sure this is 6.x-2.x? Because privatemsg_views is only compatible with 6.x-1.x.

Unless there are any queries in privatemsg which would be improved too (and I am not aware of any), I'm not sure about adding this. We already have multiple indexes on that table and adding more means slower inserts/updates...

catch’s picture

Project: Privatemsg » Privatemsg Views
Version: 6.x-2.x-dev » 6.x-1.x-dev

That's fair enough, moving to privatemsg_views.