Refs #32943 -- Added support for covering SP-GiST indexes on PostgreSQL 14+.

This commit is contained in:
Nick Pope 2021-05-28 23:52:57 +01:00 committed by Mariusz Felisiak
parent bd47b9bc81
commit e76f9d5b44
9 changed files with 54 additions and 5 deletions

View file

@ -142,7 +142,7 @@ class Migration(migrations.Migration):
name='Scene',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('scene', models.CharField(max_length=255)),
('scene', models.TextField()),
('setting', models.CharField(max_length=255)),
],
options=None,

View file

@ -101,7 +101,7 @@ class BigAutoFieldModel(models.Model):
# Scene/Character/Line models are used to test full text search. They're
# populated with content from Monty Python and the Holy Grail.
class Scene(models.Model):
scene = models.CharField(max_length=255)
scene = models.TextField()
setting = models.CharField(max_length=255)

View file

@ -518,6 +518,33 @@ class SchemaTests(PostgreSQLTestCase):
editor.remove_index(TextFieldModel, index)
self.assertNotIn(index_name, self.get_constraints(TextFieldModel._meta.db_table))
@skipUnlessDBFeature('supports_covering_spgist_indexes')
def test_spgist_include(self):
index_name = 'scene_spgist_include_setting'
index = SpGistIndex(name=index_name, fields=['scene'], include=['setting'])
with connection.schema_editor() as editor:
editor.add_index(Scene, index)
constraints = self.get_constraints(Scene._meta.db_table)
self.assertIn(index_name, constraints)
self.assertEqual(constraints[index_name]['type'], SpGistIndex.suffix)
self.assertEqual(constraints[index_name]['columns'], ['scene', 'setting'])
with connection.schema_editor() as editor:
editor.remove_index(Scene, index)
self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
def test_spgist_include_not_supported(self):
index_name = 'spgist_include_exception'
index = SpGistIndex(fields=['scene'], name=index_name, include=['setting'])
msg = 'Covering SP-GiST indexes require PostgreSQL 14+.'
with self.assertRaisesMessage(NotSupportedError, msg):
with mock.patch(
'django.db.backends.postgresql.features.DatabaseFeatures.supports_covering_spgist_indexes',
False,
):
with connection.schema_editor() as editor:
editor.add_index(Scene, index)
self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
def test_op_class(self):
index_name = 'test_op_class'
index = Index(