In Datatables I use two query one to fetch records in that particular date range with server side pagination and another to get the total count of records in that particular date range. I am using Postgresql database.
select * from daily_txns where created_date <='2017-08-01' and created_date>='2017-07-01' and mid='0446721M0008690' order by created_date desc limit 10;
select count(mid) from daily_txns where created_date <='2017-08-01' and created_date>='2017-07-01' and mid='0446721M0008690';
Is this the correct way to do or is there any best approach for the same. If the first query takes 20 sec then the second query takes 40 sec and the total time taken to display the result is more then 60 sec. How to overcome this problem.