| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
|  |  | |||
Home -> Community -> Usenet -> c.d.o.server -> Re: Checking if more than 0 rows exist.
Frank van Bortel wrote:
> Jeremy wrote: >
> I have not seen any comparism - you'll have to do that. > Basically, an exists will do something similar; stop reading > after the first match.
Here's the reality check on this discussion:
SELECT COUNT(*)
FROM bar
WHERE office = 45
AND statement = 199901
AND rownum = 1;
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1 Card=1 Bytes=26) 1 0 SORT (AGGREGATE)
    2    1     COUNT (STOPKEY)
    3    2       TABLE ACCESS (BY INDEX ROWID) OF 'BAR' (TABLE) (Cost=1 
Card=4 Bytes=104)
    4    3         INDEX (RANGE SCAN) OF 'IX_BAR_OFFICE' (INDEX) (Cost=1 
Card=4)
Statistics
           5  recursive calls
           0  db block gets
          27  consistent gets
           0  physical reads
           0  redo size
         420  bytes sent via SQL*Net to client
         508  bytes received via SQL*Net from client
           2  SQL*Net roundtrips to/from client
           0  sorts (memory)
           0  sorts (disk)
           1  rows processed
=======================================================================
SELECT 1
FROM dual
WHERE EXISTS (
   SELECT *
   FROM bar
   WHERE office = 45
   AND statement = 199901);
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=1) 1 0 FILTER
    2    1     FAST DUAL (Cost=2 Card=1)
    3    1     TABLE ACCESS (BY INDEX ROWID) OF 'BAR' (TABLE) (Cost=1 
Card=4 Bytes=104)
    4    3       INDEX (RANGE SCAN) OF 'IX_BAR_OFFICE' (INDEX) (Cost=1 
Card=4)
Statistics
           4  recursive calls
           0  db block gets
          27  consistent gets
           0  physical reads
           0  redo size
         413  bytes sent via SQL*Net to client
         508  bytes received via SQL*Net from client
           2  SQL*Net roundtrips to/from client
           0  sorts (memory)
           0  sorts (disk)
           1  rows processed
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace 'x' with 'u' to respond)Received on Tue May 10 2005 - 10:27:21 CDT
|  |  |