After tried testing restore your backup files with 2000 users, It took over 70000 queries !!
I'm running Moodle 1.9 and I've focused on reducing queries of restoring backup to existing moodle (users already exist). I tracked the queries in restore_create_users function (in backup/restorelib.php). This function alone took around 26000 queries. I found these queries are executed for every user added. a total of 13 queries/user.
1 Query SELECT * FROM mdl_backup_ids WHERE backup_code = '1201177218'
AND table_name = 'user' AND old_id = '1014' LIMIT 1
1 Query DELETE FROM mdl_backup_ids
WHERE backup_code = 1201177218 AND
table_name = 'user' AND
old_id = '1014'
1 Query INSERT INTO mdl_backup_ids ( BACKUP_CODE, TABLE_NAME, OLD_ID,
NEW_ID, INFO ) VALUES ( 1201177218, 'user', 1014, 0, 'infile' )
Above queries I thought It can't be reduced, so take a look at these
1 SELECT * FROM mdl_backup_ids WHERE backup_code = '1201177218' AND table_name =
'user' AND old_id = '1015' LIMIT 1
2 SELECT * FROM mdl_user WHERE username = 'firstname1013' AND mnethostid = '1' LIMIT 1
3 DELETE FROM mdl_backup_ids
WHERE backup_code = 1201177218 AND
table_name = 'user' AND
old_id = '1015'
4 INSERT INTO mdl_backup_ids ( BACKUP_CODE, TABLE_NAME, OLD_ID, NEW_ID, INFO )
VALUES ( 1201177218, 'user', 1015, 26, 's:6:"exists";' )
5 SELECT * FROM mdl_backup_ids WHERE backup_code = '1201177218' AND table_name =
'user' AND old_id = '1015' LIMIT 1
6 DELETE FROM mdl_backup_ids
WHERE backup_code = 1201177218 AND
table_name = 'user' AND
old_id = '1015'
7 INSERT INTO mdl_backup_ids ( BACKUP_CODE, TABLE_NAME, OLD_ID, NEW_ID, INFO )
VALUES ( 1201177218, 'user', 1015, 26, 's:14:"exists,needed,";' )
8 SELECT * FROM mdl_backup_ids WHERE backup_code = '1201177218' AND table_name =
'user' AND old_id = '1015' LIMIT 1
9 SELECT * FROM mdl_user_preferences WHERE userid = '26' AND name =
'auth_forcepasswordchange' LIMIT 1
10 SELECT * FROM mdl_user_preferences WHERE userid = '26' AND name =
'create_password' LIMIT 1
Restoring to a new, never-contain-existing-user-before database cost 19 queries/user. But restoring to an existing database (which already contained user) sill cost 13 queries/user.
Line 5-7 will be execute if $create_roles flagged as true. and Line 8-10 will be executed if $create_preference flagged as true.
But If we can know early that roles/preferences we're going to insert is the same as roles/preferences exist. We can reduce this 6 queries/user to something less.
I made a restorelib.php with a modified restore_create_users() function. I just to set $create_role and $create_preference to false if $create_user is false (line 2271 to 2275). However this can't be used since I can't just set those flag to false if $create_user is false. In case that there's already a user exist, the user might has some special preferences or roles assigned after the current database (and need to be inserted though it's already exist).
You may check out a discussion about this at http://code.google.com/p/google-highly-open-participation-moodle/issues/detail?id=104
Attaching a backup file with 2000 users assigned as students to it (and default blocks).
To restore this course takes 56K queries.