IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Count Sql performance


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sree reddy

New User


Joined: 20 Jul 2007
Posts: 27
Location: bangalore

PostPosted: Tue Aug 25, 2009 2:56 am
Reply with quote

I have a SQl to get the Count in the Program

Select count(*) from xxx
where xxx= :xxxxx

Is there any other method of SQL to get the count without using Count(*) in the SQl

Some people says using count(*) with degrade the performace.

thanks
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Aug 25, 2009 3:15 am
Reply with quote

Hello,

Quote:
Is there any other method of SQL to get the count without using Count(*) in the SQl
Sure, but they all take more resources. . .

Quote:
Some people says using count(*) with degrade the performace.
Counting rows does not cause degradation. Reading rows does. If the predicate in the example is not an index, the entire table must be read. If this is an index, only those rows needed will be read.
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Tue Aug 25, 2009 10:44 am
Reply with quote

Count * does not degrade the performance, even I was also think the same but later found out that sometime count * is been used for the existence check of some of the data in the table or not at the moment we should not use the count * but if the requirement want to have the number of rows present then by using count * will not degrade the performance,
However you can use the SQLERRD or get diagnostic for the same feature, check if these functionality does fit in your requirement.
Back to top
View user's profile Send private message
dejunzhu

Active User


Joined: 08 May 2008
Posts: 390
Location: China

PostPosted: Tue Aug 25, 2009 7:33 pm
Reply with quote

You can use
SELECT COUNT(YOUR_TABLE_PRIMARY_KEY).

This can ensure that you're using index, which is more efficient.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Aug 25, 2009 8:47 pm
Reply with quote

Hello,

Quote:
where xxx= :xxxxx

How does that accomplish the WHERE. . . icon_confused.gif

Care must be taken to post replies that answer the posted question. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts exploiting Z16 performance PL/I & Assembler 2
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
Search our Forums:

Back to Top