Hi!
I have a problem with a batch which is very slow. SQL_TRACE and TKPROF show that the problem comes from an Index: It is dropped an recreated by it is not analyzed. CBO takes a wrong path in some queries.
The application vendor refuses to modify his batch.
I tried to create a trigger that would analyze the indexes as soon as they are created:
-- with sys user:
grant select on sys.dba_indexes to system;
-- with system user:
create or replace trigger tg_analyze_index after create on schema
DECLARE
cursor c_list is select index_name from dba_indexes
where owner='MYUSER' and LAST_ANALYZED is null;
BEGIN
for id_c in c_list
LOOP
execute immediate 'ANALYZE INDEX MYUSER.'||id_c.index_name||' COMPUTE STATISTICS';
end LOOP;
end;
/
When creating an index I get:
-- with myuser
SQL> create index i2 on t2(X);
create index i2 on t2(X)
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-30511: invalid DDL operation in system triggers
ORA-06512: at line 8
*****************************
I read in Oracle documentation that triggers may not perform DDL.
Does anyone has a better idea to solve my problem ?
I have a problem with a batch which is very slow. SQL_TRACE and TKPROF show that the problem comes from an Index: It is dropped an recreated by it is not analyzed. CBO takes a wrong path in some queries.
The application vendor refuses to modify his batch.
I tried to create a trigger that would analyze the indexes as soon as they are created:
-- with sys user:
grant select on sys.dba_indexes to system;
-- with system user:
create or replace trigger tg_analyze_index after create on schema
DECLARE
cursor c_list is select index_name from dba_indexes
where owner='MYUSER' and LAST_ANALYZED is null;
BEGIN
for id_c in c_list
LOOP
execute immediate 'ANALYZE INDEX MYUSER.'||id_c.index_name||' COMPUTE STATISTICS';
end LOOP;
end;
/
When creating an index I get:
-- with myuser
SQL> create index i2 on t2(X);
create index i2 on t2(X)
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-30511: invalid DDL operation in system triggers
ORA-06512: at line 8
*****************************
I read in Oracle documentation that triggers may not perform DDL.
Does anyone has a better idea to solve my problem ?