### LockRows
![[assets/ex_lockrows.png|256]]
### The Explain Trace
```sql
-- Locking a specific row for modification
EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE)
SELECT * FROM animals WHERE id = 1 FOR UPDATE;
```
```text
LockRows (cost=1.29..9.31 rows=1 width=33) (actual time=1.017..1.017 rows=1 loops=1)
Output: id, name, species_id, created_at, ctid
Buffers: shared hit=5 dirtied=1
-> Index Scan using animals_pkey on public.animals (...)
```
---
- **Description**: Locks rows without changing them.
- **Performance**: Introduces overhead for lock acquisition and can lead to transaction blocking if other sessions held conflicting locks.
- **Factors**: Number of rows locked and the degree of lock contention.
- **Cost**: `lock acquisition cost * number of rows`
![[assets/ex_lock_rows.svg|256]]
- **Operates on**: [[Structures/Tuple]]
- **Workloads**:
- [[Workloads/Lock/Lock/Lock_Tuple|Lock: Tuple]]
- [[Workloads/Lock/Lock/Lock_TransactionId|Lock: TransactionId]]
- [[Workloads/LWLock/Lock/LockManager|LWLock: LockManager]]
- [[Workloads/IPC/Snapshot/SafeSnapshot|IPC: SafeSnapshot]]