pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
@ 2026-11-18 15:42  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Melanie Plageman @ 2026-11-18 15:42 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8c15c2cb5c49efcc6fa845f09d7619e0163e3259

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
@ 2026-11-18 15:46  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Melanie Plageman @ 2026-11-18 15:46 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ebc86fb8828ba7ef7d164848d990f57d2cf834e5

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
@ 2026-11-18 15:53  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Melanie Plageman @ 2026-11-18 15:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
@ 2026-11-18 15:56  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Melanie Plageman @ 2026-11-18 15:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/371565fc57f864942baf19520b2983e448e5b0e5

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
@ 2026-11-18 15:58  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Melanie Plageman @ 2026-11-18 15:58 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7a733b9547c171e756d2934c77805568ba716ef7

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
@ 2026-11-18 16:02  Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Melanie Plageman @ 2026-11-18 16:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/33ac2b000eaba9664c9c8fa7397629ac59c44dc8

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(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: pgsql: Fix pgstattuple_approx handling of unknown tuple estimates
@ 2026-11-18 18:18  Melanie Plageman <melanieplageman@gmail.com>
  parent: Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Melanie Plageman @ 2026-11-18 18:18 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

On Wed, Nov 18, 2026 at 10:43 AM Melanie Plageman
<melanieplageman@gmail.com> wrote:
>
> 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.

Looks like I broke the buildfarm with the new test

# @@ -257,11 +257,7 @@
#  commit;
#  select scanned_percent, approx_tuple_count
#    from pgstattuple_approx('test_approx_unknown');
# - scanned_percent | approx_tuple_count
# ------------------+--------------------
# -               0 |                  0
# -(1 row)
# -
# +ERROR:  cannot access temporary tables during a parallel operation
#  -- not for the index calls though, of course
#  select pgstatindex('test_partition');
#  ERROR:  relation "test_partition" is not a btree index
# 1 of 1 tests failed.

Something about debug_parallel_query setting that didn't fail locally.
I will investigate and push a fix.

- Melanie






^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2026-11-18 18:18 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 15:42 pgsql: Fix pgstattuple_approx handling of unknown tuple estimates Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 18:18 ` Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 15:46 pgsql: Fix pgstattuple_approx handling of unknown tuple estimates Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 15:53 pgsql: Fix pgstattuple_approx handling of unknown tuple estimates Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 15:56 pgsql: Fix pgstattuple_approx handling of unknown tuple estimates Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 15:58 pgsql: Fix pgstattuple_approx handling of unknown tuple estimates Melanie Plageman <melanieplageman@gmail.com>
2026-11-18 16:02 pgsql: Fix pgstattuple_approx handling of unknown tuple estimates Melanie Plageman <melanieplageman@gmail.com>

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