I hope this is the right place to describe an issue we are having with the database scheme and the fix we have made for it. Could Drupal developers please comment?
In brief we should not allow multiple rows in profile_values which have the same (fid, uid), as this represents multiple values for a given profile field, which we believe to be wrong.
Background
We are using Drupal in an environment where we have approximately 2,500 users whose usernames, passwords, e-mail addresses etc are imported periodically from another system. As part of this we have some profile fields which describe the person (profile_fullname is one) and we have found a problem with the database definitions.
Details
Specifically, profile_values is defined as:
CREATE TABLE profile_values (
fid int(10) unsigned default '0',
uid int(10) unsigned default '0',
value text,
KEY uid (uid),
KEY fid (fid)
)
DEFAULT CHARACTER SET utf8;
We believe that we should change the last KEY
into
unique key fiduid (fid, uid)
We have done this post-hoc my adding an index
create unique index fiduid on profile_values(fid, uid);
Why was this a problem?
The reason we needed to make this change is because our user list is updated periodically by another script producing an SQL script which writes thousands of rows into profile_values table as follows: