Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > table count

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-03, 17:53
koxuz koxuz is offline
Registered User
 
Join Date: Jul 2003
Posts: 1
table count

hi,

is it normal that when i issue a "select count(*) from <table>" command postgres performs a sequential scan in order to evaluate the number of items in that table? i have a table with almost 3 million entires and the operations takes several seconds to complete. the server has plenty of ram and is fast enough.

koxuz
Reply With Quote
  #2 (permalink)  
Old 07-13-03, 18:00
eperich eperich is offline
Registered User
 
Join Date: Sep 2001
Location: Vienna
Posts: 398
count

this is a well known problem in postgresql

this has to be I think of some transactional reasons

but there are attempts to getting rid of this seq scan
__________________
http://www.postgresql.org
--Postgresql is the only kind of thing--
Reply With Quote
  #3 (permalink)  
Old 07-14-03, 09:34
karim2k karim2k is offline
Registered User
 
Join Date: Apr 2003
Location: Tunisia
Posts: 192
Thumbs up Try this

In order to to get fatsre reponse you could shorten you query by just counting one row select count(row) from <table>, or just get the max of the id if u have a regular counter , or just create a row updated with a trigger (on upsdte/insert/delete) that saves the number of rows.

Good Luck !
__________________
Open up
Take a look to my Blog http://www.rundom.com/karim2k
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On