Max (date) in sub-query
497150Mar 9 2008 — edited Mar 11 2008I have an issue with a big view and several queries running on it where the max (date) is required in the sub-select (example below). When I run traces and explain, the perf problem is when the where cluase is evaluated, the view is pulled second time - so I basically use this view twice. The fact that the date in the underlined table is indexed did not help.
I tried to use "ROW_NUMBER() OVER (ORDER BY date ASC) AS row_number, " rather to select the max(date) in teh sub query but I get only 1 records returned by the query instead the expected about 25,000.
Need help on how to correct the max(date) to perform better and also to understand how to correct the ROW_NUMBER() not to limit me to 1 row.
Thanks a lot for the help, Tom
create view test_date as select * from user_objects;
select * --(I have specific columns in the real query)
from test_date t1
where LAST_DDL_TIME in
(select max(LAST_DDL_TIME)
from test_date t2
where t1.OBJECT_ID=t2.OBJECT_ID --(more clauses to limit the result but not reflecting the problem)
and t1.OBJECT_NAME =t2.OBJECT_NAME
and OBJECT_TYPE not in('TABLE')
group by t2.OBJECT_ID , t2.OBJECT_NAME )