我注意到我的代码中有以下查询,并想检查这是否可以优化。
UPDATE table as T1 SET C1=?
FROM
(SELECT C2, C3, C4
FROM table
WHERE C1=? and current_timestamp >= C5
ORDER BY C5 limit ? FOR UPDATE
) AS T2
WHERE T1.C2 = T2.C2 AND T1.C3 = T2.C3 AND T1.C4 = T2.C4
RETURNING *;
C2、C3 上的索引
在 C5 上分区
桌子 :
C1、C2、C3 - varchar
C4、C5 - 时间戳