在键值存储中模拟带有索引的数据库表的最简单方法是什么?

发布于 2024-08-21 22:01:00 字数 161 浏览 3 评论 0原文

在键值存储中模拟带有索引的数据库表的最简单方法是什么?键值存储没有范围查询和有序键。

我想要模拟的事情(按优先级顺序):

  1. 创建表
  2. 添加列
  3. 创建索引
  4. 基于主键
  5. 查询 基于任意列查询

What is the easiest way to simulate a database table with an index in a key value store? The key value store has NO ranged queries and NO ordered keys.

The things I want to simulate (in order of priority):

  1. Create tables
  2. Add columns
  3. Create indexes
  4. Query based on primary key
  5. Query based on arbitrary columns

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年 2024-08-28 22:01:00

如果您使用 Redis(一种高级键值存储,支持字符串、列表、集合、等等)那么这很容易。我已经开发了一个 C# redis 客户端,它原生支持存储 POCO 的数据模型。 OrmLite 可以使用这些完全相同的 POCO 将其存储在 RDBMS 中。

顺便说一句,Redis 速度很快,我有一个基准来存储和检索整个 Northwind 数据库(3202 条记录)在 1.2 秒内完成(在 3yo iMac 上的 UnitTest 中运行)。

我以两种方式存储实体:

  • 不同的实体,我将类类型名称和主键组合起来创建一个唯一的键,例如 urn:user:1
    • 然后,我维护一组单独的主键(在 Redis 集中)来跟踪我的所有实体,使用如下键:ids:user
  • 在 Redis 服务器端列表中 - 其中其行为非常类似于支持分页的表格,使用如下键:lists:user

If you use Redis (an advanced key-value store that supports strings, lists, sets, etc.) Then this is quite easy. I have already developed a C# redis client that has native support for storing POCO's data models. These exact same POCO's can be used by OrmLite to store it in a RDBMS.

By the way Redis is fast, I have a benchmark that stores and retrieves the entire Northwind Database (3202 records) in under 1.2 seconds (running inside a UnitTest on a 3yo iMac).

I store entities in two ways

  • Distinct entities, where I combine the Class type name and Primary Key to create a unique key e.g. urn:user:1
    • I then maintain a separate set of primary keys (in a Redis Set) to keep track of all my entities, using a key like: ids:user
  • In a Redis server side list - which acts very much like a table with support for paging, using a key like: lists:user
山有枢 2024-08-28 22:01:00

使用哈希表或字典。如果您想要唯一的键值,您可以使用 GUID 或哈希码。

Use a hashtable or dictionary. If you want unique key values you could use a GUID or hashcode.

帅冕 2024-08-28 22:01:00

键值存储应支持对键进行排序以及对键的远程访问。

然后,您应该创建两个字典:

id -> payload

col1, id -> NULL

,其中 payload 应包含数据库表将包含的所有数据,第二个字典的键应包含 (col1, id)< 的值/code> 来自第一个字典的每个条目。

The key-value store should support ordering the keys and ranged access to the keys.

Then you should create two dictionaries:

id -> payload

and

col1, id -> NULL

, where payload should contain all the data the database table would contain, and the keys of the second dictionary should contain the values of (col1, id) from each entry of the first dictionary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文