Here’s the table of contents:
一、模拟超级节点
- 数据建模
(人物 {name})-[发表 {score}]->(文章 {number})
- 数据生成
MERGE (per:人物 {name:'Superman'}) RETURN ID(per) AS id; //执行时间1~2秒 CALL apoc.periodic.iterate('WITH RANGE(0,1000000) AS list UNWIND list AS num RETURN num','CREATE (atc:文章 {number:num})', {parallel:true,batchSize:1000}) YIELD batches,total,timeTaken,committedOperations,failedOperations,failedBatches,retries,errorMessages,batch,operations RETURN batches,total,timeTaken,committedOperations,failedOperations,failedBatches,retries,errorMessages,batch,operations; //创建索引 CREATE INDEX ON :文章(number); //执行时间2~3秒 CALL apoc.periodic.iterate('WITH RANGE(0,1000000) AS list UNWIND list AS num RETURN num','MATCH (per),(atc:文章) WHERE ID(per)=3138206 AND atc.number=num CREATE (per)-[r:发表]->(atc) SET r.score=RAND()', {parallel:true,batchSize:1000}) YIELD batches,total,timeTaken,committedOperations,failedOperations,failedBatches,retries,errorMessages,batch,operations RETURN batches,total,timeTaken,committedOperations,failedOperations,failedBatches,retries,errorMessages,batch,operations;
- 查询
MATCH (per:人物)-[r:发表]->(atc:文章) WHERE ID(per)=3138206 RETURN ID(per) AS id,per.name AS name,r.score AS score ORDER BY score ASC SKIP 0 LIMIT 20 // Started streaming 20 records after 1 ms and completed after 1874 ms. // Started streaming 20 records in less than 1 ms and completed after 1526 ms.
MATCH (per:人物)-[r:发表]->(atc:文章) WHERE ID(per)=3138206 RETURN count(*) MATCH (n:
文章
) detach delete n
二、优化超级节点
- 数据建模
(人物 {name})-[TOP20 {score}]->(文章 {number})
- 查询
MATCH (per:人物)-[r:TOP20]->(atc:文章) WHERE ID(per)=3138206 RETURN ID(per) AS id,per.name AS name,r.score AS score
未完待续…
PREVIOUSDocker手动打包上传流程