On 2001-07-08 12:52:45 -0700, Tim Harsch wrote:
> Yes,I realized,thanks. My post is to try to understand speed issues behind
> an existence query. Once I understand that better... then the portability,
> and how that will come into play in DBI, can come next. :-)
>
> So, just to reiterate, what I'm after is this... if the following query
> returns 1 million rows:
> select * from some_table where some_column = 'some_value'
>
> then, for sure:
> select count(*) from some_table where some_column = 'some_value'
> accesses all pages on the disk that contain those rows.
Generally yes, but the original poster was asking about a *primary key*.
Since there can be at most one column with this key, the query will only
access the index for a single row (not even the row itself).
Even if it isn't a primary key, you can probably still reduce the cost
to a simple index range scan by putting a non-unique index on the
column.
I don't know how "exists" is implemented in oracle or sybase.
hp
--
_ | Peter J. Holzer | It's nice to fix problems by accident.
|_|_) | Sysadmin WSR / LUGA | -- Theo de Raadt
| | | [EMAIL PROTECTED] | <[EMAIL PROTECTED]>
__/ | http://www.hjp.at/ | on bugtraq 2001-03-19
PGP signature