postgres 中表继承需要索引吗?
这是一个相当简单的问题,但我找不到明确的答案。
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在子表上为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.