Skip to content

Commit ecbd125

Browse files
committed
lock only distinct
1 parent d444626 commit ecbd125

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

pkg/repository/sqlcv1/olap.sql

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ WITH tenants AS (
788788
worker_id IS NOT NULL
789789
GROUP BY
790790
tenant_id, task_id, task_inserted_at, retry_count
791-
), locked_tasks AS (
792-
SELECT
791+
), distinct_tasks_to_lock AS (
792+
SELECT DISTINCT ON (t.tenant_id, t.id, t.inserted_at)
793793
t.tenant_id,
794794
t.id,
795795
t.inserted_at,
@@ -801,9 +801,18 @@ WITH tenants AS (
801801
JOIN
802802
updatable_events e ON
803803
(t.tenant_id, t.id, t.inserted_at) = (e.tenant_id, e.task_id, e.task_inserted_at)
804-
WHERE t.inserted_at >= @minInsertedAt::TIMESTAMPTZ
804+
WHERE
805+
t.inserted_at >= @minInsertedAt::TIMESTAMPTZ
805806
ORDER BY
806-
t.inserted_at, t.id
807+
t.tenant_id, t.id, t.inserted_at, t.readable_status
808+
), locked_tasks AS (
809+
SELECT
810+
dt.*
811+
FROM
812+
v1_tasks_olap t
813+
JOIN
814+
distinct_tasks_to_lock dt ON
815+
(dt.inserted_at, dt.id) = (t.inserted_at, t.id)
807816
FOR UPDATE
808817
), already_in_target_partition AS (
809818
-- Check if rows already exist in the target partition (with the new readable_status)

pkg/repository/sqlcv1/olap.sql.go

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)