due to the bad performance on count(*) with our DB (when we deal with 50M records), we don't want to return back to total number of records in each slice of records we retrieve. Instead we want to work without it. I could set the total number of records to be MAX_INT for that matter within jsonReader:{records: MAX_INT}, but I want to make this better.
What I would like to do is to set the records for MAX_INT when the grid loads (that part I know how), but in parallel initiate a call for count(*) at the background, eventually when the real counter will be retrieved, I would like to override the MAX_INT with the real counter which is the real number of records.
How do I override the number of records counter?
Thanks,
First of all the it's well-known problem with
COUNT(*)
. If one need to get just the number of rows of some specific table of the database then one can get the information very easy and very quicklyIn more common case (if the data are not only in one partition) one should use
SUM(rows)
instead ofrows
. SeeI suppose that one could use in the same way
sys.dm_db_partition_stats
You can examine your database and test whether
COUNT(*)
returns the same values line the above SQL statements or some other close variants.Independent from the problem with
COUNT(*)
you can userecords
ortotal
defined as functions and don't return anyrecords
ortotal
from the server. Therecords
is not important in the most cases at all. It will be displayed on the pager ifviewrecords: true
option is used. You can use defaultviewrecords: false
and to have no problem with setting therecords
field in the server response.The
total
property of the server response will be used on the other side to setlastpage
parameter of jqGrid, which will be used to verify whether "Next Page" and "Last Page" buttons of the pager will be enabled or not. What you can do isalternatively you can return any other value like
Number.MAX_VALUE
for example or max integer9007199254740992
(253, see the answer).