So, I am querying some extremely large tables. The reason they are so large is because PeopleSoft inserts new records every time some data changes, rather than updating existing records. In fact, its transactional tables are also a data warehouse.
This requires queries that have selections nested in them in order to get the most recent / current row. They are effective and for every day (discarded by the day), they can have an effective sequence. Thus, in order to get the current record for user_id=123 , I have to do this:
select * from sometable st where st.user_id = 123 and st.effective_date = (select max(sti.effective_date) from sometable sti where sti.user_id = st.user_id) and st.effective_sequence = (select max(sti.effective_sequence) from sometable sti where sti.user_id = st.user_id and sti.effective_date = st.effective_date)
There is a phenomenal number of indexes in these tables, and I cannot find anything else that will speed up my queries.
My problem is that I often want to get data about individual of these tables, maybe 50 user_id, but when I join my tables having only a few records in them with several of these PeopleSoft tables, everything just goes to shit.
PeopleSoft tables are in a remote database, which I access through a database link. My queries tend to look like this:
select st.* from local_table lt, sometable@remotedb st where lt.user_id in ('123', '456', '789') and lt.user_id = st.user_id and st.effective_date = (select max(sti.effective_date) from sometable@remotedb sti where sti.user_id = st.user_id) and st.effective_sequence = (select max(sti.effective_sequence) from sometable@remotedb sti where sti.user_id = st.user_id and sti.effective_date = st.effective_date)
Things get even worse when I have to join multiple PeopleSoft tables with my local table. Performance is simply unacceptable.
What can I do to improve performance? I tried query hints so that the first local table is attached to her partner in PeopleSoft, so she does not try to join all her tables together before narrowing it down to the correct user_id. I tried the LEADING hint and played LEADING with hints that tried to drag processing to a remote database, but the explanation plan was closed and simply said 'REMOTE' for several operations, and I had no idea what was going on.
Assuming I have no way to change PeopleSoft and the layout of my tables, does my best choice suggest? If I joined a local table with four remote tables, and the local table joined two of them, how would I format the tooltip to my local table (which is very small - in fact, I can just do an inline scan so that my local table was only user_id, which interests me) is connected first to each of the deleted ones?
EDIT: An application needs real-time data, so unfortunately, a materialized view or other method of caching data will not be enough.