Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:46:07+00:00 2026-06-15T02:46:07+00:00

I have this statement on Oracle, but it’s very slow. Is it possible to

  • 0

I have this statement on Oracle, but it’s very slow. Is it possible to optimize it?

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')

I tried this (returns the same results), but it’s still very slow

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' 
  )
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:46:09+00:00Added an answer on June 15, 2026 at 2:46 am

    how you tried rewriting it to avoid the repeated hits to the dictionary (the all_ views are sometimes not great performance, as they do a lot of permission checks).

    eg try this:

    with tab as (select cons.owner, cons.constraint_name, cons.r_constraint_name, 
                        cons.constraint_type, cons.table_name, col.column_name 
                   from all_constraints cons
                        inner join all_cons_columns col 
                                on col.constraint_name = cons.constraint_name
                               and col.owner = cons.owner
                  where col.table_name in ('<CHILD TAB>', '<PARENT TAB>')
                    and col.owner = '<OWNER>'
                    and cons.constraint_type in ( 'P', 'R' ))
    select col.owner, col.constraint_name, col.table_name, col.column_name
      from tab col
           inner join tab col2
                   on col.column_name = col2.column_name 
                  and col.table_name = col2.table_name
                  and col.owner = col2.owner
           inner join tab col3
                   on col2.r_constraint_name = col3.constraint_name
     where col2.constraint_type = 'R'
       and col.table_name = '<CHILD TAB>'
       and col2.table_name = '<CHILD TAB>'
       and col.constraint_type = 'P'
       and col3.table_name = '<PARENT TAB>'
       and col3.constraint_type = 'P';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

select max(Key) from MyTable with(nolock) I have this T-SQL statement but need to use
We have this statement: (SELECT res_bev.bev_id, property_value.name AS priority FROM res_bev, bev_property, property_value WHERE
I have this SQL statement: SELECT * FROM history WHERE (fk_person = 2119) AND
I have the following statement being run on an oracle database. SELECT br.Number FROM
I have this statement in my c program and I want to optimize. By
I have this mysql statement: SELECT `review_userid` , `book_id` , `review_id` , `user_class` ,
i have this MySQL statement from a search page, the user enters there postcode
I have following statement in one of the oracle SP: OPEN CUR_NUM FOR SELECT
I have an " select * from tables..joins... " query on an oracle database,
Have been fighting this for two days and am very frustrated but feel like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.