No indexes created for term_user table!

nicholasThompson - October 9, 2007 - 08:17
Project:User Tags
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

We have quite a lot of users and quite a lot of tags (abut 14,000 users + 150 tags)... This means the term_user table is going to get quite large. Even with only 60 or so rows, the table became VERY slow.

I took a look and found that there wasn't even a primary key!

The install file needs to have an update to add at least a join primary key on the uid and tid fields (this forces the combination of user and term to be unique). It would also be handy to have a separate index on the column which appears as the 2nd in the primary key pair.

This tiny addition to the table reduced one of my queries from 2.2s down to 0.07s!

#1

flk - October 9, 2007 - 09:09
Status:active» fixed

cheers, done

#2

Anonymous - October 23, 2007 - 09:44
Status:fixed» closed

#3

deekayen - May 13, 2008 - 19:18

Is there a particular reason the keys were put in the order they were (tid, uid)? cYu did some testing and found (uid, tid) made much faster queries in our case.

<?php
/**
* Implementation of hook_update_N().
*/
function user_tags_update_5000() {
 
$ret = array();
 
$ret[] = update_sql("ALTER TABLE {term_user} ADD PRIMARY KEY ('uid','tid')");
  return
$ret;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.