Created
June 6, 2012 08:23
-
-
Save svartalf/2880639 to your computer and use it in GitHub Desktop.
MySQL benchmark for database index on the Django' `auth_user.is_staff` field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> SELECT COUNT(*) FROM auth_user; | |
+----------+ | |
| COUNT(*) | | |
+----------+ | |
| 48158 | | |
+----------+ | |
1 row in set (0.00 sec) | |
mysql> EXPLAIN SELECT COUNT(*) FROM auth_user WHERE is_staff = 1; | |
+----+-------------+-----------+------+---------------+------+---------+------+-------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-----------+------+---------------+------+---------+------+-------+-------------+ | |
| 1 | SIMPLE | auth_user | ALL | NULL | NULL | NULL | NULL | 48199 | Using where | | |
+----+-------------+-----------+------+---------------+------+---------+------+-------+-------------+ | |
1 row in set (0.00 sec) | |
mysql> EXPLAIN SELECT COUNT(*) FROM auth_user WHERE is_staff = 0; | |
+----+-------------+-----------+------+---------------+------+---------+------+-------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-----------+------+---------------+------+---------+------+-------+-------------+ | |
| 1 | SIMPLE | auth_user | ALL | NULL | NULL | NULL | NULL | 48199 | Using where | | |
+----+-------------+-----------+------+---------------+------+---------+------+-------+-------------+ | |
mysql> ALTER TABLE auth_user ADD INDEX (is_staff); | |
Query OK, 0 rows affected (0.10 sec) | |
Records: 0 Duplicates: 0 Warnings: 0 | |
mysql> EXPLAIN SELECT COUNT(*) FROM auth_user WHERE is_staff = 0; | |
+----+-------------+-----------+------+---------------+----------+---------+-------+-------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-----------+------+---------------+----------+---------+-------+-------+-------------+ | |
| 1 | SIMPLE | auth_user | ref | is_staff | is_staff | 1 | const | 24099 | Using index | | |
+----+-------------+-----------+------+---------------+----------+---------+-------+-------+-------------+ | |
1 row in set (0.00 sec) | |
mysql> EXPLAIN SELECT COUNT(*) FROM auth_user WHERE is_staff = 1; | |
+----+-------------+-----------+------+---------------+----------+---------+-------+------+-------------+ | |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | |
+----+-------------+-----------+------+---------------+----------+---------+-------+------+-------------+ | |
| 1 | SIMPLE | auth_user | ref | is_staff | is_staff | 1 | const | 36 | Using index | | |
+----+-------------+-----------+------+---------------+----------+---------+-------+------+-------------+ | |
1 row in set (0.00 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment