getFoundSetCount vs getFoundSetDataProviderAsArray

Hi all,

I am having huge performance issues when using databaseManager.getFoundSetCount or databaseManager.getFoundSetDataProviderAsArray.

I have a foundset with over 5000 records, and I need to get the foundset count quickly.

When using either databaseManager.getFoundSetCount /databaseManager.getFoundSetDataProviderAsArray its taking over 1 minute to return a count.

What might be the fastest method in which to return a count on a large foundset?

thank you

Hi Paul,

Using databaseManager.getFoundSetDataProviderAsArray() will give you an array of your 5000 records of a specific column. So this is a very expensive action.
databaseManager.getFoundSetCount(foundset) is the preferred way to get a total count of your foundset.

Hope this helps.

And databaseManager.getFoundSetCount() lets the database sort out how many records there are, so it’s the fastest way possible. If it’s not performing, you should have a look at the Performance log on the admin pages to see the query being fired and then see if the database can be optimized (by adding indexes) to give you the result faster.

Paul

Hi Paul / Roclasi

Thanks for the input. After trying many different methods, you are both correct in the fact that databaseManager.getFoundSetCount() is the fastest possible method in which to get a foundsets count. I was just hoping there was something that cmight be less expensive. We utilize this call in numerous places in our code, and depending on the size of the foundset, it can slow our system down quite significantly.

let me get this straight! getFoundSetCount will take 1 minute with only 5000 records?? :shock:
which database are you using? there must be something wrong. We use it also a lot, with MANY MANY more records…

Paul,

databaseManager.getFoundSetCount() does no more then taking the query from the foundset (select pk from table where …) and converts it to a select count (select count(1) from table where …).
In case of joins (for example when you have a related search condition), a distinct(pk) is added.

What shows on top in the admin page->performance data when you run the foundsetcount?

Rob