code-dot-org/code-dot-org — pull request #672 by laurelfan (2014-12-04 22:40:21+00:00)
Title: fix user_script query

because:

````
mysql> explain UPDATE `user_scripts` SET `assigned_at` = '2014-12-04 22:02:16' WHERE ((`user_id` IN (SELECT `student_user_id` FROM `followers` WHERE (`section_id` = '135906'))) AND (`script_id` = 26));
+----+--------------------+--------------+----------------+------------------------------------------------------------------+------------------------------------+---------+------+---------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+--------------+----------------+------------------------------------------------------------------+------------------------------------+---------+------+---------+------------------------------+
| 1 | PRIMARY | user_scripts | index | NULL | PRIMARY | 4 | NULL | 2187913 | Using where; Using temporary |
| 2 | DEPENDENT SUBQUERY | followers | index_subquery | index_followers_on_student_user_id,index_followers_on_section_id | index_followers_on_student_user_id | 4 | func | 1 | Using where |
+----+--------------------+--------------+----------------+------------------------------------------------------------------+------------------------------------+---------+------+---------+------------------------------+
2 rows in set (0.00 sec)

mysql> explain UPDATE `user_scripts` SET `assigned_at` = '2014-12-04 22:02:16' WHERE id = 1111111111; +----+-------------+--------------+-------+---------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+-------+---------------+---------+---------+-------+------+-------------+
| 1 | SIMPLE | user_scripts | range | PRIMARY | PRIMARY | 4 | const | 1 | Using where |
+----+-------------+--------------+-------+---------------+---------+---------+-------+------+-------------+
1 row in set (0.00 sec)

mysql> explain select * from user_scripts where ((`user_id` IN (SELECT `student_user_id` FROM `followers` WHERE (`section_id` = '135906'))) AND (`script_id` = 26));
+----+-------------+--------------+--------+------------------------------------------------------------------+---------------------------------------------+---------+------------------------------------------------------+------+-----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+--------+------------------------------------------------------------------+---------------------------------------------+---------+------------------------------------------------------+------+-----------------+
| 1 | SIMPLE | followers | ref | index_followers_on_student_user_id,index_followers_on_section_id | index_followers_on_section_id | 5 | const | 30 | Start temporary |
| 1 | SIMPLE | user_scripts | eq_ref | index_user_scripts_on_user_id_and_script_id | index_user_scripts_on_user_id_and_script_id | 8 | dashboard_production.followers.student_user_id,const | 1 | End temporary |
+----+-------------+--------------+--------+------------------------------------------------------------------+---------------------------------------------+---------+------------------------------------------------------+------+-----------------+
2 rows in set (0.00 sec)
````