Обсуждение: Performances
Hello everyone, A quick question: - how long does it take you to perform that query : "SELECT COUNT(*) FROM A_TABLE;" There are like 56113000 rows in the table. Thanks Cedric
am Thu, dem 28.12.2006, um 10:59:39 +0100 mailte Cedric BUSCHINI folgendes: > Hello everyone, > > A quick question: > - how long does it take you to perform that query : > "SELECT COUNT(*) FROM A_TABLE;" Depends: test=# \timing Timing is on. test=# select count(*) from a_table ; count ------- 0 (1 row) Time: 1.700 ms test=# > > There are like 56113000 rows in the table. A query like above performs a seq. scan on the table - this needs time. You can get an estimation for this value by asking pg_class.reltuples. select reltuples from pg_class where relname='a_table'; But this is only a estimation, depends on actual statistics. It is updated by VACUUM, ANALYZE, and a few DDL commands such as CREATE INDEX. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
Cedric BUSCHINI wrote: > Hello everyone, > > A quick question: > - how long does it take you to perform that query : > "SELECT COUNT(*) FROM A_TABLE;" > Not long :) dev5=# SELECT COUNT(*) FROM A_TABLE; ERROR: relation "a_table" does not exist
Cedric BUSCHINI wrote: > Hello everyone, > > A quick question: > - how long does it take you to perform that query : > "SELECT COUNT(*) FROM A_TABLE;" Longer than I want to wait in any case. In most cases you can rewrite that query to something else; what that something looks like, depends on how exact you want the result to be. So the question to you is, what do you want that number for? -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support