Skip to content

Commit adf08a5

Browse files
committed
FIX: move index creation to a PostgreSQL-specific trigger
1 parent c477ebb commit adf08a5

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tiled/catalog/orm.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ class Node(Timestamped, Base):
109109
"access_blob",
110110
postgresql_using="gin",
111111
),
112-
# PostgreSQL-specific covering index for fast key lookups.
113-
Index(
114-
"ix_nodes_parent_time_id_key",
115-
"parent",
116-
"time_created",
117-
"id",
118-
postgresql_include=["key"],
119-
),
120112
)
121113

122114

@@ -299,9 +291,9 @@ def unique_parameter_num_null_check(target, connection, **kw):
299291

300292
@event.listens_for(Node.__table__, "after_create")
301293
def create_index_metadata_tsvector_search(target, connection, **kw):
302-
# This creates a ts_vector based metadata search index for fulltext.
303-
# Postgres only feature
294+
# Postgres only features
304295
if connection.engine.dialect.name == "postgresql":
296+
# This creates a ts_vector based metadata search index for fulltext
305297
connection.execute(
306298
text(
307299
"""
@@ -311,6 +303,16 @@ def create_index_metadata_tsvector_search(target, connection, **kw):
311303
"""
312304
)
313305
)
306+
# Covering B-tree index on (parent, time_created, id) INCLUDE (key)
307+
connection.execute(
308+
text(
309+
"""
310+
CREATE INDEX ix_nodes_parent_time_id_key
311+
ON nodes (parent, time_created, id)
312+
INCLUDE (key)
313+
"""
314+
)
315+
)
314316

315317

316318
@event.listens_for(NodesClosure.__table__, "after_create")

0 commit comments

Comments
 (0)