【问题标题】:Indexing on TimescaledbTimescaledb 上的索引
【发布时间】:2021-06-14 21:23:26
【问题描述】:

我正在测试一些关于 Postgresql 扩展 Timescaledb 的查询。 该表称为 timestampdb,我在上面运行了一些查询,看起来像这样

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)

这样做的正确方法是什么?

【问题讨论】:

    标签: postgresql performance indexing timescaledb


    【解决方案1】:

    您可以创建没有时间维度列的索引,因为您不需要它是唯一的。如果索引包含UNIQUEPRIMARY KEY,则需要将时间维度列包含到索引中,因为TimescaleDB 将超表划分为时间维度列上的块,即问题中的timestamp1。如果分区键除了时间之外还包括空间维度列,它们也需要包括在内。

    因此,在您的情况下,迁移到超表后,以下内容就足够了:

    create index on timestampdb(id13);
    

    该问题包含两个查询,它们都不需要在id13 上建立索引。如果您希望查询与问题中不同的查询,那么在id13 上创建索引将很有价值,其中将包含id13 列上的条件或联接。

    【讨论】:

    • 感谢您的回答!非常感谢!是的,我的大多数查询仅在选择时使用 id13,就像我在上面的问题中使用的两个一样。所以我想不添加索引id13 但您的回答非常有价值,因为将来我可能想在任何列上添加索引!
    猜你喜欢
    • 2019-07-23
    • 1970-01-01
    • 2021-10-29
    • 2021-05-20
    • 1970-01-01
    • 2018-11-10
    • 2021-09-05
    • 2022-01-18
    • 2020-05-15
    相关资源
    最近更新 更多