Pass heap tuple counts to parallel vacuum as double

Started by Baji Shaik14 days ago5 messageshackers
Jump to latest
#1Baji Shaik
baji.pgdev@gmail.com

Hi,

I noticed that parallel_vacuum_bulkdel_all_indexes() and
parallel_vacuum_cleanup_all_indexes() take the heap tuple count as long,
while lazy vacuum passes a double and vacuumparallel.c stores it as a
double in shared memory for the index AMs. Where long is 32 bits, as on
Windows, a table with more than about 2.1 billion tuples gets a wrong
num_heap_tuples only when its indexes are vacuumed in parallel. It's
rare in practice, but the serial path has no such limit.

The attached patch changes the parameter to double.

Thoughts?

Thanks,
Baji Shaik

Attachments:

t258378_1
0001-Pass-heap-tuple-counts-to-parallel-vacuum-as-double.patchapplication/octet-stream; name=0001-Pass-heap-tuple-counts-to-parallel-vacuum-as-double.patchDownload+4-5
#2Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Baji Shaik (#1)
Re: Pass heap tuple counts to parallel vacuum as double

On Mon, Nov 9, 2026 at 3:16 PM Baji Shaik <baji.pgdev@gmail.com> wrote:

Hi,

I noticed that parallel_vacuum_bulkdel_all_indexes() and
parallel_vacuum_cleanup_all_indexes() take the heap tuple count as long,
while lazy vacuum passes a double and vacuumparallel.c stores it as a
double in shared memory for the index AMs. Where long is 32 bits, as on
Windows, a table with more than about 2.1 billion tuples gets a wrong
num_heap_tuples only when its indexes are vacuumed in parallel. It's
rare in practice, but the serial path has no such limit.

The attached patch changes the parameter to double.

Thank you for the report. The change looks good to me. I’m going to
push it to master only, barring objections. Although it’s an oversight
in commit 8e1fae193864, it can’t be backpatched, since it changes the
function signatures.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

#3Chao Li
li.evan.chao@gmail.com
In reply to: Masahiko Sawada (#2)
Re: Pass heap tuple counts to parallel vacuum as double

On Nov 10, 2026, at 09:46, Masahiko Sawada <sawada.mshk@gmail.com> wrote:

On Mon, Nov 9, 2026 at 3:16 PM Baji Shaik <baji.pgdev@gmail.com> wrote:

Hi,

I noticed that parallel_vacuum_bulkdel_all_indexes() and
parallel_vacuum_cleanup_all_indexes() take the heap tuple count as long,
while lazy vacuum passes a double and vacuumparallel.c stores it as a
double in shared memory for the index AMs. Where long is 32 bits, as on
Windows, a table with more than about 2.1 billion tuples gets a wrong
num_heap_tuples only when its indexes are vacuumed in parallel. It's
rare in practice, but the serial path has no such limit.

The attached patch changes the parameter to double.

Thank you for the report. The change looks good to me. I’m going to
push it to master only, barring objections. Although it’s an oversight
in commit 8e1fae193864, it can’t be backpatched, since it changes the
function signatures.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

The patch also looks good to me.

I wonder if we can still get this into 19, as it hasn’t been released yet. This may be our last chance to change these function signatures for 19.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#4Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Chao Li (#3)
Re: Pass heap tuple counts to parallel vacuum as double

Hi,

On Mon, Nov 9, 2026 at 10:03 PM Chao Li <li.evan.chao@gmail.com> wrote:

The patch also looks good to me.

Yes, it LGTM too.

"long" is a signed 8 bytes everywhere except on Windows, where it is 4
bytes, and passing a number of tuples more than the 4-byte limit could
potentially expose it to overflows.

-Wfloat-conversion tells me there are other such uses [1]gininsert.c:1689:4: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] vacuumlazy.c:2568:52: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] vacuumlazy.c:3012:52: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] nbtsort.c:499:4: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] vacuum.c:2568:13: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] variable.c:333:16: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] (haven't
checked in depth whether these are worth fixing, and even if they need
to be, in a separate thread of course).

I wonder if we can still get this into 19, as it hasn’t been released yet. This may be our last chance to change these function signatures for 19.

+1 to back-patch to PG19 (assuming we have another release after RC2
before the planned GA on Nov 19th) to avoid the overflow issues and
keep the version diff small.

[1]: gininsert.c:1689:4: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] vacuumlazy.c:2568:52: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] vacuumlazy.c:3012:52: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] nbtsort.c:499:4: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] vacuum.c:2568:13: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion] variable.c:333:16: warning: conversion to 'long int' from 'double' may alter its value [-Wfloat-conversion]
'double' may alter its value [-Wfloat-conversion]
vacuumlazy.c:2568:52: warning: conversion to 'long int' from 'double'
may alter its value [-Wfloat-conversion]
vacuumlazy.c:3012:52: warning: conversion to 'long int' from 'double'
may alter its value [-Wfloat-conversion]
nbtsort.c:499:4: warning: conversion to 'long int' from 'double' may
alter its value [-Wfloat-conversion]
vacuum.c:2568:13: warning: conversion to 'long int' from 'double' may
alter its value [-Wfloat-conversion]
variable.c:333:16: warning: conversion to 'long int' from 'double' may
alter its value [-Wfloat-conversion]

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com

#5Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Bharath Rupireddy (#4)
Re: Pass heap tuple counts to parallel vacuum as double

On Wed, Nov 11, 2026 at 9:13 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

Hi,

On Mon, Nov 9, 2026 at 10:03 PM Chao Li <li.evan.chao@gmail.com> wrote:

The patch also looks good to me.

Yes, it LGTM too.

"long" is a signed 8 bytes everywhere except on Windows, where it is 4
bytes, and passing a number of tuples more than the 4-byte limit could
potentially expose it to overflows.

-Wfloat-conversion tells me there are other such uses [1] (haven't
checked in depth whether these are worth fixing, and even if they need
to be, in a separate thread of course).

I wonder if we can still get this into 19, as it hasn’t been released yet. This may be our last chance to change these function signatures for 19.

+1 to back-patch to PG19 (assuming we have another release after RC2
before the planned GA on Nov 19th) to avoid the overflow issues and
keep the version diff small.

Agreed to backpatch to v19.

I've just pushed the fix. Thank you!

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com