PostgreSQL 当前执行查找可以扫描使用通用计划的以前运行
作者: ali-khokhar-nvidia创建于 2026年9月16日更新于 2026年9月16日
Synthetic SQL reproduction
INSERT INTO executions
SELECT i%512, decode(repeat('01',16),'hex'), 'single-use-'||i,
decode(lpad(to_hex(i),32,'0'),'hex'), 2, 1,
decode(repeat(md5(i::text),32),'hex'), 'Proto3', decode('01','hex'), 'Proto3', 1
FROM generate_series(1,100000) AS i;
INSERT INTO executions
SELECT 7, decode(repeat('01',16),'hex'), 'recurring-workflow',
decode(lpad(to_hex(i),32,'0'),'hex'), 2, 1,
decode(repeat(md5(i::text),32),'hex'), 'Proto3', decode('01','hex'), 'Proto3', 1
FROM generate_series(1,30000) AS i;
INSERT INTO current_executions
(shard_id, namespace_id, workflow_id, run_id, create_request_id, state, status,
start_time, last_write_version, data, data_encoding)
SELECT shard_id, namespace_id, workflow_id, run_id, 'request', 2, 1,
now(), last_write_version, state, state_encoding
FROM executions
WHERE workflow_id LIKE 'single-use-%'
OR run_id=decode(lpad(to_hex(30000),32,'0'),'hex');
ANALYZE executions;
ANALYZE current_executions;
PREPARE current_execution AS
SELECT ce.shard_id, ce.namespace_id, ce.workflow_id, ce.run_id,
ce.create_request_id, ce.state, ce.status, ce.start_time,
e.last_write_version, ce.data, ce.data_encoding
FROM current_executions ce
INNER JOIN executions e
ON e.shard_id=ce.shard_id AND e.namespace_id=ce.namespace_id
AND e.workflow_id=ce.workflow_id AND e.run_id=ce.run_id
WHERE ce.shard_id=$1 AND ce.namespace_id=$2 AND ce.workflow_id=$3
FOR UPDATE;
SET plan_cache_mode=force_generic_plan;
EXPLAIN (ANALYZE, BUFFERS) EXECUTE current_execution(
7,
…
内容来源: temporalio/temporal