pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Benedict Holland <benedict.m.holland@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Update blocking a select count(*)?
Date: Fri, 15 Jun 2012 14:51:26 -0500
Message-ID: <4FDB4BEE02000025000484F9@gw.wicourts.gov> (raw )
In-Reply-To: <CAD+mzowzWWea80Vthj_xNuiDOZzyqLpDZpjMgMSY-fHL-ewsCg@mail.gmail.com >
References: <CAD+mzoxfm8Wa5hrekeakG_TYNd_dsTR3W3DPZEV90chuzh0N_A@mail.gmail.com >
<CAEYLb_WqEecnjr5o0DoNh15kNF_FXGkErVKw7fCGM5xxNLmrvQ@mail.gmail.com >
<4FDB3C0202000025000484E4@gw.wicourts.gov >
<CAD+mzozTqB8YiFQsgxU5mMqVo01wxVE0yiwoMHD_uSfSApKt7Q@mail.gmail.com >
<CAD+mzoykMCtGaAKN9jOyH=nDF1E=EORcs4DSAbbKwvt4jJEXsQ@mail.gmail.com >
<4FDB40B702000025000484EE@gw.wicourts.gov >
<CAD+mzowzWWea80Vthj_xNuiDOZzyqLpDZpjMgMSY-fHL-ewsCg@mail.gmail.com >
Benedict Holland <benedict.m.holland@gmail.com> wrote:
> I can even accept the use case that the select should block with
> an Alter Table operation if data is retrieved from the table, but
> a select count(*) only returns the number of rows and should be
> table space independent.
Just as an example of why the data must be scanned for transactional
behavior. Open three connections to the same database. On the
first, run this:
create table t (id int not null);
insert into t select generate_series(1, 1000000);
vacuum analyze t;
begin;
delete from t where id between 1 and 50000;
Then, on the second, run this:
begin;
insert into t select generate_series(1000001, 1000600);
Now, run this on each of the three connections:
select count(*) from t;
You should not get the same count on each one. Depending on your
transactional context, you will get 950000, 1000600, or 1000000.
Over and over as long as the modifying transactions are open. If
you want a fast approximation:
select reltuples from pg_class where oid = 't'::regclass;
reltuples
-----------
1e+06
(1 row)
-Kevin
view thread (18+ messages) latest in thread
Message-ID: <4FDB4BEE02000025000484F9@gw.wicourts.gov>
Permalink: ../4FDB4BEE02000025000484F9@gw.wicourts.gov/
Also on: postgresql.org/message-id/4FDB4BEE02000025000484F9@gw.wicourts.gov
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: Kevin.Grittner@wicourts.gov, benedict.m.holland@gmail.com
Subject: Re: Update blocking a select count(*)?
In-Reply-To: <4FDB4BEE02000025000484F9@gw.wicourts.gov>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox