happyfirst wrote:
Walaa wrote:
GetDBCount() does: Select Count(*) From Table
So it won't hurt performance at all.
I disagree. I just don't understand how you can say it "won't hurt performace". IMO, it hurts performance. At the minimum, I'm having to make one extra db call. There are issues with count(). If I'm counting on a view, there are joins, there are calculated fields, there are filters, there are order bys, etc, then it will perform even slower. I even stopped using GetDbCount and made my own custom count to only count on the primary key field, and while that helped, it didn't help enough for our slowest screens. That's yet another reason why I don't understand how you can say that GetDbCount() doesn't hurt performance.
I think Walaa was commenting on your statement:
happyfirst wrote:
Yes, we've used that. And for most tables it performs great. But some tables that will return lots of rows, it does hurt performance.
A GetDBCount doesn't return "lots of rows".
happyfirst wrote:
I'm not trying to find a way to make getdbcount performance faster. The client is no longer in need of knowing how many pages there are. They just want performance. I just want to make the one call that I have no choice but to make, fetching that page of data, count more.
I don't think your first approach will work in some cases. Consider this:
Situation when you fetch the data
rowcount = 95
pagesize = 10
pagecount = 10
Situation when you want to know if there are more rows
Some guy insert a new row, and this is the new situation:
newrowcount = 96
newpagesize = pagesize * pagecount = 100
pagenumber = 2
limitrows = pagesize + 1 = 11
If you fetch that, that will return the 2nd. page of size 100 limiting 11. That wont return anything, but a row was added indeed.
I also don't see what exactly isn't working on your first post. Please post more info (http://llblgen.com/tinyforum/Messages.aspx?ThreadID=7722).
Back to the real need: I will recommend a COUNT. You can use GetScalar to get COUNT(SomeField). This is an example:
int rowCount = (int) customers.GetScalar(CustomerFieldIndex.CustomerId, AggregateFunction.Count);
See the generated code.
Also please test the performance of both solutions and see what is the best for you.Are you using this setup to display data on a grid using LLBLGenProDataSource? Because if you do, you can handle the GetDBCount event and perform your own COUNT.