我有一个User
类,通过User
关系与其他用户(FRIEND
)相关。
现在我想获得用户所有朋友的列表。为此,我的密码查询(下面)在非常少的数据中花费了太多时间。
我有100个User
个节点,每个节点至少有10个用户和最多20个用户。但我的下面的查询大约需要8秒钟。
@Query(
"MATCH (user:User {uid:{0}})-[:FRIEND]-(friend:User)" +
"RETURN friend"
)
public List<User> getFriends(String userId);
Neo4j版本: 2.x
Spring-data-neo4j版本: 3.x
我的其他两个查询也不是很快。第一个花费大约200毫秒,第二个花费1500毫秒
@Query(
// "MATCH (user:User {uid:{0}})-[:PLAYED_SONG|DOWNLOADED_SONG]->(song:Song {songId:{1}})<-[:PLAYED_SONG|DOWNLOADED_SONG]-(otherUser:User) " +
"MATCH (user:User {uid:{0}}), (song:Song {songId:{1}})<-[:PLAYED_SONG|DOWNLOADED_SONG]-(otherUser:User) " +
"WHERE (user)-[:FRIEND]-(otherUser) " +
"RETURN otherUser " +
"LIMIT 20"
)
public Set<User> getFriendsPlayedDownloadedSong(String userId, String songId);
@Query(
"MATCH (user:User {uid:{0}})-[:FRIEND]-(friend:User)-[:PLAYED_SONG|DOWNLOADED_SONG]-(song:Song) " +
"RETURN song " +
"LIMIT 20"
)
public Set<Song> getFriendsListenedToSongs(String userId);
相关帖子: Same cypher query taking different time when executed through different consoles