Skip to content

Commit

Permalink
feat(jdbc): improve JDBC PostgreSQL queues queries performance (#1883)
Browse files Browse the repository at this point in the history
close #1121
  • Loading branch information
loicmathieu authored Aug 17, 2023
1 parent 23faaa8 commit a6b28d6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions jdbc-h2/src/main/resources/migrations/h2/V18__index_logs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP INDEX logs_namespace;
DROP INDEX logs_timestamp;
CREATE INDEX logs_namespace_flow ON logs ("deleted", "timestamp", "level", "namespace", "flow_id");

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Recreate the queues_type__* indexes by adding the offset column otherwise the index is not used as we order on offset.
-- Also make them partial to lower the index size.
DROP INDEX queues_type__consumer_flow_topology;
DROP INDEX queues_type__consumer_indexer;
DROP INDEX queues_type__consumer_executor;
DROP INDEX queues_type__consumer_worker;
DROP INDEX queues_type__consumer_scheduler;

CREATE INDEX queues_type__consumer_flow_topology ON queues (type, consumer_flow_topology, "offset") WHERE consumer_flow_topology = false;
CREATE INDEX queues_type__consumer_indexer ON queues (type, consumer_indexer, "offset") WHERE consumer_indexer = false;
CREATE INDEX queues_type__consumer_executor ON queues (type, consumer_executor, "offset") WHERE consumer_executor = false;
CREATE INDEX queues_type__consumer_worker ON queues (type, consumer_worker, "offset") WHERE consumer_worker = false;
CREATE INDEX queues_type__consumer_scheduler ON queues (type, consumer_scheduler, "offset") WHERE consumer_scheduler = false;

-- Go back to the original PK and queues_offset__type as they are useful for offset based poll and updates
DO $$
BEGIN
IF NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'queues' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE queues ADD PRIMARY KEY("offset");
END IF;
END;
$$;
DROP INDEX IF EXISTS queues_offset;
CREATE INDEX IF NOT EXISTS queues_type__offset ON queues (type, "offset");

0 comments on commit a6b28d6

Please sign in to comment.