Re: [HACKERS] Bug#48582: psql spends hours computing results it already knows (fwd)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
Cc: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>, pgsql-hackers(at)postgreSQL(dot)org, Brian Ristuccia <brianr(at)osiris(dot)978(dot)org>, 48582(at)bugs(dot)debian(dot)org
Subject: Re: [HACKERS] Bug#48582: psql spends hours computing results it already knows (fwd)
Date: 1999-10-28 23:05:56
Message-ID: 29602.941151956@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Ross J. Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu> writes:
> Hmm, that happens to not be the case. The rows=XXXX number is drawn
> from the statistics for the table, which are only updated on VACUUM
> ANALYZE of that table. Easily tested: just INSERT a couple rows and do
> the EXPLAIN again. The rows=XXX won't change.

The short answer to this is that maintaining a perfectly accurate tuple
count on-the-fly would almost certainly cost more, totalled over all
operations that modify a table, than we could ever hope to make back
by short-circuiting "select count(*)" operations. (Consider
concurrent transactions running in multiple backends, some of which
may abort instead of committing, and others of which may already have
committed but your transaction is not supposed to be able to see their
effects...)

The optimizer is perfectly happy with approximate tuple counts, so it
makes do with stats recorded at the last VACUUM.

This has been discussed quite recently on pg-hackers; see the archives
for more info.

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-10-29 00:27:43 Re: [HACKERS] psql Week 4.142857
Previous Message Tom Lane 1999-10-28 22:58:12 Re: [HACKERS] psql Week 4.142857