Skip to content

Commit fe840ec

Browse files
committed
disable support for table & column comments
Otherwise, the Django test suite run time increases from < 1 hour to 6.5 hours.
1 parent f7df3de commit fe840ec

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ using back to Cockroach Labs. To disable this, set
104104
later operation tries to modify the table before the asynchronous query
105105
finishes. A future version of CockroachDB [may fix this](https://github.com/cockroachdb/cockroach/issues/47137).
106106

107+
- The `Field.db_comment` and `Meta.db_table_comment` options aren't supported
108+
due to [poor performance](https://github.com/cockroachdb/cockroach/issues/95068).
109+
107110
- Unsupported queries:
108111
- [Mixed type addition in SELECT](https://github.com/cockroachdb/django-cockroachdb/issues/19):
109112
`unsupported binary operator: <int> + <float>`

django_cockroachdb/features.py

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class DatabaseFeatures(PostgresDatabaseFeatures):
4949
# PostgreSQL behaves the opposite.
5050
nulls_order_largest = False
5151

52+
# pg_catalog.obj_description is very slow:
53+
# https://github.com/cockroachdb/cockroach/issues/95068
54+
supports_comments = False
55+
5256
@cached_property
5357
def introspected_field_types(self):
5458
return {

django_cockroachdb/introspection.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
11
from django.db.backends.postgresql.introspection import (
2-
DatabaseIntrospection as PostgresDatabaseIntrospection,
2+
DatabaseIntrospection as PostgresDatabaseIntrospection, TableInfo,
33
)
44

55

66
class DatabaseIntrospection(PostgresDatabaseIntrospection):
77
data_types_reverse = dict(PostgresDatabaseIntrospection.data_types_reverse)
88
data_types_reverse[1184] = 'DateTimeField' # TIMESTAMPTZ
99
index_default_access_method = 'prefix'
10+
11+
def get_table_list(self, cursor):
12+
# pg_catalog.obj_description is removed from this query to speed it up:
13+
# https://github.com/cockroachdb/cockroach/issues/95068
14+
"""Return a list of table and view names in the current database."""
15+
cursor.execute(
16+
"""
17+
SELECT
18+
c.relname,
19+
CASE
20+
WHEN c.relispartition THEN 'p'
21+
WHEN c.relkind IN ('m', 'v') THEN 'v'
22+
ELSE 't'
23+
END,
24+
''
25+
FROM pg_catalog.pg_class c
26+
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
27+
WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
28+
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
29+
AND pg_catalog.pg_table_is_visible(c.oid)
30+
"""
31+
)
32+
return [
33+
TableInfo(*row)
34+
for row in cursor.fetchall()
35+
if row[0] not in self.ignored_tables
36+
]

0 commit comments

Comments
 (0)