Subject | First Keyword (Performance question, not related to why is it there) |
---|---|
Author | Jason Frey |
Post date | 2002-07-12T23:42:58Z |
After reading the tribulations of the guy with the problem with first being
a keyword, I started wondering about performance.
Obviously, select first 1 * from people is going to be better than select *
from people (Assuming people has more than one record).
However, I'm wondering which of the following examples is going to be "the"
best for determining whether anyone with a certain last name exists
(indexed)?
select first 1 lname from people where lname = 'Smith'; // Only grabs the
first, but has to return a string. Result string has the potential to be
large, depending on column definition
select count(*) from people where lname = 'Smith'; // Has to count
everything, but it returns a single integer. My thought is that the index
might have this number already.
select first 1 count(*) from people where lname = 'Smith'; // Yeah yeah..
But it lets you do it, so I thought I'd throw it in. :)
Basically, I guess I'm wondering what people do if all they want to is check
for existance of a record, and why. I will typically do a regular count(*),
just because I've found myself needing the count later on, for situations I
didn't first envision, that it becomes easier to write the queries like that
in the first place.
Granted, what you do depends on the situation you find yourself in, but I'd
imagine people have a set way they tend to do things (I know I do, like I
said). I'm just wondering what those are and why. What are the performance
tradeoffs, and where does one method start becoming more of a burden then
another?
- Jason
a keyword, I started wondering about performance.
Obviously, select first 1 * from people is going to be better than select *
from people (Assuming people has more than one record).
However, I'm wondering which of the following examples is going to be "the"
best for determining whether anyone with a certain last name exists
(indexed)?
select first 1 lname from people where lname = 'Smith'; // Only grabs the
first, but has to return a string. Result string has the potential to be
large, depending on column definition
select count(*) from people where lname = 'Smith'; // Has to count
everything, but it returns a single integer. My thought is that the index
might have this number already.
select first 1 count(*) from people where lname = 'Smith'; // Yeah yeah..
But it lets you do it, so I thought I'd throw it in. :)
Basically, I guess I'm wondering what people do if all they want to is check
for existance of a record, and why. I will typically do a regular count(*),
just because I've found myself needing the count later on, for situations I
didn't first envision, that it becomes easier to write the queries like that
in the first place.
Granted, what you do depends on the situation you find yourself in, but I'd
imagine people have a set way they tend to do things (I know I do, like I
said). I'm just wondering what those are and why. What are the performance
tradeoffs, and where does one method start becoming more of a burden then
another?
- Jason