Repository navigation
knowledge(performance): Get behind a key-is-set check in and-condition wastes a DB call - #275
Open
Kilian Seizinger (pri-kise) wants to merge 2 commits into
Open
Kilian Seizinger (pri-kise) wants to merge 2 commits into
Kilian Seizinger (pri-kise) wants to merge 2 commits into
Conversation
…n wastes a DB call Extend the no-short-circuit rule with the case where Rec.Get is the dependent operand behind a Key <> 0 / '' check and only a field value or default is returned: nothing breaks, but every call with an unset key sends a query that cannot find a record. Add GetEntryDescription to the bad/good samples.
Kilian Seizinger (pri-kise)
marked this pull request as ready for review
November 17, 2026 13:39
Jesper Schulz-Wedde (JesperSchulz)
requested changes
Nov 17, 2026
Jesper Schulz-Wedde (JesperSchulz)
left a comment
Contributor
There was a problem hiding this comment.
The new GetEntryDescription example loads a full G/L Entry record to return only Description, so the good example still triggers our partial-record rule. Please select Description before Get in both samples, keeping the guard as the difference, or use a small self-contained table if the samples must support versions before SetLoadFields.
Please also describe this as an unnecessary Get whose result is excluded by the guard, rather than a guaranteed database round-trip. Get can use the server cache, and zero or blank key values can identify real records in AL.
…d wording Select Description with SetLoadFields before Get in both samples so the guard is the only difference. Describe the case as an unnecessary Get whose result the guard excludes, not a guaranteed database round-trip, and note that 0/blank can be real keys.
Contributor
Author
|
Thanks for the review. Both points addressed in the latest commit:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extends
boolean-operators-do-not-short-circuitwith the case whereRecord.Get(...)is the dependent operand behind a key-is-set check:if (EntryNo <> 0) and Rec.Get(EntryNo) then exit(Rec.Field); exit('');This is not unsafe, but when the guard means "key not set" the
Getis an unnecessary call whose result the guard excludes anyway. (Getmay be served from the server cache, so it is not always a database round-trip.)Changes
if EntryNo = 0 then exit('')), callGetonly after it.Rec.Get(Key)behindKey <> 0orKey <> ''when only a field value or default is returned and the guard intentionally means "key not set".GetEntryDescriptionin.bad.aland.good.al, both withSetLoadFields(Description)so the guard is the only difference.No new article: the rule already covers the pattern, so a separate file would duplicate it.
Validation
Test-ReviewFixtures.ps1passes.