# getFoundSetCount vs getFoundSetDataProviderAsArray

**URL:** <https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842>\
**Category:** Classic Servoy\
**Created:** [September 9, 2010, 10:31pm UTC](https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842 "2010-09-09T22:31:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulc](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@paulc](https://forum.servoy.com/u/paulc)\
**Post date:** [September 9, 2010, 10:31pm UTC](https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842/1 "2010-09-09T22:31:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [September 9, 2010, 10:48pm UTC](https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842/2 "2010-09-09T22:48:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [September 10, 2010, 7:27am UTC](https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842/3 "2010-09-10T07:27:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulc](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@paulc](https://forum.servoy.com/u/paulc)\
**Post date:** [September 20, 2010, 7:34pm UTC](https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842/4 "2010-09-20T19:34:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [September 20, 2010, 8:21pm UTC](https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842/5 "2010-09-20T20:21:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [September 21, 2010, 6:12pm UTC](https://forum.servoy.com/t/getfoundsetcount-vs-getfoundsetdataproviderasarray/12842/6 "2010-09-21T18:12:47Z")

</div>

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
