-1

私は Oracle でこのステートメントを持っていますが、非常に遅いです。それを最適化することは可能ですか?

SELECT col2.column_name 
FROM all_constraints cons, all_cons_columns col, all_cons_columns col2, all_constraints cons2
WHERE cons.owner = 'OWNER' 
AND cons.table_name = 'TABLE'
AND col.constraint_name = cons.constraint_name 
AND cons.constraint_type  = 'P'
AND col2.column_name  = col.column_name 
AND col2.table_name = col.table_name 
AND col2.owner = col.owner 
AND cons2.constraint_name = col2.constraint_name 
AND cons2.constraint_type = 'R'
AND cons2.r_constraint_name 
IN (SELECT parentcol.constraint_name FROM all_cons_columns parentCol WHERE parentcol.owner = 'OWNER2' AND parentcol.table_name = 'TABLE2')

私はこれを試しました(同じ結果を返します)が、それでも非常に遅いです

SELECT *
FROM all_constraints cons, all_cons_columns col
WHERE col.table_name = 'TABLE2' AND col.Owner = 'OWNER2'
AND col.constraint_name = cons.constraint_name AND cons.constraint_type = 'P' AND 
col.column_name IN 
(
  SELECT col2.column_name
  FROM all_constraints cons2, all_cons_columns col2
  WHERE col2.table_name = 'TABLE2' AND col2.Owner = 'OWNER2'
  AND col2.constraint_name = cons2.constraint_name AND cons2.constraint_type = 'R'
  AND cons2.r_constraint_name IN
  (
    SELECT cons3.constraint_name
    FROM all_constraints cons3, all_cons_columns col3
    WHERE col3.table_name = 'TABLE' AND col3.Owner = 'OWNER'
    AND col3.constraint_name = cons3.constraint_name AND cons3.constraint_type = 'P' 
  )
)
4

1 に答える 1