330
Views
2
Comments
table record list.length vs table record count

I know that tablerecord.count perform a query to the database to get the count of records, but If I already executed a query will not be better to use query.list.length property to get the count?

Also, I am asking this, because in List_Navigation widget you use the query.count as the count of records instead the tablerecord.list.length and I am confussing because tablerecord.list.length can be lower or greater than query.count if the database change fast. Why do not use tablerecord.list.length in list_navigation instead?
2012-03-02 13-17-21
Paulo Ramos
Staff
Hi Carlos,

The Platform tries to optimize this pattern by opening a cursor and retrieving rows in chunks as they are needed (instead of retrieving everything in one shot). The reason is performance - for example, if you have 100 000 rows in the table, but want to display only the first 50, this avoids all this data being transfered between the database and the front-end.

However, if you use the Length property, you are turning off this optimization. The Platform will need to retrieve all the data from the database in order to know the size of the list. So, yes, there is a trade-off here:
  • Count property: a second DB statement is executed
  • Length: all the rows are returned in one shot
2022-08-23 19-33-12
ingaponteca

ok. Understood. So, is better to use count and do not pay the full extraction of data.
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.