Issue Details (XML | Word | Printable)

Key: MDL-17201
Type: Task Task
Status: Open Open
Priority: Major Major
Assignee: Eloy Lafuente (stronk7)
Reporter: Toni Mas
Votes: 6
Watchers: 6
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Add index on user_info_data

Created: 11/Nov/08 07:13 PM   Updated: 30/Sep/09 12:11 AM
Return to search
Component/s: Database SQL/XMLDB
Affects Version/s: 1.9.4, 2.0
Fix Version/s: None

File Attachments: 1. File MDL-17201.diff (1 kB)


Database: Any
Participants: Colin Campbell, Eloy Lafuente (stronk7), Justin Filip, Mine Karakaya, Toni Mas and Wen Hao Chuang
Security Level: None
Difficulty: Easy
Affected Branches: MOODLE_19_STABLE, MOODLE_20_STABLE


 Description  « Hide
Adding userid and fieldid key to increase the performence of SGBD.


 <KEY NAME="userid" TYPE="unique" FIELDS="userid" PREVIOUS="primary" NEXT="fieldid"/>
 <KEY NAME="fieldid" TYPE="unique" FIELDS="fieldid" PREVIOUS="userid"/>

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Mine Karakaya added a comment - 29/Mar/09 05:25 PM
Hi, I am planning to do XML admin settings project for my SOC. I have added a patch for this bug as attachment.

Mine Karakaya made changes - 29/Mar/09 05:25 PM
Field Original Value New Value
Attachment MDL-17201.diff [ 16704 ]
Colin Campbell added a comment - 07/Jun/09 01:02 AM
We were getting very poor performance on selects on user_info_data, so we definitely have a need for an index on the userid, but I am not sure what benefit the separate index on fieldid would provide. Do you have any queries in mind that you think the fieldid index would help? I am generally conservative about adding indexes, so if no specific benefit is expected, it should not be added.

Also, neither index as given in the description can be unique.

I added the following to my local/db/upgrade.php.

if ($result && $oldversion < 2009060600) { $table = new XMLDBTable('user_info_data'); $index = new XMLDBIndex('userid-fieldid'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid', 'fieldid')); $result = $result && add_index($table, $index); }

Note that this is an index on both userid and fieldid. Although the code for user_info_data inserts implies that the combination of userid and fieldid are unique, I chose not to add such a constraint myself because the benefit would not be great and I would run the risk of the moodle.org code later breaking on my constraint. If we can get this index on both columns added to the core, however, I suggest that it be added as a unique index.


Wen Hao Chuang added a comment - 11/Jun/09 05:29 AM
+1 for this. We found the same thing here at SFSU too.

Justin Filip added a comment - 30/Sep/09 12:11 AM
+1

At Remote Learner this problem was causing a database to completely lock up when using the browse users filters and including searching on a custom profile field.