I have some queries of the form:
select * from MAIN.MY_TABLE
where ID in (select ID from OTHER.OTHER_TABLE where type = 'BANANA');
Where ID is indexed on MAIN.MYTABLE, but not indexed on OTHER.OTHER_TABLE
Recently these have been erroring with ORA-01555: snapshot too old.
My understanding is this this due to the query taking too long for the undo space.
This is likely to be due it being peak business season and the databases being under heavy load.
The question is, if I were to split the query into the several queries of the form:
select * from MAIN.MY_TABLE
where ID in (select ID from OTHER.OTHER_TABLE where type = 'BANANA')
and ID >= 0 and ID <1000;
select * from MAIN.MY_TABLE
where ID in (select ID from OTHER.OTHER_TABLE where type = 'BANANA')
and ID >= 1000 and ID <2000;
select * from MAIN.MY_TABLE
where ID in (select ID from OTHER.OTHER_TABLE where type = 'BANANA')
and ID >= 2000 and ID <3000;
On one hand this seems like each query would take less time than initial query. On the otherhand, it seems like such an obvious optimisation, that I would think that Oracle would do this anyway.
Why don't you try optimising the query so it doesn't take so long? For starters, Oracle can have some difficulty building a good query plan if you use IN (SELECT...) instead of a join. Does this query return the same result with a better query plan (i.e. a
JOINoperator instead of anINoperator):The only issue is if you have duplicates in
OTHER.OTHER_TABLEon theIDcolumn. This will result in double counting in the final result set. But you should really avoid that kind ofIN (SELECT....)structure if possible.