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
6e5a7367
Kaydet (Commit)
6e5a7367
authored
May 19, 2014
tarafından
Vlastimil Zíma
Kaydeden (comit)
Tim Graham
Haz 20, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[1.7.x] Fixed #22514 -- Prevented indexes on virtual fields [postgres].
Backport of
78c32f1c
from master
üst
d9a83d59
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
creation.py
django/db/backends/postgresql_psycopg2/creation.py
+2
-2
models.py
tests/indexes/models.py
+25
-0
tests.py
tests/indexes/tests.py
+7
-0
No files found.
django/db/backends/postgresql_psycopg2/creation.py
Dosyayı görüntüle @
6e5a7367
...
@@ -47,7 +47,8 @@ class DatabaseCreation(BaseDatabaseCreation):
...
@@ -47,7 +47,8 @@ class DatabaseCreation(BaseDatabaseCreation):
def
sql_indexes_for_field
(
self
,
model
,
f
,
style
):
def
sql_indexes_for_field
(
self
,
model
,
f
,
style
):
output
=
[]
output
=
[]
if
f
.
db_index
or
f
.
unique
:
db_type
=
f
.
db_type
(
connection
=
self
.
connection
)
if
db_type
is
not
None
and
(
f
.
db_index
or
f
.
unique
):
qn
=
self
.
connection
.
ops
.
quote_name
qn
=
self
.
connection
.
ops
.
quote_name
db_table
=
model
.
_meta
.
db_table
db_table
=
model
.
_meta
.
db_table
tablespace
=
f
.
db_tablespace
or
model
.
_meta
.
db_tablespace
tablespace
=
f
.
db_tablespace
or
model
.
_meta
.
db_tablespace
...
@@ -73,7 +74,6 @@ class DatabaseCreation(BaseDatabaseCreation):
...
@@ -73,7 +74,6 @@ class DatabaseCreation(BaseDatabaseCreation):
# a second index that specifies their operator class, which is
# a second index that specifies their operator class, which is
# needed when performing correct LIKE queries outside the
# needed when performing correct LIKE queries outside the
# C locale. See #12234.
# C locale. See #12234.
db_type
=
f
.
db_type
(
connection
=
self
.
connection
)
if
db_type
.
startswith
(
'varchar'
):
if
db_type
.
startswith
(
'varchar'
):
output
.
append
(
get_index_sql
(
'
%
s_
%
s_like'
%
(
db_table
,
f
.
column
),
output
.
append
(
get_index_sql
(
'
%
s_
%
s_like'
%
(
db_table
,
f
.
column
),
' varchar_pattern_ops'
))
' varchar_pattern_ops'
))
...
...
tests/indexes/models.py
Dosyayı görüntüle @
6e5a7367
...
@@ -2,10 +2,35 @@ from django.db import connection
...
@@ -2,10 +2,35 @@ from django.db import connection
from
django.db
import
models
from
django.db
import
models
class
CurrentTranslation
(
models
.
ForeignObject
):
"""
Creates virtual relation to the translation with model cache enabled.
"""
# Avoid validation
requires_unique_target
=
False
def
__init__
(
self
,
to
,
from_fields
,
to_fields
,
**
kwargs
):
# Disable reverse relation
kwargs
[
'related_name'
]
=
'+'
# Set unique to enable model cache.
kwargs
[
'unique'
]
=
True
super
(
CurrentTranslation
,
self
)
.
__init__
(
to
,
from_fields
,
to_fields
,
**
kwargs
)
class
ArticleTranslation
(
models
.
Model
):
article
=
models
.
ForeignKey
(
'indexes.Article'
)
language
=
models
.
CharField
(
max_length
=
10
,
unique
=
True
)
content
=
models
.
TextField
()
class
Article
(
models
.
Model
):
class
Article
(
models
.
Model
):
headline
=
models
.
CharField
(
max_length
=
100
)
headline
=
models
.
CharField
(
max_length
=
100
)
pub_date
=
models
.
DateTimeField
()
pub_date
=
models
.
DateTimeField
()
# Add virtual relation to the ArticleTranslation model.
translation
=
CurrentTranslation
(
ArticleTranslation
,
[
'id'
],
[
'article'
])
class
Meta
:
class
Meta
:
index_together
=
[
index_together
=
[
[
"headline"
,
"pub_date"
],
[
"headline"
,
"pub_date"
],
...
...
tests/indexes/tests.py
Dosyayı görüntüle @
6e5a7367
...
@@ -29,3 +29,10 @@ class IndexesTests(TestCase):
...
@@ -29,3 +29,10 @@ class IndexesTests(TestCase):
# unique=True and db_index=True should only create the varchar-specific
# unique=True and db_index=True should only create the varchar-specific
# index (#19441).
# index (#19441).
self
.
assertIn
(
'("slug" varchar_pattern_ops)'
,
index_sql
[
4
])
self
.
assertIn
(
'("slug" varchar_pattern_ops)'
,
index_sql
[
4
])
@skipUnless
(
connection
.
vendor
==
'postgresql'
,
"This is a postgresql-specific issue"
)
def
test_postgresql_virtual_relation_indexes
(
self
):
"""Test indexes are not created for related objects"""
index_sql
=
connection
.
creation
.
sql_indexes_for_model
(
Article
,
no_style
())
self
.
assertEqual
(
len
(
index_sql
),
1
)
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