【问题标题】:Timescale Compressed table taking forever for simple queries时间尺度压缩表永远用于简单查询
【发布时间】:2021-10-11 13:01:05
【问题描述】:

我有一个大约 4000 万行的超表。希望压缩它以减少我们的一些存储成本。在压缩之前,以下查询运行得非常快。

select * from trades where pair = 'xxxxxxxxx';

压缩后,此查询会挂起很长时间(30-40+s)

查看查询计划,似乎它正在解压缩每个块,然后检查该对是否存在,如果不存在则移动到下一个块。虽然它应该检查该对是否存在,如果存在则仅解压缩该块。

我已将 segementby 设置为配对,所以我不完全确定我缺少什么。

CREATE TABLE trades (
    "timestamp" timestamptz NOT NULL,
    tx varchar(255) NOT NULL,
    pair varchar(255) NOT NULL,
    price float8 NOT NULL,
    amount float8 NOT NULL
);

CREATE INDEX trades_pair_timestamp_idx ON public.trades USING btree (pair, "timestamp" DESC);

SELECT create_hypertable('trades', 'timestamp');

alter table trades set (
  timescaledb.compress, 
  timescaledb.compress_segmentby = 'pair',
  timescaledb.compress_orderby = 'timestamp');

SELECT add_compression_policy('trades', INTERVAL '1 week');

【问题讨论】:

  • 请注意,您的查询需要读取所有块,因为只能在时间列上排除块。仍然由于该列在 segmentby 中,因此不需要解压缩,@TDF 指出了一个错误,这可能是造成这种情况的原因。

标签: timescaledb


【解决方案1】:

您运行的是什么版本的 Timescaledb? There was a bug 与解压前未过滤的 varchar 字段相关,has been fixed in 2.3.1

【讨论】:

  • 我这辈子从来没有同时恨过和爱过一个人。一直在这上面花了几个小时。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-11
  • 2023-04-11
相关资源
最近更新 更多