on 2023 Sep 06 10:25 PM
I have the below query which is actually in a stored procedure. This is on SQLAnywhere v17.0.9.4793.
When the server first start the server and run the query with the ORDER by P.last_name, P.first_name the results are instant. Returning the correct number of rows in < 1 second. However, on the subsequent run of the query it hangs. However, if I modify the ORDER BY clause I have found some values which cause the query to consistently return results even after the first time. It's strange some of the combinations which cause it to work (ex: adding DESC to the first_name?) or even ordering by another column on the table which is not indexed (p.address_1).
I have no idea where to go in order to track this down. I've unloaded and reloaded the entire database in case it was some strange error related to the indexes (thinking that rebuilding them might help)
SELECT "RESP"."RespPartyId", "P"."last_name" + ', ' + "P"."first_name" + ' ' + "P"."middle_initial" AS "Resp Party Name", "RESP"."CURRENT", "RESP"."ThirtyDay" AS "30 DAYS", "RESP"."SixtyDay" AS "60 DAYS", "RESP"."NinetyDay" AS "90 DAYS", "RESP"."CONTRACT", ("RESP"."CURRENT" + "RESP"."ThirtyDay" + "RESP"."SixtyDay" + "RESP"."NinetyDay" + "RESP"."CONTRACT") AS "TOTAL A/R", "RESP"."EstIns" AS "- EST. INS.", ("RESP"."CURRENT" + "RESP"."ThirtyDay" + "RESP"."SixtyDay" + "RESP"."NinetyDay" + "RESP"."CONTRACT" - "RESP"."EstIns") AS "= DUE NOW" FROM (SELECT P1.responsible_party AS "RespPartyId", SUM(P1.current_bal) + sum(P1.estimated_insurance) AS "CURRENT", SUM(P1.thirty_day) AS "ThirtyDay", SUM(P1.sixty_day) AS "SixtyDay", SUM(P1.ninety_day) AS "NinetyDay", SUM(P1.contract_balance) AS "CONTRACT", SUM(P1.estimated_insurance) AS "EstIns" FROM patient P1 WHERE (P1.current_bal <> 0.00 OR P1.thirty_day <> 0.00 OR P1.sixty_day <> 0.00 OR P1.ninety_day <> 0.00 OR P1.contract_balance <> 0.00 OR P1.estimated_insurance <> 0.00) GROUP BY P1.responsible_party) AS "RESP" JOIN patient P ON "P"."patient_id" = "RESP"."RespPartyId" JOIN account A ON P.patient_id = A.patient_id WHERE (P.practice_id = 1 OR null IS NULL)
Here is a list of the various ORDER BY columns and their results. The original query has:
ORDER BY P.last_name, P.first_name ORDER BY P.last_name, P.first_name; << does not work ORDER BY P.last_name; << does not work ORDER BY "Resp Party Name"; << works using the computed column from the same fields ORDER BY P.last_name, P.first_name desc; << This works (adding DESC to first_name, strange?!?) ORDER BY P.last_name, P.home_phone << works fine ORDER BY P.notes << random text column, works fine ORDER BY P.address_1 << unindexed text column, works fine
User | Count |
---|---|
66 | |
11 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.