Reid Thompson escreveu:
On Tue, 2007-11-06 at 14:39 -0300, André Volpato wrote:Remember that you can always use serial fields to count a table, like: I meant to select using an index. I´ve done the same tests here, and realized that my server is two times slower than yours: testeprog=# select version(); version --------------------------------------------------------------------------------------------------------- PostgreSQL 8.1.4 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7) (1 row) testeprog=# select count(*) from test; count ---------- 10000000 (1 row) Time: 4116.613 ms testeprog=# alter table test add id serial; NOTICE: ALTER TABLE will create implicit sequence "test_id_seq" for serial column "test.id" ALTER TABLE Time: 90617.195 ms testeprog=# select id from test order by id desc limit 1; id ---------- 10000000 (1 row) Time: 64856.553 ms testeprog=# create unique index itest1 on test using btree (id); CREATE INDEX Time: 29026.891 ms testeprog=# explain analyze select id from test order by id desc limit 1; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..0.02 rows=1 width=4) (actual time=0.017..0.019 rows=1 loops=1) -> Index Scan Backward using itest1 on test (cost=0.00..185954.00 rows=10000000 width=4) (actual time=0.014..0.014 rows=1 loops=1) Total runtime: 0.059 ms (3 rows) @Bill: Bill Moran wrote I don't think so. What kind of accuracy do you have when rows are deleted? Also, sequences are not transactional, so rolled-back transactions will increment the sequence without actually adding rows. You are right, the serial hack should not work in most oltp cases. -- ACV |
- [GENERAL] Postgresql simple query performance qu... SHARMILA JOTHIRAJAH
- Re: [GENERAL] Postgresql simple query perfo... Pavel Stehule
- Re: [GENERAL] Postgresql simple query p... Reg Me Please
- Re: [GENERAL] Postgresql simple que... Bill Moran
- Re: [GENERAL] Postgresql simple... Reg Me Please
- Re: [GENERAL] Postgresql s... Richard Huxton
- Re: [GENERAL] Postgres... André Volpato
- Re: [GENERAL] Post... Bill Moran
- Re: [GENERAL] Post... André Volpato
- Re: [GENERAL] Post... Reg Me Please
- Re: [GENERAL] Postgresql simple query perfo... Bill Moran
- Re: [GENERAL] Postgresql simple query p... Simon Riggs
- Re: [GENERAL] Postgresql simple query perfo... SHARMILA JOTHIRAJAH
- Re: [GENERAL] Postgresql simple query p... Gokulakannan Somasundaram
- Re: [GENERAL] Postgresql simple query p... Gregory Stark
- Re: [GENERAL] Postgresql simple query perfo... SHARMILA JOTHIRAJAH
- Re: [GENERAL] Postgresql simple query perfo... SHARMILA JOTHIRAJAH
- Re: [GENERAL] Postgresql simple query p... Reg Me Please
