Tenho um programa para buscar dependencias de registros para proceder com exclusão de dados aqui na empresa. Temos suporte a alguns bancos mas no Oracle
a query é processada com muita lentidão (cerca de 10 a 15 segundos para cada tabela em bancos de produção remotos).
Queries para consulta
Tabelas pais
SELECT DISTINCT c_pk.table_name table_name, CAST(a.column_name AS
VARCHAR(100)) as MainColumnName, a.constraint_name, a.position,
a.table_name as r_table_name, c_pk.constraint_name r_pk,
CAST((SELECT ax.column_name FROM all_cons_columns ax
WHERE ax.owner = c_pk.owner
AND ax.constraint_name = c_pk.constraint_name
AND ax.position = a.position) as VARCHAR(100)) as column_name
FROM all_cons_columns a
INNER JOIN all_constraints c ON a.owner = c.owner
AND a.constraint_name = c.constraint_name
INNER JOIN all_constraints c_pk ON c.r_owner = c_pk.owner
AND c.r_constraint_name = c_pk.constraint_name
WHERE c.constraint_type = ''R''
AND a.table_name = ''%s''
ORDER BY
table_name, constraint_name, position
Tabelas filhas
SELECT a.table_name, CAST(a.column_name AS VARCHAR(100)) as
column_name, a.constraint_name, a.position,
c_pk.table_name r_table_name, c_pk.constraint_name r_pk,
CAST((SELECT ax.column_name FROM all_cons_columns ax
WHERE ax.owner = c_pk.owner
AND ax.constraint_name = c_pk.constraint_name
AND ax.position = a.position) as VARCHAR(100)) as MainColumnName
FROM all_cons_columns a
JOIN all_constraints c ON a.owner = c.owner
AND a.constraint_name = c.constraint_name
JOIN all_constraints c_pk ON c.r_owner = c_pk.owner
AND c.r_constraint_name = c_pk.constraint_name
WHERE c.constraint_type = ''R''
AND c_pk.table_name = ''%s''
ORDER BY
table_name, constraint_name, position
Existe alguma maneira mais rápida de consultar estes dados?