bcquality/microsoft/knowledge/performance/do-not-locktable-in-read-only-procedure.md
Jesper Schulz-Wedde 2b5550c346
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
Improve partner onboarding and documentation navigation (#174)
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:31:03 +02:00

1.7 KiB

bc-version domain keywords technologies countries application-area
all
performance
locktable
read-only
helper
contention
transaction
al
w1
all

Do not LockTable in a read-only procedure

Description

LockTable is a transaction-wide signal: from the call onward, every read against that table in the same transaction acquires UPDLOCK. Per the upstream guidance, "LockTable() before Modify/Insert/Delete in the same procedure is the correct pattern" — locking the read against the write that follows is what the call exists for. The anti-pattern is "LockTable() in read-only procedures — unnecessary lock contention": the procedure never writes, but the lock cost is paid by everyone sharing the transaction.

Best Practice

Reserve LockTable for the read directly before a Modify, Insert, or Delete that depends on the read value. If a helper is sometimes called for reading and sometimes for writing, split it into separate read and write paths and call LockTable only on the write path. For read-only existence checks or lookups, the right primitive is ReadIsolation (see prefer-readisolation-over-locktable-for-reads.md).

See sample: do-not-locktable-in-read-only-procedure.good.al.

Anti Pattern

A pure getter that opens with Rec.LockTable();. Every caller's transaction now acquires UPDLOCK on that table for every subsequent read until commit. The contention shows up as blocking on unrelated sessions whose own code path looks innocent — the locker is invisible to the blocked reader.

See sample: do-not-locktable-in-read-only-procedure.bad.al.