Title: RE: Do triggers cause a context switch between SQL & PL/SQL
I am not sure ... so far as I know "select count(*) from some_table" without any further group by has always resulted in one row ...
 
Raj
--------------------------------------------------------------------------------
Rajendra dot Jamadagni at nospamespn dot com
All Views expressed in this email are strictly personal.
QOTD: Any clod can have facts, having an opinion is an art !
-----Original Message-----
From: Jacques Kilchoer [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 01, 2003 7:07 PM
To: '[EMAIL PROTECTED]'
Cc: Jamadagni, Rajendra
Subject: RE: Do triggers cause a context switch between SQL & PL/SQL

Your query with the exists would be the same as doing this, right?
select count(*)
  into numrows
from from ApplicationFormCriteria
where ApplicationFormCriteria.applicationFormId = :old.applicationFormId
      and rownum = 1 ;

-----Original Message-----
From: Jamadagni, Rajendra [mailto:[EMAIL PROTECTED]]
Sent: mardi, 1. avril 2003 13:04
To: Multiple recipients of list ORACLE-L
Subject: RE: Do triggers cause a context switch between SQL & PL/SQL


A context switch is order because a trigger is a pl/sql object ...
if you can change the trigger ... instead of count(*) try using exists assuming you have a usable index ...
select count(*)
  into numrows
from dual
where exists ( select 1
                from ApplicationFormCriteria
               where ApplicationFormCriteria.applicationFormId = :old.applicationFormId);
If you have an index on "ApplicationFormCriteria.applicationFormId", this should fly ... and still accomplish what you need.

The basic problem here is the developer doesn't understand the question.
If the question is "Is there at-least one row that mayches a given value so that I can restrict the delete"? then my solution is the right one.

If the question is "How many rows do I have matches a given value so I can ... "? then the SQL you have is the right one.

Looking at the pl/sql code, the question is the former one and the SQL used by the developer is the wrong one. When you do a count(*) oracle will search the table till the HWM, if the table is large, it will make lot of difference.  Where the query above will stop after it finds the first matching row, most likely doing less work that the query you have.

You can say I am picking on the semantics, but see how much difference it makes?

*********************************************************************This e-mail 
message is confidential, intended only for the named recipient(s) above and may 
contain information that is privileged, attorney work product or exempt from 
disclosure under applicable law. If you have received this message in error, or are 
not the named recipient(s), please immediately notify corporate MIS at (860) 766-2000 
and delete this e-mail message from your computer, Thank 
you.*********************************************************************1

Reply via email to