Question : Aggregate function in subquery - performance issue

I have a query which gets max(date) for each account in the table.  The query works find, but it runs very sloooow.  How can I improve its performance?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
SELECT 
,ACCT_NUM
,DATA_DT
,CUST_NM
,STRT_DT 
FROM  FACT_MAIN AS FMAIN
	INNER JOIN DIM_MAIN AS DMAIN	
		ON DMAIN.DIM_ID = FMAIN.DIM_ID 
	inner JOIN DIM_ACCT AS DACCT 
		ON DACCT.DIM_ID = FMAIN.DIM_ID
	LEFT OUTER JOIN FACT_CUST AS FCUST
		ON FMAIN.DIM_ID = FCUST.DIM_ID
	INNER JOIN DIM_CUST_ADR AS DCADR 
		ON DCADR.CUST_DIM_ID = FCUST.CUST_DIM_ID
WHERE 
FMAIN.DATA_DT =  20090131 
AND  FCUST.DATA_DT = 20090131
AND DMAIN.BOOKED_DT BETWEEN '20090101' AND '20090131' 
AND DCADR.STRT_DT = (SELECT max(STRT_DT) FROM DIM_CUST_ADR AS ADR
					WHERE ADR.CUST_DIM_ID = DCADR.CUST_DIM_ID )
Open in New Window Select All

Answer : Aggregate function in subquery - performance issue

Make sure that you have indexes on all columns in WHERE conditions of outer query as well as corelated subquery. Indexing should be useful if you have at least 10000 records and > 90 % unique data in the column. Primary keys will be automatically indexed by the database system.

Please go through these links on indexing strategy:
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg06idx.htm
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/rzajq/rzajqindexstrat.htm
Random Solutions  
 
programming4us programming4us