Add support for doing late row locking in FDWs

Enterprise / PostgreSQL - Tom Lane [sss.pgh.pa.us] - 12 May 2015 13:10 UTC

Previously, FDWs could only do "early row locking", that is lock a row as soon as it's fetched, even though local restriction/join conditions might discard the row later. This patch adds callbacks that allow FDWs to do late locking in the same way that it's done for regular tables.

To make use of this feature, an FDW must support the "ctid" column as a unique row identifier. Currently, since ctid has to be of type TID, the feature is of limited use, though in principle it could be used by postgres_fdw. We may eventually allow FDWs to specify another data type for ctid, which would make it possible for more FDWs to use this feature.

This commit does not modify postgres_fdw to use late locking. We've tested some prototype code for that, but it's not in committable shape, and besides it's quite unclear whether it actually makes sense to do late locking against a remote server. The extra round trips required are likely to outweigh any benefit from improved concurrency.

Etsuro Fujita, reviewed by Ashutosh Bapat, and hacked up a lot by me

afb9249 Add support for doing late row locking in FDWs.
doc/src/sgml/fdwhandler.sgml | 232 +++++++++++++++++++++++++++++---
src/backend/executor/execMain.c | 79 ++++++++---
src/backend/executor/execUtils.c | 17 +--
src/backend/executor/nodeLockRows.c | 133 ++++++++++++------
src/backend/executor/nodeModifyTable.c | 2 +-
src/backend/optimizer/plan/planner.c | 8 +-
src/include/executor/executor.h | 2 +-
src/include/foreign/fdwapi.h | 12 ++
src/include/nodes/execnodes.h | 12 +-
src/include/nodes/plannodes.h | 31 +++--
10 files changed, 415 insertions(+), 113 deletions(-)

Upstream: git.postgresql.org


  • Share