| Goal | This query identifies performance and concurrency bottlenecks caused by excessive locking. It flags INSERT, UPDATE, or DELETE statements that utilize subqueries containing the FOR UPDATE clause. Using FOR UPDATE acquires an exclusive lock, which is semantically inappropriate if the rows in the subquery are merely being read for reference or validation rather than being modified. This practice degrades system concurrency by unnecessarily blocking other transactions. |
|---|---|
| Notes | A subquery can be in the WHERE clause or in a common table expression (WITH clause). In the returned body of routine the query replaces each newline character with the line break (br) tag for the better readability in case the query result is displayed in a web browser. Similarly FOR UPDATE is placed between and tags. |
| Type | Problem detection (Each row in the result could represent a flaw in the design) |
| Reliability | Medium (Medium number of false-positive results) |
| License | MIT (opens in new tab) |
| Fixing Suggestion | A weaker lock mode, such as FOR SHARE, is generally sufficient to ensure referential integrity without preventing concurrent reads. |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
Collections
This query belongs to the following collections:
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
| Name | Description |
|---|---|
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
Categories
This query is classified under the following categories:
Concurrency control
Queries of this category provide information about concurrency control.
Does not work in some earlier PostgreSQL version
Queries of this category provide information that was not available in some earlier PostgreSQL version
Transactions
Queries of this catergory provide information about the use of transactions.
User-defined routines
Queries of this category provide information about the user-defined routines
| Name | Description |
|---|---|
| Concurrency control | Queries of this category provide information about concurrency control. |
| Does not work in some earlier PostgreSQL version | Queries of this category provide information that was not available in some earlier PostgreSQL version |
| Transactions | Queries of this catergory provide information about the use of transactions. |
| User-defined routines | Queries of this category provide information about the user-defined routines |
Further reading and related materials: