]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Add covering index to patchwork_submissions for /list/ queries
authorStewart Smith <stewart@linux.ibm.com>
Fri, 10 Aug 2018 08:01:03 +0000 (18:01 +1000)
committerStephen Finucane <stephen@that.guru>
Mon, 10 Sep 2018 20:24:24 +0000 (14:24 -0600)
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 <stewart@linux.ibm.com>
[stephenfin: Regenerate migrations per addition of 0027 in earlier
 patch]
Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/migrations/0030_add_submission_covering_index.py [new file with mode: 0644]
patchwork/models.py

diff --git a/patchwork/migrations/0030_add_submission_covering_index.py b/patchwork/migrations/0030_add_submission_covering_index.py
new file mode 100644 (file)
index 0000000..e74c0cc
--- /dev/null
@@ -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'),
+        ),
+    ]
index cfa9b6c597266bc8572332a3f79b87f563060a91..d2d8f343d21d9b7e29533661fd7a30bb10a9d750 100644 (file)
@@ -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):