我应该如何/使用什么数据库在数据库中存储可查询列表?链接表似乎太多太慢了?

2024-04-25 16:39:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从事一个项目,该项目将有数百万个主键(用户ID)。每个用户都有一个长度未知的属性列表(在1到100之间,但在几乎所有情况下通常为<;5,总共约1000个可能的属性)。此列表需要能够查询,以查找具有相同属性的用户

我将如何做到这一点?一种方法似乎是为每个用户创建一个唯一的表,但这意味着我会有很多表,这似乎是错误的。使用的另一种方法似乎是将列表存储为blob,但这会使查询变得困难

<>我更喜欢使用Python,但是如果我的服务器相当轻,我可能会切换到C++。到目前为止,我唯一使用的sql DB是SQLite,但这可能并不理想,因为它每秒无法处理足够的提交(尽管我可以排队)

我应该使用什么数据库?我应该如何正确使用


1条回答
网友
1楼 · 发布于 2024-04-25 16:39:48

对于这种情况,我想基于图形的数据库GDBs是不错的选择

可以将属性定义为节点;著名且功能强大的基于图形的数据库之一是Neo4jNeo4j没有表。Neo4j使用Cypher(图形查询语言)处理其查询

来自Neo4j网站:

Unlike traditional databases, which arrange data in rows, columns and tables, Neo4j has a flexible structure defined by stored relationships between data records. With Neo4j, each data record, or node, stores direct pointers to all the nodes it’s connected to. Because Neo4j is designed around this simple, yet powerful optimization, it performs queries with complex connections orders of magnitude faster, and with more depth, than other databases.

来自Neo4j网站关于Cypher的信息:

With Neo4j, connections between data are stored – not computed at query time. Cypher is a powerful, graph-optimized query language that understands, and takes advantage of, these stored connections. When trying to find patterns or insights within data, Cypher queries are often much simpler and easier to write than massive SQL JOINs. Since Neo4j doesn’t have tables, there are no JOINs to worry about.

您可以在他们网站的主页上找到与SQL的一些比较:https://neo4j.com/

如果要在python中使用Neo4j,也请检查以下链接:

  1. https://neo4j.com/developer/python/
  2. https://pypi.org/project/neo4j-driver/
  3. https://towardsdatascience.com/neo4j-cypher-python-7a919a372be7

相关问题 更多 >

    热门问题