Expression efficiency - sequence of arguments

I'm working to optimize various expressions in places like virtual columns and security filters. I wonder whether anyone has guidance or experience regarding the following points related to the sequence of arguments within functions where some arguments don't need to be evaluated. Any known best practices seem worth applying when a function's arguments vary in complexity--e.g., simple equality vs. SELECT with complex criteria.

Examples

Sequence A Sequence B

IF(
{condition}, 
INDEX(SELECT({complexity}), 1),
CONTEXT("Host") = "Server"
)

IF(
NOT({condition}), 
CONTEXT("Host") = "Server",
INDEX(SELECT({complexity}), 1)
)

OR(
INDEX(SELECT({complexity}), 1),
CONTEXT("Host") = "Server"
)

OR(
CONTEXT("Host") = "Server",
INDEX(SELECT({complexity}), 1)
)

IF, IFS, SWITCH

The help articles for these functions all state that the only result argument that is evaluated is the one associated with the outcome of the condition argument. For example:

  • From the IF article regarding the function's second argument: "An expression to be evaluated only if the is-true? expression evaluates as TRUE."
  • From the IFS article regarding the function's second argument: "An expression to be evaluated only if the immediately preceding is-true? expression evaluates as TRUE."
  • From the SWITCH article regarding the function's third argument: "An expression that is evaluated and returned if the associated expected-value is a match."

While the phrasing is more explicit in some articles than others, they all seem to literally state that result arguments that don't need to be evaluated are indeed not evaluated. If anyone knows differently, please advise.

OR

I don't find any reference to whether all arguments are always evaluated for the OR function. Perhaps evaluation ceases as soon as one argument evaluates to true? Does anyone know?

Solved Solved
1 15 729
1 ACCEPTED SOLUTION

Steve
Platinum 5
Platinum 5

I've asked about this specifically. I have been told by the developers that AND() and OR() do short-circuit at the first opportunity. I.e., AND() fails at the first subexpression that evaluates to FALSE; and OR() succeeds at the first subexpression that evaluates to TRUE. Note that this was not always the case, but was changed only within the last few years.

View solution in original post

15 REPLIES 15
Top Labels in this Space