I don't know if
a) I'm getting grumpier as I get older
b) people are losing the ability to phrase a question.
It just seems to me that day by day, the quality of the questions goes down. I don't remember people asking questions like this just 8 years ago. I've been participating in forums since 1994. "Back in the day", the questions were mostly thought out, with examples - with some background, with some thought. In the last couple of years - this seems to be changing - universally.
Oh well, it is probably related to both bullet points... Anyway here is the QOD - question of the day.
Subject: query is not using particular partition and index despite use full table scan
Entire question:
SELECT count(*)
FROM
DIM_BANK RIGHT OUTER JOIN FACT_JRNL_ACTG ON (DIM_BANK.BANK_ID=FACT_JRNL_ACTG.BANK_ID)
LEFT OUTER JOIN DIM_BSA ON (FACT_JRNL_ACTG.BSA_ID=DIM_BSA.BSA_ID)
LEFT OUTER JOIN DIM_FY ON (FACT_JRNL_ACTG.FY_ID=DIM_FY.FY_ID)
LEFT OUTER JOIN DIM_APD ON (FACT_JRNL_ACTG.APD_ID=DIM_APD.APD_ID)
LEFT OUTER JOIN DIM_PSCD ON (FACT_JRNL_ACTG.PSCD_ID = DIM_PSCD.PSCD_ID)
WHERE
(
(DIM_BANK.BANK_ACCT_CD IN ('33')
OR '*' IN ('33'))
AND DIM_PSCD.PSCD_CLOS_CL_CD IN ('1', '4', '5')
AND CASE DIM_BSA.CASH_ACCT_FL WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' END = 'Yes'
AND DIM_APD.PER != 0
AND DIM_APD.PER != 99
AND DIM_APD.FY < 2008
OR DIM_FY.FY = 2008
AND DIM_APD.PER <= 6
AND DIM_APD.PER != 0
AND CASE DIM_BSA.CASH_ACCT_FL WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' END = 'Yes'
AND DIM_PSCD.PSCD_CLOS_CL_CD IN ('1', '4', '5')
AND (DIM_BANK.BANK_ACCT_CD IN ('33')
OR '*' IN ('33'))
);
That's it folks. "My query isn't doing partition elimination (probably, I'm sort of GUESSING) and isn't using some index (on some column of some table)"
Before anyone says anything - this comes from the US.
Some wows from reading the query:
- "(DIM_BANK.BANK_ACCT_CD IN ('33') OR '*' IN ('33')) - why would you do that?
- "CASE DIM_BSA.CASH_ACCT_FL WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' END = 'Yes'" - why would you do THAT?
- "CASE DIM_BSA.CASH_ACCT_FL WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' END = 'Yes'" - just in case you didn't believe us the first time
- wow, more duplicated predicates...
- outer joins to DIM_BSA, but we have that neat predicate using CASE - if we actually needed to outer join to DIM_BSA then all of the attributes would be NULL - the predicate would never be true - hence, we do not need or want to outer join to DIM_BSA
- Same comment about DIM_FY, we outer join to DIM_FY, but if we make up a row - then DIM_FY's attributes will all be null and DIM_FY.FY = 2008 cannot be true (or false, it is unknown)
- Ditto for DIM_APD
- and of course DIM_PSCD
- and just to make it 100% complete, the outer join to DIM_BANK - ditto. every single outer join in this query, should not be there.
I've responded with:
My car won't start. Now we are even, we have shared the same level of detail regarding our respective problems.