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
6b4d1ec8
Kaydet (Commit)
6b4d1ec8
authored
Tem 30, 2018
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 #29614 -- Added BTreeIndex to django.contrib.postres.
üst
d6381d35
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
5 deletions
+86
-5
indexes.py
django/contrib/postgres/indexes.py
+24
-1
introspection.py
django/db/backends/postgresql/introspection.py
+2
-1
indexes.txt
docs/ref/contrib/postgres/indexes.txt
+14
-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 @
6b4d1ec8
from
django.db.models
import
Index
from
django.db.models
import
Index
from
django.utils.functional
import
cached_property
from
django.utils.functional
import
cached_property
__all__
=
[
'BrinIndex'
,
'GinIndex'
,
'GistIndex'
,
'HashIndex'
,
'SpGistIndex'
]
__all__
=
[
'BrinIndex'
,
'BTreeIndex'
,
'GinIndex'
,
'GistIndex'
,
'HashIndex'
,
'SpGistIndex'
,
]
class
PostgresIndex
(
Index
):
class
PostgresIndex
(
Index
):
...
@@ -55,6 +58,26 @@ class BrinIndex(PostgresIndex):
...
@@ -55,6 +58,26 @@ class BrinIndex(PostgresIndex):
return
with_params
return
with_params
class
BTreeIndex
(
PostgresIndex
):
suffix
=
'btree'
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
class
GinIndex
(
PostgresIndex
):
class
GinIndex
(
PostgresIndex
):
suffix
=
'gin'
suffix
=
'gin'
...
...
django/db/backends/postgresql/introspection.py
Dosyayı görüntüle @
6b4d1ec8
...
@@ -200,6 +200,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
...
@@ -200,6 +200,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
"""
,
[
table_name
])
"""
,
[
table_name
])
for
index
,
columns
,
unique
,
primary
,
orders
,
type_
,
definition
,
options
in
cursor
.
fetchall
():
for
index
,
columns
,
unique
,
primary
,
orders
,
type_
,
definition
,
options
in
cursor
.
fetchall
():
if
index
not
in
constraints
:
if
index
not
in
constraints
:
basic_index
=
type_
==
'btree'
and
not
index
.
endswith
(
'_btree'
)
and
options
is
None
constraints
[
index
]
=
{
constraints
[
index
]
=
{
"columns"
:
columns
if
columns
!=
[
None
]
else
[],
"columns"
:
columns
if
columns
!=
[
None
]
else
[],
"orders"
:
orders
if
orders
!=
[
None
]
else
[],
"orders"
:
orders
if
orders
!=
[
None
]
else
[],
...
@@ -208,7 +209,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
...
@@ -208,7 +209,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
"foreign_key"
:
None
,
"foreign_key"
:
None
,
"check"
:
False
,
"check"
:
False
,
"index"
:
True
,
"index"
:
True
,
"type"
:
Index
.
suffix
if
type_
==
'btree'
else
type_
,
"type"
:
Index
.
suffix
if
basic_index
else
type_
,
"definition"
:
definition
,
"definition"
:
definition
,
"options"
:
options
,
"options"
:
options
,
}
}
...
...
docs/ref/contrib/postgres/indexes.txt
Dosyayı görüntüle @
6b4d1ec8
...
@@ -26,6 +26,20 @@ available from the ``django.contrib.postgres.indexes`` module.
...
@@ -26,6 +26,20 @@ available from the ``django.contrib.postgres.indexes`` module.
The ``autosummarize`` parameter was added.
The ``autosummarize`` parameter was added.
``BTreeIndex``
==============
.. class:: BTreeIndex(fillfactor=None, **options)
.. versionadded:: 2.2
Creates a B-Tree index.
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
``GinIndex``
``GinIndex``
============
============
...
...
docs/releases/2.2.txt
Dosyayı görüntüle @
6b4d1ec8
...
@@ -82,9 +82,10 @@ Minor features
...
@@ -82,9 +82,10 @@ Minor features
:class:`~django.contrib.postgres.aggregates.StringAgg` determines the
:class:`~django.contrib.postgres.aggregates.StringAgg` determines the
ordering of the aggregated elements.
ordering of the aggregated elements.
* The new :class:`~django.contrib.postgres.indexes.HashIndex` and
* The new :class:`~django.contrib.postgres.indexes.BTreeIndex`,
:class:`~django.contrib.postgres.indexes.HashIndex` and
:class:`~django.contrib.postgres.indexes.SpGistIndex` classes allow
:class:`~django.contrib.postgres.indexes.SpGistIndex` classes allow
creating ``
hash``
and ``SP-GiST`` indexes in the database.
creating ``
B-Tree``, ``hash``,
and ``SP-GiST`` indexes in the database.
* :class:`~django.contrib.postgres.indexes.BrinIndex` now has the
* :class:`~django.contrib.postgres.indexes.BrinIndex` now has the
``autosummarize`` parameter.
``autosummarize`` parameter.
...
...
tests/postgres_tests/test_indexes.py
Dosyayı görüntüle @
6b4d1ec8
from
django.contrib.postgres.indexes
import
(
from
django.contrib.postgres.indexes
import
(
BrinIndex
,
GinIndex
,
GistIndex
,
HashIndex
,
SpGistIndex
,
BrinIndex
,
BTreeIndex
,
GinIndex
,
GistIndex
,
HashIndex
,
SpGistIndex
,
)
)
from
django.db
import
connection
from
django.db
import
connection
from
django.test
import
skipUnlessDBFeature
from
django.test
import
skipUnlessDBFeature
...
@@ -47,6 +47,20 @@ class BrinIndexTests(IndexTestMixin, PostgreSQLTestCase):
...
@@ -47,6 +47,20 @@ class BrinIndexTests(IndexTestMixin, PostgreSQLTestCase):
BrinIndex
(
fields
=
[
'title'
],
name
=
'test_title_brin'
,
pages_per_range
=
0
)
BrinIndex
(
fields
=
[
'title'
],
name
=
'test_title_brin'
,
pages_per_range
=
0
)
class
BTreeIndexTests
(
IndexTestMixin
,
PostgreSQLTestCase
):
index_class
=
BTreeIndex
def
test_suffix
(
self
):
self
.
assertEqual
(
BTreeIndex
.
suffix
,
'btree'
)
def
test_deconstruction
(
self
):
index
=
BTreeIndex
(
fields
=
[
'title'
],
name
=
'test_title_btree'
,
fillfactor
=
80
)
path
,
args
,
kwargs
=
index
.
deconstruct
()
self
.
assertEqual
(
path
,
'django.contrib.postgres.indexes.BTreeIndex'
)
self
.
assertEqual
(
args
,
())
self
.
assertEqual
(
kwargs
,
{
'fields'
:
[
'title'
],
'name'
:
'test_title_btree'
,
'fillfactor'
:
80
})
class
GinIndexTests
(
IndexTestMixin
,
PostgreSQLTestCase
):
class
GinIndexTests
(
IndexTestMixin
,
PostgreSQLTestCase
):
index_class
=
GinIndex
index_class
=
GinIndex
...
@@ -194,6 +208,34 @@ class SchemaTests(PostgreSQLTestCase):
...
@@ -194,6 +208,34 @@ class SchemaTests(PostgreSQLTestCase):
editor
.
remove_index
(
CharFieldModel
,
index
)
editor
.
remove_index
(
CharFieldModel
,
index
)
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
self
.
assertNotIn
(
index_name
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
def
test_btree_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_btree'
index
=
BTreeIndex
(
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'
],
BTreeIndex
.
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_btree_parameters
(
self
):
index_name
=
'integer_array_btree_fillfactor'
index
=
BTreeIndex
(
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'
],
BTreeIndex
.
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
))
def
test_gist_index
(
self
):
def
test_gist_index
(
self
):
# Ensure the table is there and doesn't have an index.
# Ensure the table is there and doesn't have an index.
self
.
assertNotIn
(
'field'
,
self
.
get_constraints
(
CharFieldModel
.
_meta
.
db_table
))
self
.
assertNotIn
(
'field'
,
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