Hi,
We’ve been experimenting with TimescaleDB, primarily on compression to address our disk space issues. However, we noticed an increase in query execution time after enabling compression.
SELECT
*
FROM
action_receipt_actions
WHERE
receipt_id = '5uTTiGqdqLKUFwo6WXTC1V8tM6PekW6gmDGaKrNPPfNz'
AND action_kind = 'FUNCTION_CALL'
AND args ->> 'method_name' = 'heartbeat';
# Postgresql table
Planning Time: 0.706 ms
Execution Time: 0.097 ms
# Hypertable with compression enabled
Planning Time: 33.903 ms
Execution Time: 1860.641 ms
Table schema:
CREATE TABLE "public"."action_receipt_actions" (
"receipt_id" text NOT NULL,
"index_in_action_receipt" integer NOT NULL,
"receipt_predecessor_account_id" text NOT NULL,
"receipt_receiver_account_id" text NOT NULL,
"receipt_included_in_block_timestamp" bigint NOT NULL,
"action_kind" action_kind NOT NULL,
"args" jsonb NOT NULL,
CONSTRAINT "action_receipt_actions_pkey" PRIMARY KEY ("receipt_id", "index_in_action_receipt")
) WITH (oids = false);
CREATE INDEX "action_receipt_actions_args_function_call_idx" ON "public"."action_receipt_actions" USING btree ("");
CREATE INDEX "action_receipt_actions_receipt_id_args_function_call_idx" ON "public"."action_receipt_actions" USING btree ("receipt_id", "");
CREATE INDEX "action_receipt_actions_receipt_included_in_block_timestamp_idx" ON "public"."action_receipt_actions" USING btree ("receipt_included_in_block_timestamp" DESC);
Queries used for creating the hypertable & setting the compression policy:
SELECT
create_hypertable(
'action_receipt_actions',
'receipt_included_in_block_timestamp',
migrate_data = > true,
chunk_time_interval = > 604800000000000
);
ALTER TABLE
action_receipt_actions_hypertable_chunk
SET
(timescaledb.compress);
SELECT
add_compression_policy(
'action_receipt_actions',
BIGINT '604800000000000'
);
Query execution plan:
QUERY PLAN
Append (cost=0.04..64086.09 rows=12709000 width=14) (actual time=0.470..1859.661 rows=1 loops=1)
Buffers: shared hit=276533 read=28627
I/O Timings: shared/local read=153.380
-> Custom Scan (DecompressChunk) on _timescaledb_internal._hyper_3_25_chunk (cost=0.04..12.90 rows=290000 width=10) (actual time=0.149..0.150 rows=0 loops=1)
Output: _hyper_3_25_chunk.receipt_receiver_account_id
Filter: ((_hyper_3_25_chunk.receipt_id = '5uTTiGqdqLKUFwo6WXTC1V8tM6PekW6gmDGaKrNPPfNz'::text) AND (_hyper_3_25_chunk.action_kind = 'FUNCTION_CALL'::action_kind) AND ((_hyper_3_25_chunk.args ->> 'method_name'::text) = 'heartbeat'::text))
Rows Removed by Filter: 42
Buffers: shared hit=34
-> Seq Scan on _timescaledb_internal.compress_hyper_5_69_chunk (cost=0.00..12.90 rows=290 width=132) (actual time=0.008..0.009 rows=1 loops=1)
Output: compress_hyper_5_69_chunk.receipt_id, compress_hyper_5_69_chunk.index_in_action_receipt, compress_hyper_5_69_chunk.receipt_predecessor_account_id, compress_hyper_5_69_chunk.receipt_receiver_account_id, compress_hyper_5_69_chunk.receipt_included_in_block_timestamp, compress_hyper_5_69_chunk.action_kind, compress_hyper_5_69_chunk.args, compress_hyper_5_69_chunk._ts_meta_count, compress_hyper_5_69_chunk._ts_meta_sequence_num, compress_hyper_5_69_chunk._ts_meta_min_1, compress_hyper_5_69_chunk._ts_meta_max_1
Buffers: shared hit=1
...
-> Custom Scan (DecompressChunk) on _timescaledb_internal._hyper_3_68_chunk (cost=0.03..7.13 rows=213000 width=18) (actual time=132.736..132.736 rows=0 loops=1)
Output: _hyper_3_68_chunk.receipt_receiver_account_id
Filter: ((_hyper_3_68_chunk.receipt_id = '5uTTiGqdqLKUFwo6WXTC1V8tM6PekW6gmDGaKrNPPfNz'::text) AND (_hyper_3_68_chunk.action_kind = 'FUNCTION_CALL'::action_kind) AND ((_hyper_3_68_chunk.args ->> 'method_name'::text) = 'heartbeat'::text))
Rows Removed by Filter: 212419
Buffers: shared hit=24692
-> Seq Scan on _timescaledb_internal.compress_hyper_5_112_chunk (cost=0.00..7.13 rows=213 width=132) (actual time=0.010..0.087 rows=213 loops=1)
Output: compress_hyper_5_112_chunk.receipt_id, compress_hyper_5_112_chunk.index_in_action_receipt, compress_hyper_5_112_chunk.receipt_predecessor_account_id, compress_hyper_5_112_chunk.receipt_receiver_account_id, compress_hyper_5_112_chunk.receipt_included_in_block_timestamp, compress_hyper_5_112_chunk.action_kind, compress_hyper_5_112_chunk.args, compress_hyper_5_112_chunk._ts_meta_count, compress_hyper_5_112_chunk._ts_meta_sequence_num, compress_hyper_5_112_chunk._ts_meta_min_1, compress_hyper_5_112_chunk._ts_meta_max_1
Buffers: shared hit=5
Query Identifier: -1707176995114799452
Planning:
Buffers: shared hit=12972 dirtied=1
Planning Time: 33.903 ms
Execution Time: 1860.641 ms
We noticed the decompression of chunks from the execution plan. Is that a problem? Does anyone have any suggestions on how to address this?
Regards,
Sarin