Skip to content

Commit

Permalink
small improvements to real time queries
Browse files Browse the repository at this point in the history
  • Loading branch information
abelanger5 committed Feb 2, 2025
1 parent bad8ee8 commit fff16f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/repository/v2/timescalev2/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ WITH relevant_events AS (
tenant_id = @tenantId::uuid
AND inserted_at >= @insertedAfter::timestamptz
-- TODO: MORE FILTERS HERE
-- NOTE: we can limit in this CTE when there are no filters
LIMIT COALESCE(sqlc.narg('limit')::integer, 50)
), unique_tasks AS (
SELECT
tenant_id,
Expand Down Expand Up @@ -188,8 +190,7 @@ SELECT
max(retry_count)::integer AS max_retry_count
FROM all_task_events
GROUP BY tenant_id, task_id, task_inserted_at
ORDER BY task_inserted_at DESC, task_id DESC
LIMIT COALESCE(sqlc.narg('limit')::integer, 50);
ORDER BY task_inserted_at DESC, task_id DESC;

-- name: ListTasksFromAggregate :many
SELECT
Expand Down
11 changes: 6 additions & 5 deletions pkg/repository/v2/timescalev2/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sql/schema/timescale.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ CREATE INDEX v2_task_events_olap_task_id_idx ON v2_task_events_olap (task_id);

SELECT * from create_hypertable('v2_task_events_olap', by_range('task_inserted_at', INTERVAL '1 day'));

SET timescaledb.enable_chunk_skipping = on;

SELECT enable_chunk_skipping('v2_task_events_olap', 'inserted_at');

CREATE MATERIALIZED VIEW v2_cagg_task_status
Expand Down

0 comments on commit fff16f2

Please sign in to comment.