Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
4c36e9e4
Kaydet (Commit)
4c36e9e4
authored
Ara 05, 2017
tarafından
Nick Pope
Kaydeden (comit)
Tim Graham
Agu 02, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28887 -- Added SpGistIndex to django.contrib.postgres.
üst
d526b077
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
4 deletions
+82
-4
indexes.py
django/contrib/postgres/indexes.py
+21
-1
indexes.txt
docs/ref/contrib/postgres/indexes.txt
+15
-0
2.2.txt
docs/releases/2.2.txt
+3
-2
test_indexes.py
tests/postgres_tests/test_indexes.py
+43
-1
No files found.
django/contrib/postgres/indexes.py
Dosyayı görüntüle @
4c36e9e4
from
django.db.models
import
Index
from
django.utils.functional
import
cached_property
__all__
=
[
'BrinIndex'
,
'GinIndex'
,
'GistIndex'
,
'HashIndex'
]
__all__
=
[
'BrinIndex'
,
'GinIndex'
,
'GistIndex'
,
'HashIndex'
,
'SpGistIndex'
]
class
PostgresIndex
(
Index
):
...
...
@@ -118,3 +118,23 @@ class HashIndex(PostgresIndex):
if
self
.
fillfactor
is
not
None
:
with_params
.
append
(
'fillfactor =
%
d'
%
self
.
fillfactor
)
return
with_params
class
SpGistIndex
(
PostgresIndex
):
suffix
=
'spgist'
def
__init__
(
self
,
*
,
fillfactor
=
None
,
**
kwargs
):
self
.
fillfactor
=
fillfactor
super
()
.
__init__
(
**
kwargs
)
def
deconstruct
(
self
):
path
,
args
,
kwargs
=
super
()
.
deconstruct
()
if
self
.
fillfactor
is
not
None
:
kwargs
[
'fillfactor'
]
=
self
.
fillfactor
return
path
,
args
,
kwargs
def
get_with_params
(
self
):
with_params
=
[]
if
self
.
fillfactor
is
not
None
:
with_params
.
append
(
'fillfactor =
%
d'
%
self
.
fillfactor
)
return
with_params
docs/ref/contrib/postgres/indexes.txt
Dosyayı görüntüle @
4c36e9e4
...
...
@@ -91,3 +91,18 @@ available from the ``django.contrib.postgres.indexes`` module.
they suffer from a number of data integrity issues in older versions.
.. _fillfactor: https://www.postgresql.org/docs/current/static/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS
``SpGistIndex``
===============
.. class:: SpGistIndex(fillfactor=None, **options)
.. versionadded:: 2.2
Creates an `SP-GiST index
<https://www.postgresql.org/docs/current/static/spgist.html>`_.
Provide an integer value from 10 to 100 to the fillfactor_ parameter to
tune how packed the index pages will be. PostgreSQL's default is 90.
.. _fillfactor: https://www.postgresql.org/docs/current/static/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS
docs/releases/2.2.txt
Dosyayı görüntüle @
4c36e9e4
...
...
@@ -82,8 +82,9 @@ Minor features
:class:`~django.contrib.postgres.aggregates.StringAgg` determines the
ordering of the aggregated elements.
* The new :class:`~django.contrib.postgres.indexes.HashIndex` class
allows creating ``hash`` indexes in the database.
* The new :class:`~django.contrib.postgres.indexes.HashIndex` and
:class:`~django.contrib.postgres.indexes.SpGistIndex` classes allow
creating ``hash`` and ``SP-GiST`` indexes in the database.
:mod:`django.contrib.redirects`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
tests/postgres_tests/test_indexes.py
Dosyayı görüntüle @
4c36e9e4
from
django.contrib.postgres.indexes
import
(
BrinIndex
,
GinIndex
,
GistIndex
,
HashIndex
,
BrinIndex
,
GinIndex
,
GistIndex
,
HashIndex
,
SpGistIndex
,
)
from
django.db
import
connection
from
django.test
import
skipUnlessDBFeature
...
...
@@ -99,6 +99,20 @@ class HashIndexTests(IndexTestMixin, PostgreSQLTestCase):
self
.
assertEqual
(
kwargs
,
{
'fields'
:
[
'title'
],
'name'
:
'test_title_hash'
,
'fillfactor'
:
80
})
class
SpGistIndexTests
(
IndexTestMixin
,
PostgreSQLTestCase
):
index_class
=
SpGistIndex
def
test_suffix
(
self
):
self
.
assertEqual
(
SpGistIndex
.
suffix
,
'spgist'
)
def
test_deconstruction
(
self
):
index
=
SpGistIndex
(
fields
=
[
'title'
],
name
=
'test_title_spgist'
,
fillfactor
=
80
)
path
,
args
,
kwargs
=
index
.
deconstruct
()
self
.
assertEqual
(
path
,
'django.contrib.postgres.indexes.SpGistIndex'
)
self
.
assertEqual
(
args
,
())
self
.
assertEqual
(
kwargs
,
{
'fields'
:
[
'title'
],
'name'
:
'test_title_spgist'
,
'fillfactor'
:
80
})
class
SchemaTests
(
PostgreSQLTestCase
):
def
get_constraints
(
self
,
table
):
...
...
@@ -217,3 +231,31 @@ class SchemaTests(PostgreSQLTestCase):
with
connection
.
schema_editor
()
as
editor
:
editor
.
remove_index
(
CharFieldModel
,
index
)
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
def
test_spgist_index
(
self
):
# Ensure the table is there and doesn't have an index.
self
.
assertNotIn
(
'field'
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
# Add the index.
index_name
=
'char_field_model_field_spgist'
index
=
SpGistIndex
(
fields
=
[
'field'
],
name
=
index_name
)
with
connection
.
schema_editor
()
as
editor
:
editor
.
add_index
(
CharFieldModel
,
index
)
constraints
=
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
)
# The index was added.
self
.
assertEqual
(
constraints
[
index_name
][
'type'
],
SpGistIndex
.
suffix
)
# Drop the index.
with
connection
.
schema_editor
()
as
editor
:
editor
.
remove_index
(
CharFieldModel
,
index
)
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
def
test_spgist_parameters
(
self
):
index_name
=
'integer_array_spgist_fillfactor'
index
=
SpGistIndex
(
fields
=
[
'field'
],
name
=
index_name
,
fillfactor
=
80
)
with
connection
.
schema_editor
()
as
editor
:
editor
.
add_index
(
CharFieldModel
,
index
)
constraints
=
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
)
self
.
assertEqual
(
constraints
[
index_name
][
'type'
],
SpGistIndex
.
suffix
)
self
.
assertEqual
(
constraints
[
index_name
][
'options'
],
[
'fillfactor=80'
])
with
connection
.
schema_editor
()
as
editor
:
editor
.
remove_index
(
CharFieldModel
,
index
)
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment