Subject | RE: [ib-support] Re: COUNT(*) versus COUNT(primary_key) |
---|---|
Author | Robert DiFalco |
Post date | 2003-04-30T18:59:03Z |
Basically, for a Web UI, I have to do paged queries using SELECT
FIRST...SKIP. I specify the page and the page size. Unfortunately, I
also have to find the total count of the records matching the SELECT
criteria so that I can know how many pages of data exist. The only way I
know how to do this is to do the query omitting the values and order and
replacing the values with COUNT(*) first to get the totalRecords. Then I
perform the paged select query. Finally I divide totalRecords by the
pageSize value to know how many pages there are to display. I'm
definitely open to a better method for this.
R.
-----Original Message-----
From: Alexander V.Nevsky [mailto:ded@...]
Sent: Wednesday, April 30, 2003 11:38 AM
To: ib-support@yahoogroups.com
Subject: [ib-support] Re: COUNT(*) versus COUNT(primary_key)
--- In ib-support@yahoogroups.com, "Robert DiFalco"
<rdifalco@t...>
wrote:
Robert, Count(column) should be a little slower than Count(*)
because first should check column values for NULL and don't
count such
a rows. Don't think difference will be distinguished by human
eye.
Note Count is one of slow operations because index can't be used
even
if you count PK columns - engine should count rows which
transaction
within which context statement run can see and this can be
performed
only by visiting data pages. So I recommend to don't use it just
with
decorative purposes - to show user that select return 30654 rows
for
example, informativity is low and price is high. If you need to
determine just presence of rows complyed to some conditions, use
Exists instead of Count.
Best regards, Alexander.
Yahoo! Groups Sponsor
<http://rd.yahoo.com/M=229633.3212141.4526654.2595810/D=egroupweb/S=1705
115386:HM/A=1556779/R=0/*http://shop.store.yahoo.com/cgi-bin/clink?ftd2+
shopping:dmad/M=229633.3212141.4526654.2595810/D=egroupweb/S=1705115386:
HM/A=1556779/R=1/1051727857+http://us.rmi.yahoo.com/rmi/http://www.ftd.c
om/rmi-framed-url/http://www.ftd.com/yahoo36>
<http://us.adserver.yahoo.com/l?M=229633.3212141.4526654.2595810/D=egrou
pmail/S=:HM/A=1556779/rand=439707175>
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .
[Non-text portions of this message have been removed]
FIRST...SKIP. I specify the page and the page size. Unfortunately, I
also have to find the total count of the records matching the SELECT
criteria so that I can know how many pages of data exist. The only way I
know how to do this is to do the query omitting the values and order and
replacing the values with COUNT(*) first to get the totalRecords. Then I
perform the paged select query. Finally I divide totalRecords by the
pageSize value to know how many pages there are to display. I'm
definitely open to a better method for this.
R.
-----Original Message-----
From: Alexander V.Nevsky [mailto:ded@...]
Sent: Wednesday, April 30, 2003 11:38 AM
To: ib-support@yahoogroups.com
Subject: [ib-support] Re: COUNT(*) versus COUNT(primary_key)
--- In ib-support@yahoogroups.com, "Robert DiFalco"
<rdifalco@t...>
wrote:
> In the case where these are functionally equivalent, is thereany
> performance difference between the two that I should be awareof?
Robert, Count(column) should be a little slower than Count(*)
because first should check column values for NULL and don't
count such
a rows. Don't think difference will be distinguished by human
eye.
Note Count is one of slow operations because index can't be used
even
if you count PK columns - engine should count rows which
transaction
within which context statement run can see and this can be
performed
only by visiting data pages. So I recommend to don't use it just
with
decorative purposes - to show user that select return 30654 rows
for
example, informativity is low and price is high. If you need to
determine just presence of rows complyed to some conditions, use
Exists instead of Count.
Best regards, Alexander.
Yahoo! Groups Sponsor
<http://rd.yahoo.com/M=229633.3212141.4526654.2595810/D=egroupweb/S=1705
115386:HM/A=1556779/R=0/*http://shop.store.yahoo.com/cgi-bin/clink?ftd2+
shopping:dmad/M=229633.3212141.4526654.2595810/D=egroupweb/S=1705115386:
HM/A=1556779/R=1/1051727857+http://us.rmi.yahoo.com/rmi/http://www.ftd.c
om/rmi-framed-url/http://www.ftd.com/yahoo36>
<http://us.adserver.yahoo.com/l?M=229633.3212141.4526654.2595810/D=egrou
pmail/S=:HM/A=1556779/rand=439707175>
To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .
[Non-text portions of this message have been removed]