Performance Impact of utils.hasRecords()

We use utils.hasRecords(project_elements_to_supplier_invoices) to test if an invoice has been already booked against a project element.

Am I right that this will basically fire a SQL COUNT(*) to decide the hasRecords-question?
Because I wonder why I do not see such a COUNT() in the SQL performance log on the AppServer.

I am in general curious about the performance impact of the hasRecords() function.

Bernd.N:
Am I right that this will basically fire a SQL COUNT(*) to decide the hasRecords-question?
Because I wonder why I do not see such a COUNT() in the SQL performance log on the AppServer.

Your assumption is not correct.
Servoy will fire a full SELECT as if you were requesting the related foundset.

So this:

utils.hasRecords(project_elements_to_supplier_invoices)

will have the same backend impact as:

var _fs = project_elements_to_supplier_invoices; var _bHasRecords = _fs.getSize() > 0

Will the ‘utils.hasRecords’ function have to much impact on performance? I wouldn’t say so.
Most of the times you’ll use this function to check if you need to perform an action on / read data from the related foundset.
As executing ‘utils.hasRecords’ will make Servoy cache this particular foundset, the query won’t be executed twice in the back-end.

Depending on the relation you could prevent he application server to execute the query.
So in case of a relation ‘project_to_client’, you would have the client_id as a FK in the table projects.

if(client_id && utils.hasRecords(project_to_client)) {
   application.output('This project is for a client!');
}

The above code will already stop the evaluation in the ‘if’ statement as soon as the client_id doesn’t contain a value.

Hope this is clarifying things.

Depending on the size of your table and the relation criteria, a count could be really expensive… That’s why you have a special databaseManager.getFoundSetCount(foundset).

Thanks to all for the clarification!
Now I see why there was no server log entry, as Servoy looked at the cached foundset.

About this (and perhaps off-topic, sorry…), is there any difference between utils.hasRecords() and databaseManager.hasRecords()?

juan.cristobo:
About this (and perhaps off-topic, sorry…), is there any difference between utils.hasRecords() and databaseManager.hasRecords()?

No.
Actually utils.hasRecords() was deprecated for a short while, but as the ‘databaseManager’ node is not available in ‘calculation-mode’ the deprecated-state has been reverted.
In general I always use databaseManager.hasRecords(), except for calculations.
But I try to stay away from related stuff in calculations as this executes a whole lot of queries which could have a huge drawback on performance.

Ok, thanks for the info!