【发布时间】:2021-06-16 06:50:58
【问题描述】:
我使用名为 Timescaledb 的 porstgreSQL 扩展。我有一个名为 timestampdb 的表。我想问一下这是否是创建一个包含两列(timestamp1,id13)的索引的正确方法。
我使用的一些查询如下所示:
select * from timestampdb where timestamp1 >='2020-01-01 00:05:00' and timestamp1<='2020-01-02 00:05:00' and id13>'5',
select date_trunc('hour',timestamp1) as hour,avg(id13) from timestampdb where timestamp1 >='2020-01-01 00:05:00' and timestamp1<='2020-01-02 00:05:00' group by hour order by hour ,
select date_trunc('hour',timestamp1) as hour,max(id13) from timestampdb where timestamp1<='2020-01-01 00:05:00' group by hour order by hour desc limit 5
创建表后我这样做:
create_hypertable("timestampdb",timestamp1) and then CREATE INDEX ON timestampdb (timestamp1,id13)
这是正确的方法吗?这会创建一个包含两列的索引吗?还是在 timestamp1 中创建一个索引,在 (timestamp1,id13) 中创建一个索引
【问题讨论】:
-
CREATE INDEX 在 PostgreSQL 中创建一个包含所有列的索引,这些列包含在语句中,并按照提供的顺序排列。我建议阅读best practivce of using composite index in TimescaleDB
-
@k_rus 谢谢你的回答。我已经读了很多遍了,但我找不到任何解决我的问题的方法
标签: indexing timescaledb