bcquality/microsoft/knowledge/performance/use-findset-readonly-by-default.md
Jesper Schulz-Wedde 5bcdc55df9 Sync knowledge articles with review agent instructions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-05 14:08:32 +02:00

1.2 KiB

bc-version domain keywords technologies countries application-area
all
performance
findset
lock
locktable
readonly
update
al
w1
all

Use FindSet in read-only mode by default

Description

FindSet has two modes: FindSet() and FindSet(false) are read-only and take no update lock; FindSet(true) sets update-lock read isolation on the record before fetching. Update locks are expensive and hold for the lock scope, so passing true when you do not intend to modify the records increases contention under load.

Best Practice

Call FindSet with no arguments when the loop only reads field values. Pass true only when the same loop is expected to call Modify, Delete, or Rename on the record, and the correctness of the operation depends on the matching rows being locked for the iteration.

See sample: use-findset-readonly-by-default.good.al.

Anti Pattern

Writing FindSet(true) reflexively for every iteration forces the platform to take a LockTable on every call, even when the loop only reads values. The older two-parameter signature FindSet(ForUpdate, UpdateKey) is obsolete and must not be used.

See sample: use-findset-readonly-by-default.bad.al.