1
我剛剛開始使用圖形數據庫和Neo4j。我創建了具有以下標籤的節點:人員,公司,城市,技能,它們之間有一個或多個關係。Cypher查詢性能和結構
我想做一個密碼查詢找到一個人節點(通過節點ID),然後我想找到所有的技能,公司等與此人相關。這是迄今爲止我的查詢:
MATCH (person:Person)
WHERE ID (person) = 123
WITH person LIMIT 1
OPTIONAL MATCH (p:Person) - [:HAS_SKILL] -> (skill:Skill)
WHERE ID (p) = 123
WITH person, skill ORDER BY skill.name ASC
OPTIONAL MATCH (p:Person) - [:WORKED_AT] -> (company:Company)
WHERE ID (p) = 123
WITH person, skill, company ORDER BY company.name ASC
OPTIONAL MATCH (p:Person) - [:LIVES_IN] -> (city:City)
WHERE ID (p) = 123
WITH person
, collect(DISTINCT skill) as skills
, collect(DISTINCT company) as companies
, city LIMIT 1
RETURN person, skills, companies, city
我擔心這是不是一個真正的最佳查詢和它看起來會很慢,如果/當我們可以說幾百萬的節點。有人能告訴我一個更好的方式來構建這種查詢嗎?我應該把它分成幾個更小的查詢嗎?