Add index to PostgreSQL AGE graph storage
This commit is contained in:
@@ -1083,27 +1083,36 @@ class PGGraphStorage(BaseGraphStorage):
|
|||||||
if self.db is None:
|
if self.db is None:
|
||||||
self.db = await ClientManager.get_client()
|
self.db = await ClientManager.get_client()
|
||||||
|
|
||||||
node1_id = "dummy_entity"
|
# 分别执行每个语句,忽略错误
|
||||||
node1_data = {
|
queries = [
|
||||||
"entity_id": node1_id,
|
f"SELECT create_graph('{self.graph_name}')",
|
||||||
"description": "dummy description",
|
f'CREATE INDEX CONCURRENTLY vertex_p_idx ON {self.graph_name}."_ag_label_vertex" (id)',
|
||||||
"keywords": "dummy,keywords",
|
f'CREATE INDEX CONCURRENTLY vertex_idx_node_id ON {self.graph_name}."_ag_label_vertex" (ag_catalog.agtype_access_operator(properties, \'"entity_id"\'::agtype))',
|
||||||
"entity_type": "dummy_type",
|
f'CREATE INDEX CONCURRENTLY edge_p_idx ON {self.graph_name}."_ag_label_edge" (id)',
|
||||||
}
|
f'CREATE INDEX CONCURRENTLY edge_sid_idx ON {self.graph_name}."_ag_label_edge" (start_id)',
|
||||||
await self.upsert_node(node1_id, node1_data)
|
f'CREATE INDEX CONCURRENTLY edge_eid_idx ON {self.graph_name}."_ag_label_edge" (end_id)',
|
||||||
await self.delete_node(node1_id)
|
f'CREATE INDEX CONCURRENTLY edge_seid_idx ON {self.graph_name}."_ag_label_edge" (start_id,end_id)',
|
||||||
|
f'CREATE INDEX CONCURRENTLY directed_p_idx ON {self.graph_name}."DIRECTED" (id)',
|
||||||
|
f'CREATE INDEX CONCURRENTLY directed_eid_idx ON {self.graph_name}."DIRECTED" (end_id)',
|
||||||
|
f'CREATE INDEX CONCURRENTLY directed_sid_idx ON {self.graph_name}."DIRECTED" (start_id)',
|
||||||
|
f'CREATE INDEX CONCURRENTLY directed_seid_idx ON {self.graph_name}."DIRECTED" (start_id,end_id)',
|
||||||
|
f'CREATE INDEX CONCURRENTLY entity_p_idx ON {self.graph_name}."base" (id)',
|
||||||
|
f'CREATE INDEX CONCURRENTLY entity_idx_node_id ON {self.graph_name}."base" (ag_catalog.agtype_access_operator(properties, \'"entity_id"\'::agtype))',
|
||||||
|
f'CREATE INDEX CONCURRENTLY entity_node_id_gin_idx ON {self.graph_name}."base" using gin(properties)',
|
||||||
|
f'ALTER TABLE {self.graph_name}."DIRECTED" CLUSTER ON directed_sid_idx',
|
||||||
|
]
|
||||||
|
|
||||||
query = (
|
for query in queries:
|
||||||
"""CREATE INDEX entity_id_gin_idxSELECT ON %s."base" USING gin (properties);"""
|
try:
|
||||||
% (self.graph_name)
|
await self.db.execute(
|
||||||
)
|
query,
|
||||||
|
upsert=True,
|
||||||
await self.db.execute(
|
with_age=True,
|
||||||
query,
|
graph_name=self.graph_name,
|
||||||
upsert=True,
|
)
|
||||||
with_age=True,
|
logger.info(f"Successfully executed: {query}")
|
||||||
graph_name=self.graph_name,
|
except Exception:
|
||||||
)
|
continue
|
||||||
|
|
||||||
async def finalize(self):
|
async def finalize(self):
|
||||||
if self.db is not None:
|
if self.db is not None:
|
||||||
|
Reference in New Issue
Block a user