Severe performance degradation with concurrent updates due to excessive EvalPlanQual (EPQ) re‑evaluation

From: Wei Sun <936739278(at)qq(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Severe performance degradation with concurrent updates due to excessive EvalPlanQual (EPQ) re‑evaluation
Date: 2026-09-15 08:05:46
Message-ID: tencent_99512A59217723920605D8E93FA95EAA0608@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,
      
I encountered a serious performance regression when running concurrent
UPDATE statements targeting the same set of rows on PostgreSQL 18.1.
The second update session runs extremely slow due to excessive
EvalPlanQual (EPQ) re‑evaluation logic.

## Test setup
Create test table and populate 1000000 rows of mock bond trading data,
no user‑defined indexes (only identity primary key on `id`).
Then create a copy table `bond_deal_detail_sw` for concurrent update tests.
This issue occurs when read committed isolation level.

```sql
DROP TABLE IF EXISTS bond_deal_detail;
CREATE TABLE bond_deal_detail (
&nbsp; &nbsp; id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
&nbsp; &nbsp; deal_no TEXT,
&nbsp; &nbsp; bond_code TEXT,
&nbsp; &nbsp; bond_name TEXT,
&nbsp; &nbsp; trade_date DATE,
&nbsp; &nbsp; trade_time TIME,
&nbsp; &nbsp; buy_inst TEXT,
&nbsp; &nbsp; sell_inst TEXT,
&nbsp; &nbsp; deal_amt NUMERIC(20,4),
&nbsp; &nbsp; deal_price NUMERIC(12,6),
&nbsp; &nbsp; yield_rate NUMERIC(10,6),
&nbsp; &nbsp; trade_type TEXT,
&nbsp; &nbsp; settle_date DATE,
&nbsp; &nbsp; create_at TIMESTAMP
);

INSERT INTO bond_deal_detail(
&nbsp; &nbsp; deal_no, bond_code, bond_name, trade_date, trade_time,
&nbsp; &nbsp; buy_inst, sell_inst, deal_amt, deal_price, yield_rate,
&nbsp; &nbsp; trade_type, settle_date, create_at
)
SELECT
&nbsp; &nbsp; 'DEAL' || LPAD(i::TEXT,10,'0'),
&nbsp; &nbsp; '10' || LPAD((i % 99999)::TEXT,8,'0'),
&nbsp; &nbsp; 'SimBond_' || (i % 2000),
&nbsp; &nbsp; '2025-01-01'::DATE + (i % 365),
&nbsp; &nbsp; ('09:00:00'::TIME + (i % 32400) * INTERVAL '1 second'),
&nbsp; &nbsp; 'Inst_' || (i % 1500),
&nbsp; &nbsp; 'Inst_' || ((i + 777) % 1500),
&nbsp; &nbsp; (random() * 500000000)::NUMERIC(20,4),
&nbsp; &nbsp; (90 + random() * 20)::NUMERIC(12,6),
&nbsp; &nbsp; (1.5 + random() * 3.5)::NUMERIC(10,6),
&nbsp; &nbsp; CASE WHEN i % 5 = 0 THEN 'Repo' ELSE 'SpotBond' END,
&nbsp; &nbsp; '2025-01-01'::DATE + (i % 365) + (CASE WHEN i%5=0 THEN 1 ELSE 0 END),
&nbsp; &nbsp; NOW()
FROM generate_series(1,1000000) AS t(i);

-- create working table for concurrent update
CREATE TABLE bond_deal_detail_sw(LIKE bond_deal_detail);
INSERT INTO bond_deal_detail_sw SELECT * FROM bond_deal_detail;

## Concurrent reproduction steps

Open two independent sessions and run below UPDATE SQL
simultaneously against table `bond_deal_detail_sw`.
Both queries try to update the same top‑100 000 rows derived
from the source table `bond_deal_detail`.

Session 1:
EXPLAIN ANALYZE UPDATE bond_deal_detail_sw
SET deal_price = 26915
WHERE deal_no IN (SELECT deal_no FROM bond_deal_detail ORDER BY deal_no LIMIT 100000);

Session 2 (run concurrently with session 1):
EXPLAIN ANALYZE UPDATE bond_deal_detail_sw
SET deal_price = 26915
WHERE deal_no IN (SELECT deal_no FROM bond_deal_detail ORDER BY deal_no LIMIT 100000);

1. Session 1 executes quickly, it locks and updates those 100 000 target rows.
2. Session 2 blocks waiting for row‑level locks. After session 1 commits,
session 2 resumes execution but becomes extremely slow.
3. From execution plan and trace, the slowdown comes from massive EvalPlanQual (EPQ) re‑evaluation:
for each row already modified and committed by transaction 1,
PostgreSQL fetches the new tuple version and re‑evaluates the whole sub‑query / qual tree for EPQ.
Even though the new value of `deal_price` is a constant literal (`SET deal_price = 26915`)
and does not depend on original row values, heavy EPQ overhead still occurs for every conflicting row.

since the target update value is a constant and does not reference any column of the updated table,
logically there is no need to recompute the target new value via EPQ for these rows.
But PostgreSQL still triggers full EPQ re‑evaluation for every updated tuple,
leading to huge overhead and long elapsed time for the second concurrent transaction.

Expectation / question
When the updated assignment is pure constant and does not reference
any columns from the target relation, could PostgreSQL skip the expensive EPQ re‑computation
for the new target value, even though it still needs to check row visibility and tuple versions?

Best regards,&nbsp;
Wei Sun

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message ChenhuiMo 2026-09-15 08:06:31 Re: [PATCH] Speed up repeat() for larger counts
Previous Message Peter Eisentraut 2026-09-15 08:03:57 Re: fix more casting away of qualifiers