Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
feat(schema): invert metrics view to start with labels, add (name, ti…
Browse files Browse the repository at this point in the history
…me) index to samples
  • Loading branch information
ssube committed Nov 29, 2019
1 parent 581764d commit 9034a0d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions schema/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ SELECT create_hypertable(

SELECT set_chunk_time_interval('metric_samples', INTERVAL '1 hour');

CREATE INDEX IF NOT EXISTS metric_samples_name_lid_time ON metric_samples USING BTREE (name, lid, time DESC);
CREATE INDEX IF NOT EXISTS metric_samples_lid_time ON metric_samples USING BTREE (lid, time DESC);
CREATE INDEX IF NOT EXISTS metric_samples_name_time ON metric_samples USING BTREE (name, time DESC);
-- this index is only used for caggs and causes 2x write amplification
-- CREATE INDEX IF NOT EXISTS metric_samples_name_lid_time ON metric_samples USING BTREE (name, lid, time DESC);

-- samples compression
ALTER TABLE metric_samples
Expand All @@ -51,10 +54,12 @@ SELECT add_compress_chunks_policy(
CREATE OR REPLACE VIEW metrics AS
SELECT
s.time,
s.name,
l.labels->>'__name__' AS name,
s.lid,
s.value,
l.labels
FROM metric_samples AS s
JOIN metric_labels AS l ON s.lid = l.lid
WHERE s.time > NOW() - INTERVAL :retain_live; -- maximum time range for high-resolution queries
FROM metric_labels AS l
JOIN metric_samples AS s
ON s.lid = l.lid
WHERE
s.time > NOW() - INTERVAL :retain_live; -- maximum time range for high-resolution queries

0 comments on commit 9034a0d

Please sign in to comment.