简体   繁体   English

为高度非规范化的NoSQL数据库设计唯一键(主键)

[英]Designing Unique Keys(Primary Keys) for a heavily denormalized NoSQL database

I am working on a web application related to Discussion forums using Java and Cassandra database. 我正在使用Java和Cassandra数据库开发与“论坛”相关的Web应用程序。

I need to construct 'keys' for the rows storing the user's details and & another set of rows storing the content posted by the user. 我需要为存储用户详细信息的行和存储用户发布的内容的另一组行构造“键”。

One option is to get the randomly generated UUID provided by Java language, but these are 16 bytes long. 一种选择是获取Java语言提供的随机生成的UUID,但这些UUID长度为16个字节。 and since NoSQL database involves heavy denormalization, I am concerned whether I would be wasting lots of disk space, RAM and other resources if the key could be generated in smaller sizes. 由于NoSQL数据库涉及严重的非规范化,我担心如果密钥可以以较小的尺寸生成,我是否会浪费大量的磁盘空间,RAM和其他资源。

I need to generate two types of keys, one for the Users & other for Content Posted by Users. 我需要生成两种类型的密钥,一种用于用户,另一种用于用户发布的内容。

For the Content posted by users, would timestamp+userId be a good key. 对于用户发布的内容, timestamp+userId将是一个不错的选择。 where timestamp is the server time at which content was posted and userId refers to key of user row. 其中timestamp是发布内容的服务器时间, userId是指用户行的密钥。

Any suggestions, comments appreciated .. 任何建议,评论赞赏..

Thanks Marcos 谢谢马科斯

Is this a distributed application? 这是分布式应用程序吗?

Then you could use a simple synchronized counter and initialize it on startup with the next available id. 然后你可以使用一个简单的同步计数器,并在启动时使用下一个可用的id初始化它。

On the other hand a database should be able to handle the UUID hashes as created by java. 另一方面,数据库应该能够处理由java创建的UUID哈希。 This is a standard for creating things like sessionIds, that need to be unique. 这是用于创建像sessionIds这样需要唯一的东西的标准。 Your problem is somewhat similar since a session in your context would represent a set of user input. 您的问题有点类似,因为您上下文中的会话将代表一组用户输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM