如何解决Timescaledb 上的索引
我正在测试有关 Postgresql 扩展 Timescaledb 的一些查询。 该表称为时间戳记,我对它运行了一些查询,看起来像这样
select id13 from timestampdb where timestamp1 >='2010-01-01 00:05:00' and timestamp1<='2011-01-01 00:05:00',select avg(id13)::numeric(10,2) from timestasmpdb where timestamp1>='2015-01-01 00:05:00' and timestamp1<='2015-01-01 10:30:00'
当我创建一个超级表时,我会这样做。
create hyper_table('timestampdb','timestamp1')
问题是现在我想在 id13 上创建一个索引。
我应该尝试这样的事情吗?:
create hyper_table('timestampdb','timestamp1'),import data of the table and then create index on timestampdb(id13)
或类似的东西:
create table timestampdb,then create hypertable('timestampdb',timestamp1'),import the data and then CREATE INDEX ON timestampdb (timestamp1,id13)
这样做的正确方法是什么?
解决方法
您可以创建没有时间维度列的索引,因为您不需要它是唯一的。如果索引包含 UNIQUE
或 PRIMARY KEY
,则需要将时间维度列包含到索引中,因为 TimescaleDB 将超表分区为时间维度列上的块,这在问题中是 timestamp1
。如果分区键除了时间还包含空间维度列,也需要包含。
因此,在您的情况下,迁移到 hypertable 后,以下内容就足够了:
create index on timestampdb(id13);
该问题包含两个查询,它们都不需要在 id13
上建立索引。如果您期望与问题中的查询不同,那么在 id13
上创建索引将很有价值,问题将包含 id13
列上的条件或连接。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。