From ea85d4303d9b58704ebdea5b88bbd0dbfd6ab30c Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 28 Oct 2010 11:56:37 +0000 Subject: [PATCH] Fixed #14231 -- Added an index to the expire_date column on the Session 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 --- django/contrib/sessions/models.py | 2 +- docs/releases/1.3.txt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/django/contrib/sessions/models.py b/django/contrib/sessions/models.py index 4c76ddf09a0..32cbc39451f 100644 --- a/django/contrib/sessions/models.py +++ b/django/contrib/sessions/models.py @@ -45,7 +45,7 @@ class Session(models.Model): session_key = models.CharField(_('session key'), max_length=40, primary_key=True) session_data = models.TextField(_('session data')) - expire_date = models.DateTimeField(_('expire date')) + expire_date = models.DateTimeField(_('expire date'), db_index=True) objects = SessionManager() class Meta: diff --git a/docs/releases/1.3.txt b/docs/releases/1.3.txt index 39037f423ca..da4eaf993db 100644 --- a/docs/releases/1.3.txt +++ b/docs/releases/1.3.txt @@ -165,6 +165,24 @@ To return to the previous rendering (without the ability to clear the model = Document widgets = {'document': forms.FileInput} +New index on database session table +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Prior to Django 1.3, the database table used by the database backend +for the :doc:`sessions ` app had no index on +the ``expire_date`` column. As a result, date-based queries on the +session table -- such as the query that is needed to purge old +sessions -- would be very slow if there were lots of sessions. + +If you have an existing project that is using the database session +backend, you don't have to do anything to accommodate this change. +However, you may get a significant performance boost if you manually +add the new index to the session table. The SQL that will add the +index can be found by running the :djadmin:`sqlindexes` admin +command:: + + python manage.py sqlindexes sessions + .. _deprecated-features-1.3: Features deprecated in 1.3