我将MySQL数据库迁移到Neo4j并测试了一个简单的请求。我很惊讶地发现neo4j中的等效请求比MySql中的请求长10到100倍。我正在研究Neo4j 2.0.1。
在原始的MySql模式中,我具有以下三个表:
每个属性都有一个索引。我要显示在多个条件下给定大陆的城市剧院数量。请求是:
SELECT count(*) as nb, c.name
FROM `cities` c LEFT JOIN theaters t ON c.id = t.city_id
WHERE c.country_code IN
(SELECT code FROM countries WHERE selected is true AND continent_id = 4)
AND c.status=1 AND t.public = 1
GROUP BY c.name ORDER BY nb DESC
Run Code Online (Sandbox Code Playgroud)
Neo4j中
的数据库架构如下:
(:Continent)-[:Include]->(:Country {selected:bool })-[:Include]->(:City {name:string,status:bool })-[:Include]->(:Theater {public:bool })
每个属性上还定义了一个索引。密码请求是:
MATCH (:Continent{code: 4})-[:Include]->(:Country{selected:true})-[:Include]->(city:City{status:true})-[:Include]->(:Theater{public: true})
RETURN city.name, count(*) AS nb …Run Code Online (Sandbox Code Playgroud) neo4j ×1