Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14231 -- Added an index to the expire_date column on the Sessi…

…on model. Thanks to joeri for the report, via Frodo from Medid.

This won't affect any existing session tables; see the release notes for migration instructions.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14378 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ea85d4303d9b58704ebdea5b88bbd0dbfd6ab30c 1 parent 90ac023
Russell Keith-Magee authored October 28, 2010
2  django/contrib/sessions/models.py
@@ -45,7 +45,7 @@ class Session(models.Model):
45 45
     session_key = models.CharField(_('session key'), max_length=40,
46 46
                                    primary_key=True)
47 47
     session_data = models.TextField(_('session data'))
48  
-    expire_date = models.DateTimeField(_('expire date'))
  48
+    expire_date = models.DateTimeField(_('expire date'), db_index=True)
49 49
     objects = SessionManager()
50 50
 
51 51
     class Meta:
18  docs/releases/1.3.txt
@@ -165,6 +165,24 @@ To return to the previous rendering (without the ability to clear the
165 165
             model = Document
166 166
             widgets = {'document': forms.FileInput}
167 167
 
  168
+New index on database session table
  169
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170
+
  171
+Prior to Django 1.3, the database table used by the database backend
  172
+for the :doc:`sessions </topics/http/sessions>` app had no index on
  173
+the ``expire_date`` column. As a result, date-based queries on the
  174
+session table -- such as the query that is needed to purge old
  175
+sessions -- would be very slow if there were lots of sessions.
  176
+
  177
+If you have an existing project that is using the database session
  178
+backend, you don't have to do anything to accommodate this change.
  179
+However, you may get a significant performance boost if you manually
  180
+add the new index to the session table. The SQL that will add the
  181
+index can be found by running the :djadmin:`sqlindexes` admin
  182
+command::
  183
+
  184
+    python manage.py sqlindexes sessions
  185
+
168 186
 .. _deprecated-features-1.3:
169 187
 
170 188
 Features deprecated in 1.3

0 notes on commit ea85d43

Please sign in to comment.
Something went wrong with that request. Please try again.