QUERY BY FORMULA slow when searching using object properties

I noticed that QUERY BY FORMULA becomes slow when using object properties as the search values.

For example this runs slow (5630 ms):
QUERY BY FORMULA([Company];([Company]Code=$line.company) & ([Company]Admin=$request.admin))

But when I copy the properties to local variables first, then the same query runs fast (< 0 ms)
$company:=$line.company
$admin:=$request.admin
QUERY BY FORMULA([Company];([Company]Code=$company) & ([Company]Admin=$admin))

This leads me to believe the first example runs in sequential mode because it sees $line.company as an expression rather than a fixed value.

Why can’t 4D optimize such queries?

How big is the object $line? How many records are in the table Company?
I think, 4D take the time to analyse the object.
You should query by formula with ORDA.

please post Query Plan and Query Path

Hi Thomas,

I already did this and it helped me to find the reason.

Here are the query plan and the query paths for both queries.

  1. Using object properties:

<code 4D>
QUERY BY FORMULA([Company];([Company]Code=$line.company) & ([Company]Admin=$request.admin))

</code 4D>
Code :
Query plan:

4D Script

And
4D Script

Query path:

[Company]Code=$1.company And [Company]Admin=$2.admin   (1 record found in 5640 ms)
  1. Using intermediate variables:

<code 4D>
$code:=$line.company
$admin:=$request.admin
QUERY BY FORMULA([Company];([Company]Code=$code) & ([Company]Admin=$admin))

</code 4D>

Code :
Query plan:

[index : Code, Admin ] LIKE PLUGHAAG , 0001

Query path:

[index : Code, Admin ] LIKE PLUGHAAG , 0001 (1 record found in 0 ms)

As you can see the first example switches to sequential mode.