March 12, 2007 at 9:28 am
Alright guys, this is going to be a bit messy. Just wondering if anyone had any suggestions on optimizing this query. Let me know if there's a better way to post this:
Query Removed and posted here: http://theninjalist.com/
I didn't want to post the formatted version here because it was too big. That link will show you the full, formatted query.
March 12, 2007 at 10:16 am
>>Alright guys, this is going to be a bit messy.
That qualifies as understatement of the month
Try these SQL formatting sites:
http://www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl
March 12, 2007 at 10:27 am
Yep, I used http://sqlinform.com/ to format it. You can peep it at http://theninjalist.com/.
March 12, 2007 at 10:28 am
FROM drs_pending_deduct AS a
LEFT OUTER JOIN settlement AS b
ON a.order_id = b.order_id
WHERE a.company_id = 'TMS2'
AND a.payee_id IN (SELECT id
FROM payee
WHERE status = 'A'
AND non_office_emp = 'Y'
AND company_id = 'TMS2')
AND a.ready_to_pay_flag <> 'V'
AND a.amount IS NOT NULL
For optimization, try removing the IN (SELECT ...).
Make it an inner join to a derived table instead ?
INNER JOIN
(
SELECT DISTINCT id
FROM Payee
WHERE Status = 'A'
AND non-office_emp = 'Y'
AND company_id = 'TMS2'
)
March 12, 2007 at 9:41 pm
Actually, it's a long but fairly simple crosstab. The big performance killers are whereever you have the unqualified correlation of...
a.order_id <> b.order_id
That's IF it were to ever be executed... Can you say wasted code? The join on the tables makes that code impossible ...
FROM drs_pending_deduct as a
LEFT OUTER JOIN settlement as b
ON a.order_id = b.order_id
I haven't analyzed the code deeply, but between the obvious unused code and the horrible date binning methods used, my advise would be, figure out what the code was supposed to do, throw it away, and rewrite it correctly.
Lemme guess... written by Business Objects or some Report Formatter?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply