I have a query that in certain conditions exhibits unusual behaviour when performing an index range scan.
For example, I have 3 tables (simplified below, but note that its just an example to illustrate the problem and not my actual tables).
Table RECORDS has 2 columns,
ID number(20), STATUS char(1)
Primary key is on ID, a second compound index is on [ID,STATUS]
Table GENRES has 2 columns,
ID number(20), GENRE char(1)
Primary key (compound) on [ID,GENRE]
Foreign key on ID, linked to RECORDS ID
Table REVIEWS has 2 columns
ID number(20), REVIEW varchar2(20)
Foreign key on ID, linked to RECORDS ID
Now, I use a basic query which returns 3 rows...
select *
from RECORDS R
left outer join REVIEWS RV on R.ID=RV.ID
inner join join GENRES G on R.ID=G.ID
where rv.review= 'good'
and r.status='A'
and g.genre='A'
I would expect this query to return in under a second, instead its taking over 40! What im seeing in the autotrace plan (using sqldeveloper) is a RANGE SCAN on one of the compound indexes has a LAST_CR_BUFFER_GETS of over 9 million(im guessing bytes?). Removing either of the last 2 "AND" conditions in the query above drops this value to about 20 !
I dont really know much about Oracle so can't understand why this is happening, or where to look next, and am struggling even to explain the problem.
My best guess is that the range scan is (for some reason) using the whole compound key rather than just the ID part of it (e.g. looking for a range between [1,'good'] AND [12345678,'good'] ) - this is the only thing I can think of that would explain the huge amount of fetches?
Oracle is a complicated old beast, and this problem is appearing at a clients site (so access for prodding around is very limited), so any suggestions/ideas where to start looking are greatly appreciated !
Thanks,
JOC
For example, I have 3 tables (simplified below, but note that its just an example to illustrate the problem and not my actual tables).
Table RECORDS has 2 columns,
ID number(20), STATUS char(1)
Primary key is on ID, a second compound index is on [ID,STATUS]
Table GENRES has 2 columns,
ID number(20), GENRE char(1)
Primary key (compound) on [ID,GENRE]
Foreign key on ID, linked to RECORDS ID
Table REVIEWS has 2 columns
ID number(20), REVIEW varchar2(20)
Foreign key on ID, linked to RECORDS ID
Now, I use a basic query which returns 3 rows...
select *
from RECORDS R
left outer join REVIEWS RV on R.ID=RV.ID
inner join join GENRES G on R.ID=G.ID
where rv.review= 'good'
and r.status='A'
and g.genre='A'
I would expect this query to return in under a second, instead its taking over 40! What im seeing in the autotrace plan (using sqldeveloper) is a RANGE SCAN on one of the compound indexes has a LAST_CR_BUFFER_GETS of over 9 million(im guessing bytes?). Removing either of the last 2 "AND" conditions in the query above drops this value to about 20 !
I dont really know much about Oracle so can't understand why this is happening, or where to look next, and am struggling even to explain the problem.
My best guess is that the range scan is (for some reason) using the whole compound key rather than just the ID part of it (e.g. looking for a range between [1,'good'] AND [12345678,'good'] ) - this is the only thing I can think of that would explain the huge amount of fetches?
Oracle is a complicated old beast, and this problem is appearing at a clients site (so access for prodding around is very limited), so any suggestions/ideas where to start looking are greatly appreciated !
Thanks,
JOC