postgres 中表继承需要索引吗?

发布于 2024-09-11 21:17:02 字数 324 浏览 2 评论 0原文

这是一个相当简单的问题,但我找不到明确的答案。

我在 PostgreSQL 中有一个父表,然后定义了几个子表。触发器已建立,并且仅当某个字段(例如字段x)满足特定条件时,子表才会插入数据。

当我使用基于x的字段查询父表时,PostgreSQL知道立即转到与x的特定值相关的子表。

话虽如此,我不需要在列 x 上指定特定索引,对吗? PostgreSQL 已经知道如何对其进行排序,并且通过向父表 x 添加索引,PostgreSQL 会为每个新子表在 x 上生成唯一索引。

创建该索引有点多余,对吧?

This is a fairly simple question, but it's one I can't find a firm answer on.

I have a parent table in PostgreSQL, and then several child tables which have been defined. A trigger has been established, and the children tables only have data inserted if a field, say field x, meets a certain criteria.

When I query the parent table with a field based upon x, PostgreSQL knows to immediately go to the child table that is related to that particular value of x.

That all being said, I don't need to specify a particular index on the column x do I? PostgreSQL already knows how to sort on it, and by adding an index to the parent x, PostgreSQL is therefore generating unique indexes on x for each of the new child tables.

Creating that index is a bit redundant, right?

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

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

发布评论

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

评论(1

耀眼的星火 2024-09-18 21:17:02

在子表上为x创建索引,如果x只有一个值(或者非常非常少的值)的话可能会损失,是的。无论如何,规划者都会扫描整个桌子。

如果 x 是时间戳并且您指定的时间范围可能不是整个分区,或者如果 x 是另一个范围或一组值,则索引很可能是胜利。

编辑:当我说一个值或值范围时,我的意思是每个子表。

Creating an index on the child table for x, if x only has one value (or a very, very small number of values) if probably a loss, yes. The planner would scan the whole table anyway.

If x is a timestamp and you're specifying a timeframe that may not be a whole partition, or if x is another range or set of values, an index would be a win most likely.

Edit: When I say one value or range of values, I mean, per child table.

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