Duplicate SQL 'count' queries being sent

Duplicate SQL 'count' queries being sent

MarkAndersonUKMarkAndersonUK Posts: 44Questions: 17Answers: 0

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) ascntfromrecruitsleft joinstagesonstages.stageID=recruits.statusIDleft joinrecruits_dataonrecruits_data.recruitID=recruits.recruitIDleft joinrecruits_licensesonrecruits_licenses.recruitID=recruits.recruitIDandrecruits_licenses.state_code=recruits._Primary_Statewhere (recruits._search_current> 0 andrecruits.isDoNotContact= 0 andrecruits.isDoNotPhone= 0 andrecruits.isCompassAgent= 0 andrecruits.isExCompassAgent= 0 andrecruits_licenses.isLobHealth>= '1' andrecruits.statusID<> 11 andrecruits.statusID<> 12 andrecruits.statusID<> 13 andrecruits.statusID<> 17 andrecruits.RecruitmentAsst= '3071' andrecruits.tsNextActionMaster>= '1705302000' andrecruits.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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    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 ;)

    Allan

Sign In or Register to comment.