Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

CBO horribly slow with SYS views such as all_constraints/all_cons_columns

759978May 9 2013 — edited May 10 2013
I have a problem with an Oracle 11g Release 11.2.0.1.0 database, where a query such as:
SELECT fields
FROM all_constraints ac,
all_cons_columns loc,
all_cons_columns rem
WHERE ac.table_name = '&tab'
AND ac.constraint_type = 'R'
AND ac.owner = '&own'
AND ac.owner = loc.owner
AND ac.constraint_name = loc.constraint_name
AND ac.r_owner = rem.owner
AND ac.r_constraint_name = rem.constraint_name
AND loc.position=rem.position
ORDER BY constraint_name, loc_pos;

Takes a very very long time, but adding the /*+ RULE */ hint makes it execute quite fast.

When I ran:
SQL> exec DBMS_STATS.DELETE_DICTIONARY_STATS();

PL/SQL procedure successfully completed.

SQL> exec DBMS_STATS.DELETE_FIXED_OBJECTS_STATS();

PL/SQL procedure successfully completed.

Then afterwards, the query was fast (without the /*+ RULE */ hint).

Gathering the stats again:
SQL> exec DBMS_STATS.GATHER_DICTIONARY_STATS();

Slowed it back down.

I can't imagine that best practice is to DELETE_DICTIONARY_STATS()? Can anyone explain what is going on and advise?

Many thanks for your time!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 7 2013
Added on May 9 2013
14 comments
2,130 views