Re: [SQLObject] PostgreSQL: costly count
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Frank B. <fb...@fo...> - 2003-12-04 17:26:16
|
Hallo, J-P Lee hat gesagt: // J-P Lee wrote: > Hmm.. the thread seems to suggest the same thing. I'm not sure if you > can get around the sequential scan. count(id) saves you the time of > fetching all field contents. Fetching field contents is not the problem, I guess, because a count doesn't (or shouldn't) fetch any contents (we didn't ask for them). This message however: http://archives.postgresql.org/pgsql-performance/2003-10/msg00093.php suggests doing a "count(pkey)" instead: <quote> Have you tried doing SELECT count(pkey) rather than count(*) where pkey is the primary key (assuming you have a single field that is a primary key or a unique indexed key). This is MUCH faster in my experience. </qoute> Note that the pkey is not the id-colmun, but an index on this column. I couldn't try this yet, but it might be worth a try. ciao -- Frank Barknecht _ ______footils.org__ |