final class Locking
Restricted visibility: declared "@visibility SqlSemantics\Platform\PostgreSql". Code outside that scope must not name this declaration.

Checks which FROM items a locking clause can lock.

Rule: PG-LOCKING-TARGET-001. Scope: the locking clauses of a selection. A clause with OF locks the named FROM items; a named join, function, table function or WITH query cannot be locked ("FOR UPDATE cannot be

  • applied to a join" and the like). A clause without OF locks every table

of the FROM clause and skips the items that cannot be locked. A table on the nullable side of an outer join (the right side of LEFT, the left side of RIGHT, both sides of FULL) cannot be locked. Reference to a WITH query is told from a table by resolving its name where the selection stands. Every table of the FROM clause of a query with a locking clause gets a row mark: a declared sequence is reported (cannot lock rows in sequence), and so is a declared materialized view a clause locks (PG-RELATION-KIND-001, CheckValidRowMarkRel in execMain.c). Source: https://www.postgresql.org/docs/17/sql-select.html#SQL-FOR-UPDATE-SHARE, transformLockingClause in src/backend/parser/analyze.c and make_outerjoininfo in src/backend/optimizer/plan/initsplan.c of PostgreSQL 17. Termination: one walk over the FROM tree per clause. Status: Implemented.

Methods§

public function check(
    list<LockingClause> $clauses,
    list<VisibleRelation> $visible,
    Relation|null $from,
    Derivation $derivation,
    Environment $base,
): void

Reports the FROM items the locking clauses name or cover that cannot be locked.

Parameters

$clauseslist<LockingClause>
$visiblelist<VisibleRelation>The relations of the FROM items of the query
$fromRelation|nullThe FROM clause of the query
$derivationDerivation
$baseEnvironmentThe environment the query stands in, which holds its WITH queries
Called from 1
Calls 11
public function kinds(
    list<TableInput> $tables,
    list<TableInput> $locked,
    Derivation $derivation,
    Environment $base,
): void

Reports the tables of a query with row marks whose declared kind cannot be marked.

Every table of the FROM clause of a query that locks rows, or of the FROM or USING clause of UPDATE, DELETE and MERGE, gets a row mark, even one no clause locks; a sequence cannot have one. A materialized view can be referenced but not locked.

Parameters

$tableslist<TableInput>The tables of the FROM clause
$lockedlist<TableInput>The tables the locking clauses lock
$derivationDerivation
$baseEnvironment
Called from 2
Calls 9
public function named(
    list<VisibleRelation> $visible,
    Name $name,
    Derivation $derivation,
): ?Relation

Answers the FROM item an unqualified name of a locking clause denotes, or null when no item has the name.

Parameters

$visiblelist<VisibleRelation>
$nameName
$derivationDerivation

Returns

Test cases 1
Called from 1
Calls 4

Test cases 3§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 3

Relations§

Instantiated in 2
Method calls 3