josephu12
Programmer
- Nov 27, 2007
- 4
I have a query that works just fine in our test environment. I pointed to our production side though and it takes 517 seconds to execute. This will not work well for a Web Application don't you agree?
It seems that the main problem is in one of the tables, on test it only has about 50,000 records, in production it has well over a million. All joins are on indexed fields. We are using version 8.
I have used two different tools and one times out, the other is "patient" and lets it run to completion. I am not a DB2 person. But they say SQL is SQL don't they? I am in learning mode, I have checked various sites for two days now without much luck in how to speed this up.
Would an inner select help? How would I include it in this if it would?
I would apprectiate any help I can get, if more information is needed I will provide it.
Thanks!
SELECT DISTINCT
TC.CONT_NUM AS ContractNumber,
TC.CONT_STAT_CD AS ContractStatus,
TC.CONT_ISS_DEL_DT AS DeliveryDate,
PROD.TAPLAN.PLAN_TYP AS PlanType, PROD.TCAGT.AGENT_NAME AS AgentName, PROD.TAYBBASE.BILL_MODE_CD AS BillMode,
PROD.TAYBBASE.MODE_PREM_AMT AS PremAmtMode, PROD.TZAN.CLIENT_REFERENCE AS ClientReference,
PROD.TW1A0.FIRST_NAME AS ClientFName, PROD.TW1A0.LAST_NAME_COY_NAME AS ClientLName
FROM PROD.TZAN INNER JOIN PROD.TAYBBASE INNER JOIN
PROD.TCAGT INNER JOIN
PROD.TAPLAN INNER JOIN
PROD.TYCNT TC INNER JOIN
PROD.TAAGT TCA ON TC.CONT_NUM = TCA.CONT_NUM ON PROD.TAPLAN.PLAN_CD = TC.PLAN_CD
AND PROD.TAPLAN.TAX_QUAL_CD = TC.TAX_QUAL_CD ON PROD.TCAGT.AGENT_NO = TCA.AGNT_NUM ON
PROD.TAYBBASE.CONT_NUM = TC.CONT_NUM ON PROD.TZAN.CONNECT_ANNU_KEY = TC.CONT_NUM INNER JOIN
PROD.TW1A0 ON PROD.TZAN.CLIENT_REFERENCE = PROD.TW1A0.CLIENT_REFERENCE
WHERE (TC.CONT_STAT_CD = '09') OR
(TC.CONT_STAT_CD = '14') AND (CURRENT_DATE - TC.CONT_ISS_DEL_DT >= 0) AND ("DAYS"(CURRENT_DATE) - "DAYS"(TC.CONT_ISS_DEL_DT)<= 60)
AND (TC.TAX_QUAL_CD IN ('D', 'K', 'A'))
AND (PROD.TZAN.RELATIONSHIP = 'AN')
OR (TC.CONT_STAT_CD = '14')
AND (CURRENT_DATE - TC.CONT_ISS_DEL_DT >= 0)
AND ("DAYS"(CURRENT_DATE) - "DAYS"(TC.CONT_ISS_DEL_DT)
<= 60)
AND (TC.TAX_QUAL_CD NOT IN ('D', 'K', 'A'))
AND (PROD.TZAN.RELATIONSHIP = 'OW')
ORDER BY ContractNumber
It seems that the main problem is in one of the tables, on test it only has about 50,000 records, in production it has well over a million. All joins are on indexed fields. We are using version 8.
I have used two different tools and one times out, the other is "patient" and lets it run to completion. I am not a DB2 person. But they say SQL is SQL don't they? I am in learning mode, I have checked various sites for two days now without much luck in how to speed this up.
Would an inner select help? How would I include it in this if it would?
I would apprectiate any help I can get, if more information is needed I will provide it.
Thanks!
SELECT DISTINCT
TC.CONT_NUM AS ContractNumber,
TC.CONT_STAT_CD AS ContractStatus,
TC.CONT_ISS_DEL_DT AS DeliveryDate,
PROD.TAPLAN.PLAN_TYP AS PlanType, PROD.TCAGT.AGENT_NAME AS AgentName, PROD.TAYBBASE.BILL_MODE_CD AS BillMode,
PROD.TAYBBASE.MODE_PREM_AMT AS PremAmtMode, PROD.TZAN.CLIENT_REFERENCE AS ClientReference,
PROD.TW1A0.FIRST_NAME AS ClientFName, PROD.TW1A0.LAST_NAME_COY_NAME AS ClientLName
FROM PROD.TZAN INNER JOIN PROD.TAYBBASE INNER JOIN
PROD.TCAGT INNER JOIN
PROD.TAPLAN INNER JOIN
PROD.TYCNT TC INNER JOIN
PROD.TAAGT TCA ON TC.CONT_NUM = TCA.CONT_NUM ON PROD.TAPLAN.PLAN_CD = TC.PLAN_CD
AND PROD.TAPLAN.TAX_QUAL_CD = TC.TAX_QUAL_CD ON PROD.TCAGT.AGENT_NO = TCA.AGNT_NUM ON
PROD.TAYBBASE.CONT_NUM = TC.CONT_NUM ON PROD.TZAN.CONNECT_ANNU_KEY = TC.CONT_NUM INNER JOIN
PROD.TW1A0 ON PROD.TZAN.CLIENT_REFERENCE = PROD.TW1A0.CLIENT_REFERENCE
WHERE (TC.CONT_STAT_CD = '09') OR
(TC.CONT_STAT_CD = '14') AND (CURRENT_DATE - TC.CONT_ISS_DEL_DT >= 0) AND ("DAYS"(CURRENT_DATE) - "DAYS"(TC.CONT_ISS_DEL_DT)<= 60)
AND (TC.TAX_QUAL_CD IN ('D', 'K', 'A'))
AND (PROD.TZAN.RELATIONSHIP = 'AN')
OR (TC.CONT_STAT_CD = '14')
AND (CURRENT_DATE - TC.CONT_ISS_DEL_DT >= 0)
AND ("DAYS"(CURRENT_DATE) - "DAYS"(TC.CONT_ISS_DEL_DT)
<= 60)
AND (TC.TAX_QUAL_CD NOT IN ('D', 'K', 'A'))
AND (PROD.TZAN.RELATIONSHIP = 'OW')
ORDER BY ContractNumber