Here's the problem I'm trying to solve:
这是我试图解决的问题:
I need to design a database capable of storing user
data and post
data. Among other things, each entry in the user table needs to track a series of post
attributes we've determined that the user likes. For each post, I need to store a list of attributes associated with the post.
我需要设计一个能够存储用户数据和发布数据的数据库。除此之外,用户表中的每个条目都需要跟踪我们确定用户喜欢的一系列帖子属性。对于每个帖子,我需要存储与帖子相关的属性列表。
I'd like to use a linked list to track post
attributes and a hash table to track a user's likes (I'll be doing a lot of "for each attribute of this post, check if the user likes it"?). The trouble is I don't have any idea how I could store those data structures in a relational table. Is something like that even possible? If not, can you offer suggestions on alternative implementations?
我想使用链接列表来跟踪帖子属性和哈希表来跟踪用户的喜欢(我会做很多“对于这篇文章的每个属性,检查用户是否喜欢它”?)。问题是我不知道如何将这些数据结构存储在关系表中。这样的事情甚至可能吗?如果没有,您能提供有关替代实施的建议吗?
1 个解决方案
#1
1
I'll talk specifically about SQL databases, because I've got a little more experience with them than with other kinds of databases.
我将专门讨论SQL数据库,因为我对它们的经验比其他类型的数据库更多。
A SQL database has essentially one data structure: the table. You really don't want to use tables to implement linked lists or hash tables. And you don't want to store linked lists or hash tables in a database.
SQL数据库基本上有一个数据结构:表。您真的不想使用表来实现链表或哈希表。而且您不希望在数据库中存储链表或散列表。
The concerns that make you want to use a linked list (manage unbounded memory?) or a hash table (fast searches?) have already been taken care of by the people who designed and built the database management systems.
您想要使用链接列表(管理无限内存?)或哈希表(快速搜索?)的问题已由设计和构建数据库管理系统的人员负责。
So you just need to build the right tables. You'll find that building tables is simple, but building them right might be far from easy. Google is your friend.
所以你只需要构建正确的表格。您会发现构建表格很简单,但正确构建它们可能并不容易。谷歌是你的朋友。
#1
1
I'll talk specifically about SQL databases, because I've got a little more experience with them than with other kinds of databases.
我将专门讨论SQL数据库,因为我对它们的经验比其他类型的数据库更多。
A SQL database has essentially one data structure: the table. You really don't want to use tables to implement linked lists or hash tables. And you don't want to store linked lists or hash tables in a database.
SQL数据库基本上有一个数据结构:表。您真的不想使用表来实现链表或哈希表。而且您不希望在数据库中存储链表或散列表。
The concerns that make you want to use a linked list (manage unbounded memory?) or a hash table (fast searches?) have already been taken care of by the people who designed and built the database management systems.
您想要使用链接列表(管理无限内存?)或哈希表(快速搜索?)的问题已由设计和构建数据库管理系统的人员负责。
So you just need to build the right tables. You'll find that building tables is simple, but building them right might be far from easy. Google is your friend.
所以你只需要构建正确的表格。您会发现构建表格很简单,但正确构建它们可能并不容易。谷歌是你的朋友。