{"Entry":{"collection":"plan","key":"lockrows","name":"LockRows","aliases":["LockRows","T_LockRows"],"metadata":{"aliases":["LockRows","T_LockRows"],"category":"Control","content_hash":"799293bef5b0135fef7ebcbdb9c63a78774579c331cad7cd32c66101654d281b","derived_content_hash":"d08abe6941aee06162e9eae5dff12db29ef239a60e5d6552d46dd1386720ee7e","imported_at":"2026-09-30T00:40:44.086311+08:00","name":"LockRows","name_zh":"LockRows","slug":"lockrows","summary":"Locks rows selected by its child for row-locking clauses."}},"Definition":{"Collection":"plan","Key":"lockrows","SourceDatabase":"center","Version":"18","SourceTable":"plan_node","SourceKey":"lockrows","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"comparison_data":{"initializer":"ExecInitLockRows","memory_mechanism":"unclassified","node_tag":"T_LockRows","parallel_callbacks":[],"partial_modes":[],"strategies":[],"text_names":["LockRows"]},"comparison_hash":"67f9133563e6e17a1409787c4b2ae050edaccb9feed71e462118303f83324626","description":["Locks rows selected by its child for row-locking clauses."],"description_zh":"为行锁定子句锁定子计划选出的行。","description_zh_html":"\u003cp\u003e为行锁定子句锁定子计划选出的行。\u003c/p\u003e\u003cp\u003e核心节点标识：\u003ccode\u003eT_LockRows\u003c/code\u003e；EXPLAIN 名称：\u003ccode\u003eLockRows\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e本版本源码中的并行执行或观测回调：该节点实现中未提取到此类回调。回调的存在不表示该节点必然支持共享并行扫描；在并行工作进程中执行也不等于具有并行感知能力。\u003c/p\u003e\u003ch3\u003e同版本中文手册节选\u003c/h3\u003e\u003cp\u003e\n\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 会为收到的每个查询制定一个\u003cem class=\"firstterm\"\u003e查询计划\u003c/em\u003e。选择与查询结构和数据特性相匹配的正确计划，对获得良好的性能至关重要，因此系统内置了一个复杂的\u003cem class=\"firstterm\"\u003e规划器\u003c/em\u003e来尽量选出好的计划。可以使用 \u003ca class=\"link\" href=\"/zh/docs/18/sql-explain.html\"\u003e\u003ccode class=\"command\"\u003eEXPLAIN\u003c/code\u003e\u003c/a\u003e 命令查看规划器为任意查询生成的查询计划。读懂计划是一门需要经验积累的技能，本节将尝试介绍其中的基础知识。\n   \u003c/p\u003e\u003cp\u003e\n    本节中的示例取自执行过 \u003ccode class=\"command\"\u003eVACUUM ANALYZE\u003c/code\u003e 的回归测试数据库，使用的是 v18 开发版本源码。如果自行尝试这些示例，通常应当能得到相近的结果，但估计代价和行计数可能略有差异，因为 \u003ccode class=\"command\"\u003eANALYZE\u003c/code\u003e 生成的统计信息来自随机采样而非精确计数，而且代价本身在某种程度上也依赖于平台。\n   \u003c/p\u003e\u003cp\u003e\n    这些示例使用 \u003ccode class=\"command\"\u003eEXPLAIN\u003c/code\u003e 默认的\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003etext\u003c/span\u003e”\u003c/span\u003e输出格式，它紧凑且便于人工阅读。如果希望将 \u003ccode class=\"command\"\u003eEXPLAIN\u003c/code\u003e 的输出交给程序做进一步分析，则应改用机器可读的输出格式（XML、JSON 或 YAML）。\n   \u003c/p\u003e\u003cp\u003e\u003ca href=\"/zh/docs/18/using-explain.html\"\u003e查看完整中文手册与上下文\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e本页开头的中文说明为 PG.CENTER 对编辑说明的翻译；手册节选保留对应版本中文文档原文。源码信息及手册示例不代表重新进行过运行测试。\u003c/p\u003e","evidence_kind":"source and documentation","explain_names":["LockRows"],"explain_prefixes":["Parallel","Async"],"facts":[{"label":"Core node tag","value":"T_LockRows"},{"label":"Structured EXPLAIN Node Type","value":"LockRows"},{"label":"Inputs","value":"One child plan with row identity information"},{"label":"Output","value":"Locked qualifying tuples"},{"label":"Executor initializer","value":"ExecInitLockRows"},{"label":"Memory mechanism","value":"unclassified"}],"facts_zh":[{"label":"核心节点标签","value":"T_LockRows"},{"label":"结构化 EXPLAIN 节点类型","value":"LockRows"},{"label":"输入","value":"一个带行身份信息的子计划"},{"label":"输出","value":"已加锁且满足条件的元组"},{"label":"执行器初始化函数","value":"ExecInitLockRows"},{"label":"内存机制","value":"unclassified"}],"memory":{"description":"This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider.","evidence":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeLockRows.c","path":"src/backend/executor/nodeLockRows.c","sha256":"a6a30b944beee0590bdabee0ac2571bc1beb231a492df06c19017217daed357f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"mechanism":"unclassified","source_notes":[]},"node_tag":"T_LockRows","parallel_callbacks":[],"partial_modes":[],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"Row locks","url":"/wiki/lock/?v=18"}],"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"runtime_verified":false,"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: LockRows.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: none extracted from this node implementation."],"title":"Parallel execution and instrumentation"},{"paragraphs":["nodeLockRows.c Routines to handle FOR UPDATE/FOR SHARE row locking","We don't need EvalPlanQual unless we get updated tuple version(s)","Attempt to lock the source tuple(s). (Note we only have locking rowmarks in lr_arowMarks.)","if FDW says tuple was updated before getting locked, we need to perform EPQ testing to see if quals are still satisfied","The target tuple was already updated or deleted by the current command, or by a later command in the current transaction. We *must* ignore the tuple in the former case, so as to avoid the \"Halloween problem\" of repeated update attempts. In the latter case it might be sensible to fetch the updated tuple instead, but doing so would require changing heap_update and heap_delete to not complain about updating \"invisible\" tuples, which seems pretty scary (table_tuple_lock will not complain, but few callers expect TM_Invisible, and we're not one of them). So for now, treat the tuple as deleted and do not process."],"title":"Executor implementation notes"},{"code":"case T_LockRows:\n\t\t\tpname = sname = \"LockRows\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"sections_zh":[{"paragraphs":["结构化格式使用上述 Node Type。文本格式名称还可能包含操作、策略、连接类型、扫描方向或聚合阶段属性。","此源码记录的文本名称：LockRows.","并行感知与并行安全是不同的计划属性。在并行工作进程内运行的节点不一定是并行感知节点。"],"title":"EXPLAIN 名称与属性"},{"paragraphs":["本次抽取不为此节点设定统一的内存上限或落盘策略。请查看同一构建的实现、相关表达式或提供方。"],"title":"内存与临时存储"},{"paragraphs":["以下源码回调可以协调执行或收集工作进程的测量数据。回调存在不代表该节点普遍支持共享并行扫描或共享状态。","此构建的回调：none extracted from this node implementation."],"title":"并行执行与运行信息采集"},{"paragraphs":["nodeLockRows.c：处理 FOR UPDATE/FOR SHARE 行锁的例程。","除非取得更新后的元组版本，否则无需执行 EvalPlanQual。","尝试锁定源元组。（注意，lr_arowMarks 中仅包含需要加锁的行标记。）","如果 FDW 表示元组在加锁之前已被更新，则需要执行 EPQ 检查，确认条件仍然满足。","目标元组已被当前命令，或同一事务中的后续命令更新或删除。前一种情况必须忽略该元组，以避免重复更新的“万圣节问题”。后一种情况或许可以获取更新后的元组，但这需要修改 heap_update 和 heap_delete，使它们不再对更新“不可见”元组报错，风险很大（table_tuple_lock 不会报错，但很少有调用者预期收到 TM_Invisible，这里也不例外）。因此目前将该元组视为已删除，不予处理。"],"title":"执行器实现说明"},{"code":"case T_LockRows:\n\t\t\tpname = sname = \"LockRows\";\n\t\t\tbreak;","title":"核心源码中的 EXPLAIN 标识"}],"source_inventory":{"executor":"src/backend/executor/execProcnode.c","explain":"src/backend/commands/explain.c","implementation":"src/backend/executor/nodeLockRows.c"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1598","line":1598,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:375","line":375,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeLockRows.c","path":"src/backend/executor/nodeLockRows.c","sha256":"a6a30b944beee0590bdabee0ac2571bc1beb231a492df06c19017217daed357f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"strategies":[],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"LockRows","label":"LockRows"}],"title":"EXPLAIN labels in this source build"}],"tables_zh":[{"columns":[{"key":"label","label":"文本格式标签"},{"key":"identity","label":"结构化节点标识"}],"key":"explain-labels","rows":[{"identity":"LockRows","label":"LockRows"}],"title":"本构建中的 EXPLAIN 标签"}],"zh_from":{"authored_translation":"authored-translation-of-reviewed-guidance","body_sha256":"54f19106a81bb8b3be6974b3b9266eb980192ec235666779f397f01bb272d38e","kind":"same-version-chinese-manual-with-authored-translation-of-reviewed-guidance","manual":{"anchor":"","build_id":107,"extraction":"concept-introduction","fragment_sha256":"15fbdf84b8f499253ade4f4a5841de138619a9933b93cc241d431dbe922fa40c","locale":"zh-Hans","page_key":"using-explain.html","source_hash":"d2f749744b3ac5aa2eb0154f295e8163903cd20fcc130c74c6172cdf2ae3a9df","source_revision":"unknown:rendered-translation-baseline","translated_from_revision":null,"translation_revision":"git:b1b500221dbe5437cfca004d6b04d3f6e422765d;html-sha256:08e987a66af27b98444a8057c256314eafa13611a3fb9e888214fc436824244b","url":"/zh/docs/18/using-explain.html","version":"18"},"runtime_rerun":false,"source_facts_revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}},"ManualEvidence":{"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1598","line":1598,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:375","line":375,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeLockRows.c","path":"src/backend/executor/nodeLockRows.c","sha256":"a6a30b944beee0590bdabee0ac2571bc1beb231a492df06c19017217daed357f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"MeasuredEvidence":{"runtime_verified":false}},"Text":{"Collection":"plan","Key":"lockrows","SourceDatabase":"center","Version":"18","Locale":"en","Title":"LockRows","Summary":"Locks rows selected by its child for row-locking clauses.","BodyHTML":"\u003cp\u003eLocks rows selected by its child for row-locking clauses.\u003c/p\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"2318efa9a57e3ec98af079490de95e4c5c09f90fdc9278378172c53493d15456","Payload":{"description":["Locks rows selected by its child for row-locking clauses."],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"Row locks","url":"/wiki/lock/?v=18"}],"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: LockRows.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: none extracted from this node implementation."],"title":"Parallel execution and instrumentation"},{"paragraphs":["nodeLockRows.c Routines to handle FOR UPDATE/FOR SHARE row locking","We don't need EvalPlanQual unless we get updated tuple version(s)","Attempt to lock the source tuple(s). (Note we only have locking rowmarks in lr_arowMarks.)","if FDW says tuple was updated before getting locked, we need to perform EPQ testing to see if quals are still satisfied","The target tuple was already updated or deleted by the current command, or by a later command in the current transaction. We *must* ignore the tuple in the former case, so as to avoid the \"Halloween problem\" of repeated update attempts. In the latter case it might be sensible to fetch the updated tuple instead, but doing so would require changing heap_update and heap_delete to not complain about updating \"invisible\" tuples, which seems pretty scary (table_tuple_lock will not complain, but few callers expect TM_Invisible, and we're not one of them). So for now, treat the tuple as deleted and do not process."],"title":"Executor implementation notes"},{"code":"case T_LockRows:\n\t\t\tpname = sname = \"LockRows\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"LockRows","label":"LockRows"}],"title":"EXPLAIN labels in this source build"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
