超过 10 列的唯一约束

发布于 2024-09-05 06:43:09 字数 656 浏览 21 评论 0原文

我有一个时间序列模拟模型,有超过 10 个输入变量。不同模拟实例的数量将超过 100 万个,每个模拟实例每天都会生成一些输出行。

为了将模拟结果保存在关系数据库中,我设计了这样的表。

创建表SimulationModel (

simul_id 整数主键,

输入0字符串/数字,

输入1字符串/数字,

...)

创建表SimulationOutput (

dt 日期时间主键,

simul_id 整数主键,

输出0数字,

...)

使每个模型都是唯一的,我正在考虑如下一些方法。

  1. 对SimulationModel表的所有输入列设置唯一约束

  2. 重新设计SimulationModel 表,将输入列分组为2~3 列,并对这些分组的列设置唯一约束。 (通过创建一个长字符串值,如“input0_input1_input2”)

  3. 忘记服务器端约束并在应用程序端完成工作。

您如何看待这些选择?

在10多列、几百万行上使用唯一索引没有问题吗?

还有其他方法可以推荐吗?

(我可能会使用postgresql)

I have a time-series simulation model which has more than 10 input variables. The number of distinct simulation instances would be more than 1 million, and each simulation instance generates a few output rows every day.

To save the simulation result in a relational database, i designed tables like this.

create table SimulationModel (

simul_id integer primary key,

input0 string/numeric,

input1 string/numeric,

...)

create table SimulationOutput (

dt DateTime primary key,

simul_id integer primary key,

output0 numeric,

...)

To make each model be unique, i'm considering some ways like below.

  1. put an unique constraint on all of the input columns of the SimulationModel table

  2. redesign SimulationModel table to group input columns into 2~3 columns and put an unique constraint on these grouped columns. (By making a long string value like "input0_input1_input2")

  3. forget about the server side constraint and do the job in the application side.

How do you think about these options?

Is there no problem to use an unique index on more than 10 columns with millions rows?

Is there some other way to recommend?

(I may use postgresql)

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

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

发布评论

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

评论(5

迷你仙 2024-09-12 06:43:09

创建独特的约束。 10 列和几百万行并不是一个真正的大表。此外,您的测试可能会受益于使用索引 - 或者至少索引不会造成任何损害。

Create the unqiue constraint. 10 columns with a couple of million rows isn't really a large table. Also your tests will presumably benefit from having an index to work with - or at least an index wouldn't do any harm.

拥醉 2024-09-12 06:43:09

如果您为您的仿真模型创建两个表,如下所示:

Table SimulationModel {
id: integer,
...
}

Table SimulationModelInput {
simulationmodel_id: integer foreign key(SimulationModel.id),
input: string or numeric,
...
}

那么您可以对 (simulationmodel_id, input) 添加一个约束,但获取配置的查询会更加复杂。

If you create two tables for your simulationmodel like this:

Table SimulationModel {
id: integer,
...
}

Table SimulationModelInput {
simulationmodel_id: integer foreign key(SimulationModel.id),
input: string or numeric,
...
}

then you can put a single constrain on (simulationmodel_id, input) but the query to fetch the configuration is more complex.

策马西风 2024-09-12 06:43:09

唯一索引是确保每组输入都是唯一的方法。

The unique index is the way to go to make sure each set of inputs is unique.

秉烛思 2024-09-12 06:43:09

您可以创建一个“唯一”列,它是其他列的哈希值,并将其称为标识。

You could create a single "unique" column that is a hash of the other columns and call that the identity.

许仙没带伞 2024-09-12 06:43:09

我将处理应用程序中的唯一性约束,特别是如果只有一个进程正在创建模拟。然后,您可以在常用过滤的输入列上拥有一个或多个非唯一索引,以实现高效访问。

I would handle the uniqueness constraint in the application, especially if only one process is creating simulations. You could then have one or more non-unique indexes on commonly-filtered input columns for efficient access.

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