Dick,
I’m happy to try to improve this query, but it is not executed when Toad is
creating view scripts. This query comes from generating user scripts. There is,
however, a similar query that is executed when generating view scripts. So if we
can find an improvement to this one, I may be able to apply it to the other.
Try these queries and let me know if either is significantly better.
This one is rewritten using a WITH.
with privs as
( Select p. grantee , p. owner , p. table_name , null column_name , p.privilege,
p. grantable
from dba_tab_privs p, dba_users u
where p. grantee = u. username
and p. grantee = : OneObjectName
UNION ALL
Select p. grantee , p. owner , p. table_name , p. column_name , p.privilege, p.
grantable
from dba_col_privs p, dba_users u
where p. grantee = u. username
and p. grantee = : OneObjectName )
Select o . object_type , pp . *
from dba_objects o , privs pp
where o . OWNER = pp . owner
and o . object_name = pp . table_name
and o . object_type in ( ‘TABLE’ , ‘VIEW’ , ‘SEQUENCE’ , ‘PACKAGE’ , ‘PROCEDURE’
, ‘FUNCTION’ , ‘SNAPSHOT’ , ‘MATERIALIZED VIEW’ , ‘DIRECTORY’ , ‘LIBRARY’ ,
‘TYPE’ , ‘OPERATOR’ , ‘INDEXTYPE’ , ‘EDITION’ , ‘JOB’ , ‘PROGRAM’ , ‘SCHEDULE’ )
order by pp . grantee , pp . owner , pp . table_name , pp . column_name
This one adds a USE_HASH hint. It seems others have run across this query being
a problem. If you add this line in the SETTINGS section of Toad.ini, the query
will use this hint.
HashHintforPrivsQuery=1
Select /*+ USE_HASH(PP,O) */ o . object_type , pp . *
from dba_objects o ,
(Select p. grantee , p. owner , p. table_name , null column_name , p.privilege,
p. grantable
from dba_tab_privs p, dba_users u
where p. grantee = u. username
and p . grantee = : OneObjectName
UNION ALL
Select p. grantee , p. owner , p. table_name , p. column_name , p.privilege, p.
grantable
from dba_col_privs p, dba_users u
where p. grantee = u. username
and p . grantee = : OneObjectName
) pp
where o . OWNER = pp . owner
and o . object_name = pp . table_name
and o .object_type in ( ‘TABLE’ , ‘VIEW’ , ‘SEQUENCE’ , ‘PACKAGE’ , ‘PROCEDURE’
, ‘FUNCTION’ , ‘SNAPSHOT’ , ‘MATERIALIZED VIEW’ , ‘DIRECTORY’ , ‘LIBRARY’ ,
‘TYPE’ , ‘OPERATOR’ , ‘INDEXTYPE’ , ‘EDITION’ , ‘JOB’ , ‘PROGRAM’ , ‘SCHEDULE’ )
order by pp . grantee , pp . owner , pp . table_name , pp . column_name