pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Melanie Plageman <melanieplageman@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
Date: Wed, 18 Nov 2026 15:53:35 +0000
Message-ID: <E1xThyY-00000000G4v-0Mdo@gemulon.postgresql.org> (raw)

Fix pgstattuple_approx handling of unknown tuple estimates

vac_estimate_reltuples() can return -1 when there is not enough
information to estimate the number of live tuples. pgstattuple_approx()
assigned that value to an unsigned counter before attempting to clamp
it, making the clamp ineffective and exposing -1 through the bigint
result.

Clamp the signed estimate before assigning it to the unsigned counter.

Reported-by: Zsolt Parragi <zsolt.parragi@percona.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAN4CZFM0y8t%2BAQ8PWTeuBXnFtRDUNvkfVzzA_yo6uJ2bceK%3DxA%40mail.gmail.com
Backpatch-through: 15

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/23a8402f8bdb98cad0baa144ffb7a7d3b4fc7964

Modified Files
--------------
contrib/pgstattuple/expected/pgstattuple.out | 12 ++++++++++++
contrib/pgstattuple/pgstatapprox.c           |  9 +++++----
contrib/pgstattuple/sql/pgstattuple.sql      | 10 ++++++++++
doc/src/sgml/pgstattuple.sgml                |  3 ++-
4 files changed, 29 insertions(+), 5 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xThyY-00000000G4v-0Mdo@gemulon.postgresql.org>
Permalink:  ../E1xThyY-00000000G4v-0Mdo@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xThyY-00000000G4v-0Mdo@gemulon.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: melanieplageman@gmail.com
  Subject: Re: pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
  In-Reply-To: <E1xThyY-00000000G4v-0Mdo@gemulon.postgresql.org>
  References: <E1xThyY-00000000G4v-0Mdo@gemulon.postgresql.org>

* 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