37
Views
2
Comments
Solved
Best Practices - Queries

Hi,

Can someone give me an example in reactive web, where his happens?

Solution

Hi Pedro,

When you execute a query, then iterate over the result with a For Each, the Platform uses a database cursor, fetching records one-by-one for each iteration. This conserves memory, as the result set doesn't need to be loaded in its entirety (though might be slightly slower, as for each record communication with the database is needed).

When you re-iterate the query result, the Platform can no longer use a cursor (it's not possible to reset the cursor apparently), so the entire result set needs to be fetched from the database first. Also, when indexing the result set, more than one record at a time may be needed, and using a cursor is no longer possible.

As for your question, "where this happens", the short answer is "wherever you create code that re-iterates or uses indexes". The recommendation says "don't do this, unless it is strictly necessary", so if you don't do it, it doesn't happen.

Hi Pedro,

It is very common, sometimes when we write any logic, we may need to iterate queries's result on click of a button or on some event.  As mentioned above in such a case we should avoid multiple iteration, also getting value through an index.

Thanks,

Sachin

Solution

Hi Pedro,

When you execute a query, then iterate over the result with a For Each, the Platform uses a database cursor, fetching records one-by-one for each iteration. This conserves memory, as the result set doesn't need to be loaded in its entirety (though might be slightly slower, as for each record communication with the database is needed).

When you re-iterate the query result, the Platform can no longer use a cursor (it's not possible to reset the cursor apparently), so the entire result set needs to be fetched from the database first. Also, when indexing the result set, more than one record at a time may be needed, and using a cursor is no longer possible.

As for your question, "where this happens", the short answer is "wherever you create code that re-iterates or uses indexes". The recommendation says "don't do this, unless it is strictly necessary", so if you don't do it, it doesn't happen.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.