MySQL 和 Neo4j 一起使用是个好主意吗? [英] Is it a good idea to use MySQL and Neo4j together?

查看:81
本文介绍了MySQL 和 Neo4j 一起使用是个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建一个包含大量相似项(数百万个)的应用程序,并且我想将它们存储在 MySQL 数据库中,因为我想进行大量统计并搜索特定列的特定值.

I will make an application with a lot of similar items (millions), and I would like to store them in a MySQL database, because I would like to do a lot of statistics and search on specific values for specific columns.

但同时,我将存储所有项之间的关系,这些关系在许多连接的二叉树状结构(传递闭包)中相关,而关系数据库不擅长这种结构,所以我会喜欢将所有关系存储在 Neo4j 中,对此类数据具有良好的性能.

But at the same time, I will store relations between all the items, that are related in many connected binary-tree-like structures (transitive closure), and relation databases are not good at that kind of structures, so I would like to store all relations in Neo4j which have good performance for this kind of data.

我的计划是将除了 MySQL 数据库中的关系和所有与 item_id 的关系存储在 Neo4j 数据库中的所有数据.当我想查找一棵树时,我首先在 Neo4j 中搜索树中的所有 item_id:s,然后在 MySQL 数据库中搜索查询中的所有指定项目,如下所示:

My plan is to have all data except the relations in the MySQL database and all relations with item_id stored in the Neo4j database. When I want to lookup a tree, I first search the Neo4j for all the item_id:s in the tree, then I search the MySQL-database for all the specified items in a query that would look like:

SELECT * FROM items WHERE item_id = 45 OR item_id = 345435 OR item_id = 343 OR item_id = 78 OR item_id = 4522 OR item_id = 676 OR item_id = 443 OR item_id = 4255 OR item_id

SELECT * FROM items WHERE item_id = 45 OR item_id = 345435 OR item_id = 343 OR item_id = 78 OR item_id = 4522 OR item_id = 676 OR item_id = 443 OR item_id = 4255 OR item_id = 4345

这是个好主意,还是我错了?我以前没有使用过图形数据库.有没有更好的方法来解决我的问题?在这种情况下,MySQL 查询将如何执行?

Is this a good idea, or am I very wrong? I haven't used graph-databases before. Are there any better approaches to my problem? How would the MySQL-query perform in this case?

推荐答案

对此的一些想法:

我会尝试对您的 Neo4j 域模型进行建模,以在图中包含每个节点的属性.通过将您的数据分成两个不同的数据存储,您可能会限制您可能想要执行的某些操作.

I would try modelling your Neo4j domain model to include the attributes of each node in the graph. By separating your data into two different data stores you might limit some operations that you might want to do.

我想这归结为您将如何处理您的图表.例如,如果您想查找所有连接到其属性(即名称、年龄等)为特定值的特定节点的所有节点,您是否首先必须在 MySQL 数据库中找到正确的节点 ID,然后进入Neo4j?当您可以在 Neo4j 中完成所有这些时,这看起来很慢且过于复杂.所以问题是:遍历图时是否需要节点的属性?

I guess it comes down to what you will be doing with your graph. If, for example, you want to find all the nodes connected to a specific node whose attributes (ie name, age.. whatever) are certain values, would you first have to find the correct node ID in your MySQL database and then go into Neo4j? This just seems slow and overly complicated when you could do all this in Neo4j. So the question is: will you need the attributes of a node when traversing the graph?

您的数据会改变还是静态的?拥有两个独立的数据存储会使事情复杂化.

Will your data change or is it static? By having two separate data stores it will complicate matters.

虽然使用 MySQL 数据库生成统计数据可能比在 Neo4j 中做任何事情都容易,但遍历图形以查找满足定义条件的所有节点所需的代码并不太困难.这些统计数据应该推动您的解决方案.

Whilst generating statistics using a MySQL database might be easier than doing everything in Neo4j, the code required to traverse a graph to find all the nodes that meet a defined criteria isn't overly difficult. What these stats are should drive your solution.

我无法评论用于选择节点 ID 的 MySQL 查询的性能.我想这取决于您需要选择多少个节点以及您的索引策略.不过,我同意遍历图形时的性能方面.

I can't comment on the performance of the MySQL query to select node ids. I guess that comes down to how many nodes you will need to select and your indexing strategy. I agree about the performance side of things when it comes to traversing a graph though.

这是一篇很好的文章:MySQL vs. Neo4j在大规模图遍历中,在这种情况下,当他们说大时,它们仅意味着一百万个顶点/节点和四百万条边.所以它甚至不是一个特别密集的图.

This is a good article on just this: MySQL vs. Neo4j on a Large-Scale Graph Traversal and in this case, when they say large, they only mean a million vertices/nodes and four million edges. So it wasn't even a particularly dense graph.

这篇关于MySQL 和 Neo4j 一起使用是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆