Changes between Version 1 and Version 2 of Ticket #25399
- Timestamp:
- Sep 14, 2015, 5:46:17 AM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #25399
- Property Resolution → invalid
- Property Status new → closed
- Property Version 1.8 → master
-
Ticket #25399 – Description
v1 v2 1 1 Having a user database table with millions of entries, even a simple look-up by username (or email address) takes a rather long time and causes a significant overhead on servers. For example, the Django database query for a user signing in looks roughly like this: 2 3 4 2 {{{ 3 SELECT * FROM "accounts_user" WHERE UPPER("accounts_user"."email"::text) = UPPER('foo@bar.com') 4 }}} 5 5 The problem is, without a database index, the string transformation and comparison takes a lot of resources and even with a powerful infrastructure, such a query may take over a second when having a million or more users. With the growing user base, the query gets slower an slower. 6 6 7 7 By adding a database index, the process takes only about a microsecond. Using PostgreSQL, we've simply added the index manually, which works fine: 8 9 10 8 {{{ 9 CREATE INDEX accounts_user_username_upper ON accounts_user (UPPER(username)); 10 }}} 11 11 Yet, this is a crucial part of most web applications and therefore, it would probably make sense if Django created the index automatically for the integrated User and AbstractUser classes. Or at least, the issue could be pointed out clearly in the docs.