Database maintenance tool hangs correcting deposit slip sums

This forum is for programmers who have questions about the source code.
Post Reply
mowgli
Posts: 134
Joined: Fri Sep 14, 2007 1:42 pm

Database maintenance tool hangs correcting deposit slip sums

Post by mowgli » Fri Oct 30, 2009 1:54 pm

I'm running into a really bothersome issue trying to run database maintenance for practices that have a lot of deposit slips. When the tool runs the query on line 556 in DatabaseMaintenance.cs, it can hang for 20 minutes or more while mysqld-nt.exe churns thru the data. This query retrieves deposit slip amounts and compares those with the sum of the claimpayments and the patient payments on each deposit slip, in order to correct those that don't match. I think the problem is that it does this for all deposit slips, making a very large join, and it's executed whenever the tool is run, causing a lengthy ordeal every time. A solution might be to somehow retain the depositnums from the preceding query to correct claimpayment sums. That way the following query would be a small join. I've tried taking apart and reworking the problem query, but it always seems to choke on trying to join all claim payments and patient payments together with deposit slip numbers, using very large amounts of memory (and resulting paging to disk). The 3 tables involved all have records in the thousands. See current query below:

SELECT DepositNum,deposit.Amount,DateDeposit, IFNULL((SELECT SUM(CheckAmt) FROM claimpayment WHERE claimpayment.DepositNum=deposit.DepositNum GROUP BY deposit.DepositNum),0)+IFNULL((SELECT SUM(PayAmt) FROM payment WHERE payment.DepositNum=deposit.DepositNum GROUP BY deposit.DepositNum),0) _sum FROM deposit HAVING ROUND(_sum,2) != ROUND(deposit.Amount,2)

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Database maintenance tool hangs correcting deposit slip sums

Post by jordansparks » Fri Oct 30, 2009 3:02 pm

I don't have a database to test this query on, so can you try this? Run the following two queries:
ALTER TABLE claimpayment ADD INDEX (DepositNum)
ALTER TABLE payment ADD INDEX (DepositNum)
Then try the query in question one more time. If the speed is significantly better, let me know, and I'll add the indexes as a bug fix with the next version.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Database maintenance tool hangs correcting deposit slip sums

Post by jordansparks » Sun Nov 01, 2009 3:51 pm

I added those queries to the next build.
Jordan Sparks, DMD
http://www.opendental.com

mowgli
Posts: 134
Joined: Fri Sep 14, 2007 1:42 pm

Re: Database maintenance tool hangs correcting deposit slip sums

Post by mowgli » Mon Nov 02, 2009 6:05 am

Just saw your response this morning, since I posted at the end of the workday Friday, and added the indexes to a couple of problem databases. This resolved the issue completely! Thanks for addressing this so quickly.

Post Reply