Duplicate SQL 'count' queries being sent
Duplicate SQL 'count' queries being sent
![MarkAndersonUK](https://secure.gravatar.com/avatar/43fcdb9a1b08d999ee4a088cc151cbbe/?default=https%3A%2F%2Fvanillicon.com%2F43fcdb9a1b08d999ee4a088cc151cbbe_200.png&rating=g&size=120)
Hi,
I was looking my my SQL server query log (I was optimizing tables, so had logging turned on). I noticed that the is sending the exact same query is sent to the SQL server twice. Obviously that is not very efficient, and in this case add about 3sec to the overall load time as these are large tables.
My environment is NodeJS, and the datatable is running in serverSide mode.
Below is one of the queries that was run twice back-to-back.:
select count(
recruits.
recruitID) as
cntfrom
recruitsleft join
stageson
stages.
stageID=
recruits.
statusIDleft join
recruits_dataon
recruits_data.
recruitID=
recruits.
recruitIDleft join
recruits_licenseson
recruits_licenses.
recruitID=
recruits.
recruitIDand
recruits_licenses.
state_code=
recruits.
_Primary_Statewhere (
recruits.
_search_current> 0 and
recruits.
isDoNotContact= 0 and
recruits.
isDoNotPhone= 0 and
recruits.
isCompassAgent= 0 and
recruits.
isExCompassAgent= 0 and
recruits_licenses.
isLobHealth>= '1' and
recruits.
statusID<> 11 and
recruits.
statusID<> 12 and
recruits.
statusID<> 13 and
recruits.
statusID<> 17 and
recruits.
RecruitmentAsst= '3071' and
recruits.
tsNextActionMaster>= '1705302000' and
recruits.
tsNextActionMaster<= '1721109599')
IS there some way I can eliminate this duplicate 'count' query
below is a copy of the SQL log that shows the same query running twice within milliseconds
Answers
Have you verified whether those duplicated queries are coming from a single browser request, or is the browser sending two requests (in which case, the duplicated SQL queries would be correct)?
If it is coming from a single request, could you post your server-side script, please, so we can take a look,
Colin
Looking at the code, I think I see a case where a duplicate count query could be issued if there is no filter applied to the table. Could you possibly confirm this for me please, but checking initially if you can see the duplicate with no filter, and then type into the search box at which point I would expect there not to be a duplicate.
If it isn't that, then I need a new theory![;) ;)](https://datatables.net/forums/resources/emoji/wink.png)
Allan