mirror of https://github.com/django/django.git
Refs #25809 -- Made a few late review comments for BrinIndex.
This commit is contained in:
parent
0f46bc67e2
commit
65e321b781
|
@ -9,10 +9,10 @@ class BrinIndex(Index):
|
||||||
suffix = 'brin'
|
suffix = 'brin'
|
||||||
|
|
||||||
def __init__(self, fields=[], name=None, pages_per_range=None):
|
def __init__(self, fields=[], name=None, pages_per_range=None):
|
||||||
if pages_per_range is not None and not (isinstance(pages_per_range, int) and pages_per_range > 0):
|
if pages_per_range is not None and pages_per_range <= 0:
|
||||||
raise ValueError('pages_per_range must be None or a positive integer for BRIN indexes')
|
raise ValueError('pages_per_range must be None or a positive integer')
|
||||||
self.pages_per_range = pages_per_range
|
self.pages_per_range = pages_per_range
|
||||||
return super(BrinIndex, self).__init__(fields, name)
|
super(BrinIndex, self).__init__(fields, name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.pages_per_range is not None:
|
if self.pages_per_range is not None:
|
||||||
|
|
|
@ -60,9 +60,9 @@ class Index(object):
|
||||||
'extra': tablespace_sql,
|
'extra': tablespace_sql,
|
||||||
}
|
}
|
||||||
|
|
||||||
def create_sql(self, model, schema_editor, using='', parameters=None):
|
def create_sql(self, model, schema_editor, using=''):
|
||||||
sql_create_index = schema_editor.sql_create_index
|
sql_create_index = schema_editor.sql_create_index
|
||||||
sql_parameters = parameters or self.get_sql_create_template_values(model, schema_editor, using)
|
sql_parameters = self.get_sql_create_template_values(model, schema_editor, using)
|
||||||
return sql_create_index % sql_parameters
|
return sql_create_index % sql_parameters
|
||||||
|
|
||||||
def remove_sql(self, model, schema_editor):
|
def remove_sql(self, model, schema_editor):
|
||||||
|
|
|
@ -12,12 +12,12 @@ available from the ``django.contrib.postgres.indexes`` module.
|
||||||
``BrinIndex``
|
``BrinIndex``
|
||||||
=============
|
=============
|
||||||
|
|
||||||
.. class:: BrinIndex(pages_per_range=None)
|
.. class:: BrinIndex(fields=[], name=None, pages_per_range=None)
|
||||||
|
|
||||||
Creates a `BRIN index
|
Creates a `BRIN index
|
||||||
<https://www.postgresql.org/docs/current/static/brin-intro.html>`_. For
|
<https://www.postgresql.org/docs/current/static/brin-intro.html>`_.
|
||||||
performance considerations and use cases of the index, please consult the
|
|
||||||
documentation.
|
The ``pages_per_range`` argument takes a positive integer.
|
||||||
|
|
||||||
``GinIndex``
|
``GinIndex``
|
||||||
============
|
============
|
||||||
|
|
|
@ -27,7 +27,7 @@ class BrinIndexTests(PostgreSQLTestCase):
|
||||||
self.assertEqual(args, ())
|
self.assertEqual(args, ())
|
||||||
self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_brin', 'pages_per_range': None})
|
self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_brin', 'pages_per_range': None})
|
||||||
|
|
||||||
def test_deconstruction_with_pages_per_rank(self):
|
def test_deconstruction_with_pages_per_range(self):
|
||||||
index = BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=16)
|
index = BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=16)
|
||||||
path, args, kwargs = index.deconstruct()
|
path, args, kwargs = index.deconstruct()
|
||||||
self.assertEqual(path, 'django.contrib.postgres.indexes.BrinIndex')
|
self.assertEqual(path, 'django.contrib.postgres.indexes.BrinIndex')
|
||||||
|
@ -35,10 +35,7 @@ class BrinIndexTests(PostgreSQLTestCase):
|
||||||
self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_brin', 'pages_per_range': 16})
|
self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_brin', 'pages_per_range': 16})
|
||||||
|
|
||||||
def test_invalid_pages_per_range(self):
|
def test_invalid_pages_per_range(self):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaisesMessage(ValueError, 'pages_per_range must be None or a positive integer'):
|
||||||
BrinIndex(fields=['title'], name='test_title_brin', pages_per_range='Charles Babbage')
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=0)
|
BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue