From: Stewart Smith Date: Fri, 10 Aug 2018 08:01:03 +0000 (+1000) Subject: Add covering index to patchwork_submissions for /list/ queries X-Git-Tag: v2.2.0-rc1~294 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=332956146469575c3ceeb3ecd94c7459e1e3dbea;p=thirdparty%2Fpatchwork.git Add covering index to patchwork_submissions for /list/ queries This gets PostgreSQL to generate *much* better query plans, gaining us about two orders of magnitude in performance on the /list/ query for the worst state project on the patchwork.ozlabs.org instance (qemu-devel). Signed-off-by: Stewart Smith [stephenfin: Regenerate migrations per addition of 0027 in earlier patch] Signed-off-by: Stephen Finucane --- diff --git a/patchwork/migrations/0030_add_submission_covering_index.py b/patchwork/migrations/0030_add_submission_covering_index.py new file mode 100644 index 00000000..e74c0ccf --- /dev/null +++ b/patchwork/migrations/0030_add_submission_covering_index.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.15 on 2018-08-31 23:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0029_add_list_covering_index'), + ] + + operations = [ + migrations.AddIndex( + model_name='submission', + index=models.Index(fields=['date', 'project', 'submitter', 'name'], name='submission_covering_idx'), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index cfa9b6c5..d2d8f343 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -383,6 +383,14 @@ class Submission(FilenameMixin, EmailMixin, models.Model): class Meta: ordering = ['date'] unique_together = [('msgid', 'project')] + indexes = [ + # This is a covering index for the /list/ query + # Like what we have for Patch, but used for displaying what we want + # rather than for working out the count (of course, this all + # depends on the SQL optimiser of your db engine) + models.Index(fields=['date', 'project', 'submitter', 'name'], + name='submission_covering_idx'), + ] class SeriesMixin(object):