classLocking
final class Locking
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,
): voidReports the FROM items the locking clauses name or cover that cannot be locked.
Parameters
$clauses | list<LockingClause> | |
$visible | list<VisibleRelation> | The relations of the FROM items of the query |
$from | Relation|null | The FROM clause of the query |
$derivation | Derivation | |
$base | Environment | The environment the query stands in, which holds its WITH queries |
Called from 1
Calls 11
- method-call Locking::tables() line 65
- new Name line 68
- method-call Locking::named() line 71
- method-call Locking::refused() line 72
- method-call Derivation::report() line 74
- new QueryMisuse line 74
- function-call
array_columnline 79 - function-call
in_arrayline 80 - class-const QueryMisuseRule::LockingNullableSide() line 81
- function-call
array_pushline 85 - method-call Locking::kinds() line 88
public function kinds(
list<TableInput> $tables,
list<TableInput> $locked,
Derivation $derivation,
Environment $base,
): voidReports 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
$tables | list<TableInput> | The tables of the FROM clause |
$locked | list<TableInput> | The tables the locking clauses lock |
$derivation | Derivation | |
$base | Environment |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ModificationScope::inputs() packages/sql-semantics-postgres/src/Rules/Manipulation/ModificationScope.php:69
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Locking::check() packages/sql-semantics-postgres/src/Rules/Query/Locking.php:88
Calls 9
- new RelationKinds line 105
- method-call RelationKinds::declared() line 107
- class-const RelationKind::Sequence() line 108
- method-call Derivation::report() line 109
- new KindProblem line 109
- class-const KindRule::LockSequenceRows() line 109
- class-const RelationKind::MaterializedView() line 110
- function-call
in_arrayline 110 - class-const KindRule::LockMaterializedViewRows() line 111
public function named(
list<VisibleRelation> $visible,
Name $name,
Derivation $derivation,
): ?RelationAnswers the FROM item an unqualified name of a locking clause denotes, or null when no item has the name.
Parameters
$visible | list<VisibleRelation> | |
$name | Name | |
$derivation | Derivation |
Returns
Test cases 1
Called from 1
Calls 4
- new Environment line 123
- method-call Visibility::admits() line 125
- new Visibility line 125
- new QualifiedName line 125
public function refused(
Relation $item,
Derivation $derivation,
Environment $base,
): ?QueryMisuseRuleAnswers the rule a FROM item breaks when it is named in a locking clause, or null when it can be locked.
Parameters
$item | Relation | |
$derivation | Derivation | |
$base | Environment |
Returns
Test cases 1
Called from 2
Calls 6
- class-const QueryMisuseRule::LockingOnJoin() line 139
- class-const QueryMisuseRule::LockingOnFunction() line 140
- class-const QueryMisuseRule::LockingOnTableFunction() line 141
- method-call Derivation::table() line 142
- method-call Relation::name() line 142
- class-const QueryMisuseRule::LockingOnCommonTable() line 142
public function tables(Relation $from, bool $nullable = false): list<array{TableInput, bool}>Answers the table references of a FROM clause, each with whether it is on the nullable side of an outer join; $nullable tells whether the clause itself is.
Parameters
$from | Relation | |
$nullable | bool |
Returns
list<array{TableInput, bool}>Test cases 1
Called from 6
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ModificationScope::inputs() packages/sql-semantics-postgres/src/Rules/Manipulation/ModificationScope.php:69
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Locking::check() packages/sql-semantics-postgres/src/Rules/Query/Locking.php:65
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Locking::tables() packages/sql-semantics-postgres/src/Rules/Query/Locking.php:156
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Locking::tables() packages/sql-semantics-postgres/src/Rules/Query/Locking.php:157
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Locking::tables() packages/sql-semantics-postgres/src/Rules/Query/Locking.php:159
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Locking::tables() packages/sql-semantics-postgres/src/Rules/Query/Locking.php:160
Calls 6
- method-call Locking::tables() line 156
- function-call
array_mergeline 157 - function-call
array_mapline 157 - class-const JoinKind::Right() line 159
- class-const JoinKind::Full() line 159
- class-const JoinKind::Left() line 160
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ModificationScope::inputs() packages/sql-semantics-postgres/src/Rules/Manipulation/ModificationScope.php:68
- new SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::options() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:128
Method calls 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ModificationScope::inputs() packages/sql-semantics-postgres/src/Rules/Manipulation/ModificationScope.php:69
- method-call SqlSemantics\Platform\PostgreSql\Rules\Manipulation\ModificationScope::inputs() packages/sql-semantics-postgres/src/Rules/Manipulation/ModificationScope.php:69
- method-call SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts::options() packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:128