Skip to main content
Participant
June 4, 2012
Question

Query the database;

  • June 4, 2012
  • 2 replies
  • 1436 views

Hello;

My application is running the following query:

SELECT NULL AS pktable_cat,

      p.owner as pktable_schem,

      p.table_name as pktable_name,

      pc.column_name as pkcolumn_name,

      NULL as fktable_cat,

      f.owner as fktable_schem,

      f.table_name as fktable_name,

      fc.column_name as fkcolumn_name,

      fc.position as key_seq,

      NULL as update_rule,

      decode (f.delete_rule, 'CASCADE', 0, 'SET NULL', 2, 1) as delete_rule,

      f.constraint_name as fk_name,

      p.constraint_name as pk_name,

      decode(f.deferrable, 'DEFERRABLE',5 ,'NOT DEFERRABLE',7 , 'DEFERRED', 6 ) deferrability

FROM all_cons_columns pc,

      all_constraints p,

      all_cons_columns fc,

      all_constraints f

WHERE 1 = 1 AND

      p.table_name = '?' /*Bind1*/ AND

      p.owner = '?' /*Bind2*/ AND

      f.constraint_type = 'R' AND

      p.owner = f.r_owner AND

      p.constraint_name = f.r_constraint_name AND

      p.constraint_type = 'P' AND

      pc.owner = p.owner AND

      pc.constraint_name = p.constraint_name AND

      pc.table_name = p.table_name AND

      fc.owner = f.owner AND

      fc.constraint_name = f.constraint_name AND

      fc.table_name = f.table_name AND

      fc.position = pc.position

ORDER BY fktable_schem, fktable_name, key_seq

We use the CF9 and the database is ORACLE 11G.

The same is performed several times a day and it's hurting the performance of queries in my system. How to fix it, or remove from the application;

It is executed by the same driver ?

thanks;

Jaider Fraga;

    This topic has been closed for replies.

    2 replies

    Sreeindia
    Participating Frequently
    June 5, 2012

    Hello

    As Mr Dan mentioned, you can do move the condition mentioned in 'where' clause to Join statements .Something like below

    SELECT NULL AS pktable_cat,

          p.owner as pktable_schem,

          p.table_name as pktable_name,

          pc.column_name as pkcolumn_name,

          NULL as fktable_cat,

          f.owner as fktable_schem,

          f.table_name as fktable_name,

          fc.column_name as fkcolumn_name,

          fc.position as key_seq,

          NULL as update_rule,

          decode (f.delete_rule, 'CASCADE', 0, 'SET NULL', 2, 1) as delete_rule,

          f.constraint_name as fk_name,

          p.constraint_name as pk_name,

          decode(f.deferrable, 'DEFERRABLE',5 ,'NOT DEFERRABLE',7 , 'DEFERRED', 6 ) deferrability

    FROM all_cons_columns pc ,

          INNER JOIN all_constraints p ON

                   p.table_name = '?' /*Bind1*/ AND

                   p.owner = '?' /*Bind2*/ AND,

                   p.constraint_type = 'P' AND,

                   pc.owner = p.owner AND,

                   pc.constraint_name = p.constraint_name AND,

                   pc.table_name = p.table_name

          INNER JOIN all_cons_columns fc ON

                   fc.position = pc.position

          INNER JOIN all_constraints f

                   f.constraint_type = 'R' AND

                   p.owner = f.r_owner AND

                   p.constraint_name = f.r_constraint_name AND

                   fc.owner = f.owner AND

                   fc.constraint_name = f.constraint_name AND

                   fc.table_name = f.table_name

    WHERE 1 = 1

    ORDER BY fktable_schem, fktable_name, key_seq

    Advantage is that if you are using the conditions in join statement the query results are filtered on joinning tables itself rather than taking the whole data and gets filtered by where clause. This will improve the query performance and the results will also be correct ones

    Hope this help

    Regards

    Sreekar

    Participant
    June 5, 2012

    Ok, Sreeindia

    The problem is that I can not find where it is called or executed;

    It seems the driver is running on Oracle or ColdFusion code;

    Thanks.

    Obrigado.

    Jaider Sousa Fraga

    Gerente de Projetos

    Ministério da Saúde - SE/DATASUS/CGAM

    Esplanada dos Ministérios Bloco G Anexo A Sala 171A

    jaider.fraga@saude.gov.br<mailto:jaider.fraga@saude.gov.br>

    Fone: (61) 3315.3274 VOIP: 1267

    De: Sreeindia

    Enviada em: terça-feira, 5 de junho de 2012 08:56

    Para: Jaider Sousa Fraga

    Assunto: Query the database;

    Re: Query the database;

    created by Sreeindia<http://forums.adobe.com/people/Sreeindia> in ColdFusion - View the full discussion<http://forums.adobe.com/message/4466290#4466290

    Sreeindia
    Participating Frequently
    June 6, 2012

    Hi

    I hope you tried running a search in entire application for the instances of the result values  (such as pktable_cat,pktable_schem ) etc. This will help you to understand the please its used

    Regards

    Sreekar

    Inspiring
    June 4, 2012

    To make it run faster you can put your joins in the from clause instead of the where clause.  You can also make it a stored procedure.

    If you want to remove it, find out where you are using the results and see if there is another way.

    Participant
    June 5, 2012

    Ok, Dan Bracuk

    The problem is that I can not find where it is called or executed;

    It seems the driver is running on Oracle or ColdFusion code;

    Thanks.

    Jaider Sousa Fraga

    Gerente de Projetos

    Ministério da Saúde - SE/DATASUS/CGAM

    Esplanada dos Ministérios Bloco G Anexo A Sala 171A

    jaider.fraga@saude.gov.br<mailto:jaider.fraga@saude.gov.br>

    Fone: (61) 3315.3274 VOIP: 1267

    De: Dan Bracuk

    Enviada em: segunda-feira, 4 de junho de 2012 18:38

    Para: Jaider Sousa Fraga

    Assunto: Query the database;

    Re: Query the database;

    created by Dan Bracuk<http://forums.adobe.com/people/Dan+Bracuk> in ColdFusion - View the full discussion<http://forums.adobe.com/message/4464839#4464839