fix deadlock

This commit is contained in:
etreschenkov 2026-02-09 16:27:56 +03:00
parent 46ff036c38
commit 8df92fde73

View file

@ -139,21 +139,55 @@
</select>
<update id="updateIdCachedData" parameterType="string">
update signals_phones_map dst
set ser_num = src.ser_num,
id_type = src.id_type
WITH src AS (SELECT DISTINCT ON (phone) phone,
ser_num,
id_type
FROM json_to_recordset(#{json}::json) AS src(
phone bigint,
ser_num varchar(255),
id_type varchar(255)
)
where dst.phone = src.phone;
order by phone),
to_lock AS (select dst.id
from signals_phones_map dst
join src on src.phone = dst.phone
order by dst.phone
for update)
update signals_phones_map dst
set ser_num = src.ser_num,
id_type = src.id_type
FROM src
where dst.phone = src.phone
AND dst.id in (select id from to_lock);
</update>
<update id="updateNameCachedData" parameterType="string">
WITH src AS (SELECT DISTINCT ON (phone) fid,
phone,
name_1,
first,
middle,
birth_dt
FROM json_to_recordset(#{json}::json) AS src(
fid int,
phone bigint,
name_1 varchar(255),
first varchar(255),
middle varchar(255),
birth_dt timestamp
)
order by phone),
to_lock AS (select dst.id
from signals_phones_map dst
join src on src.phone = dst.phone
order by dst.phone
for update)
update signals_phones_map dst
set
fid = src.fid,
set fid = src.fid,
name_1 = src.name_1,
first = src.first,
middle = src.middle,
@ -167,10 +201,26 @@
middle varchar(255),
birth_dt timestamp
)
where dst.phone = src.phone;
where dst.phone = src.phone
AND dst.id in (select id from to_lock);
</update>
<update id="updateFlagCachedData" parameterType="string">
WITH src AS (SELECT DISTINCT ON (phone) phone,
flag_debt5000,
flag_90_12
FROM json_to_recordset(#{json}::json) AS src(
phone bigint,
flag_debt5000 smallint,
flag_90_12 smallint
)
order by phone),
to_lock AS (select dst.id
from signals_phones_map dst
join src on src.phone = dst.phone
order by dst.phone
for update)
update signals_phones_map dst
set flag_debt5000 = src.flag_debt5000,
flag_90_12 = src.flag_90_12,
@ -180,7 +230,8 @@
flag_debt5000 smallint,
flag_90_12 smallint
)
where dst.phone = src.phone;
where dst.phone = src.phone
AND dst.id in (select id from to_lock);
</update>
<update id="setFidJson" parameterType="string">