Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

Started by Yugo Nagata7 months ago13 messages
Jump to latest
#1Yugo Nagata
nagata@sraoss.co.jp

Hi,

I found that "vacuumdb --missing-stats-only" always performs ANALYZE
on tables with a virtual generated column, since such columns currently
never have statistics. This seems like an obvious waste, so I've attached
a patch to fix it, ensuring that virtual generated columns are not
regarded as missing statistics.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

0001-Don-t-treat-virtual-generated-columns-as-missing-sta.patchtext/x-diff; name=0001-Don-t-treat-virtual-generated-columns-as-missing-sta.patchDownload+3-1
#2Fujii Masao
masao.fujii@gmail.com
In reply to: Yugo Nagata (#1)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Wed, Aug 20, 2025 at 10:42 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

I found that "vacuumdb --missing-stats-only" always performs ANALYZE
on tables with a virtual generated column, since such columns currently
never have statistics. This seems like an obvious waste, so I've attached
a patch to fix it, ensuring that virtual generated columns are not
regarded as missing statistics.

Thanks for the report and patch! This seems to be an oversight from
the commit that added virtual generated columns.

For the patch, shouldn't we also add a regression test for --missing-stats-only
with generated columns, to prevent this issue from happening again?

Regards,

--
Fujii Masao

#3Yugo Nagata
nagata@sraoss.co.jp
In reply to: Fujii Masao (#2)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Wed, 20 Aug 2025 12:49:14 +0900
Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Aug 20, 2025 at 10:42 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

I found that "vacuumdb --missing-stats-only" always performs ANALYZE
on tables with a virtual generated column, since such columns currently
never have statistics. This seems like an obvious waste, so I've attached
a patch to fix it, ensuring that virtual generated columns are not
regarded as missing statistics.

Thanks for the report and patch! This seems to be an oversight from
the commit that added virtual generated columns.

For the patch, shouldn't we also add a regression test for --missing-stats-only
with generated columns, to prevent this issue from happening again?

Thank you for reviewing the patch and your suggestion.

I agree that we should add a test, since the behavior may change in the future
when statistics begin to be collected for virtual generated columns, and the test
will serve as a reminder when this behavior changes.

I've attached a updated patch including the test.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

v2-0001-Don-t-treat-virtual-generated-columns-as-missing-.patchtext/x-diff; name=v2-0001-Don-t-treat-virtual-generated-columns-as-missing-.patchDownload+15-1
#4Yugo Nagata
nagata@sraoss.co.jp
In reply to: Yugo Nagata (#3)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Wed, 20 Aug 2025 13:30:12 +0900
Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Wed, 20 Aug 2025 12:49:14 +0900
Fujii Masao <masao.fujii@gmail.com> wrote:

On Wed, Aug 20, 2025 at 10:42 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

Hi,

I found that "vacuumdb --missing-stats-only" always performs ANALYZE
on tables with a virtual generated column, since such columns currently
never have statistics. This seems like an obvious waste, so I've attached
a patch to fix it, ensuring that virtual generated columns are not
regarded as missing statistics.

Thanks for the report and patch! This seems to be an oversight from
the commit that added virtual generated columns.

For the patch, shouldn't we also add a regression test for --missing-stats-only
with generated columns, to prevent this issue from happening again?

Thank you for reviewing the patch and your suggestion.

I agree that we should add a test, since the behavior may change in the future
when statistics begin to be collected for virtual generated columns, and the test
will serve as a reminder when this behavior changes.

I've attached a updated patch including the test.

The patch conflicted with the latest commit, so I rebased it.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

v3-0001-Avoid-treating-virtual-generated-columns-as-missi.patchtext/x-diff; name=v3-0001-Avoid-treating-virtual-generated-columns-as-missi.patchDownload+15-1
#5Nathan Bossart
nathandbossart@gmail.com
In reply to: Yugo Nagata (#4)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Wed, Aug 20, 2025 at 01:53:38PM +0900, Yugo Nagata wrote:

The patch conflicted with the latest commit, so I rebased it.

Nice find. I would suggest adding the virtual generated column to
regression_vacuumdb_test when it is first created so that we can just rely
on the existing test cases. In fact, by doing so, you'll see that we need
a similar change to the "inheritance and regular stats" part of the query.

--
nathan

#6Fujii Masao
masao.fujii@gmail.com
In reply to: Nathan Bossart (#5)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Thu, Aug 21, 2025 at 4:19 AM Nathan Bossart <nathandbossart@gmail.com> wrote:

On Wed, Aug 20, 2025 at 01:53:38PM +0900, Yugo Nagata wrote:

The patch conflicted with the latest commit, so I rebased it.

Nice find. I would suggest adding the virtual generated column to
regression_vacuumdb_test when it is first created so that we can just rely
on the existing test cases. In fact, by doing so, you'll see that we need
a similar change to the "inheritance and regular stats" part of the query.

+1

Regards,

--
Fujii Masao

#7Nathan Bossart
nathandbossart@gmail.com
In reply to: Fujii Masao (#6)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Thu, Aug 21, 2025 at 11:13:44AM +0900, Fujii Masao wrote:

On Thu, Aug 21, 2025 at 4:19 AM Nathan Bossart <nathandbossart@gmail.com> wrote:

Nice find. I would suggest adding the virtual generated column to
regression_vacuumdb_test when it is first created so that we can just rely
on the existing test cases. In fact, by doing so, you'll see that we need
a similar change to the "inheritance and regular stats" part of the query.

+1

Since we're running out of time for v18, I went ahead and updated the
patch. I've also added an open item for this.

--
nathan

Attachments:

v4-0001-vacuumdb-Fix-missing-stats-only-with-virtual-gene.patchtext/plain; charset=us-asciiDownload+9-4
#8Corey Huinker
corey.huinker@gmail.com
In reply to: Nathan Bossart (#7)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Thu, Aug 21, 2025 at 9:56 AM Nathan Bossart <nathandbossart@gmail.com>
wrote:

On Thu, Aug 21, 2025 at 11:13:44AM +0900, Fujii Masao wrote:

On Thu, Aug 21, 2025 at 4:19 AM Nathan Bossart <nathandbossart@gmail.com>

wrote:

Nice find. I would suggest adding the virtual generated column to
regression_vacuumdb_test when it is first created so that we can just

rely

on the existing test cases. In fact, by doing so, you'll see that we

need

a similar change to the "inheritance and regular stats" part of the

query.

+1

Since we're running out of time for v18, I went ahead and updated the
patch. I've also added an open item for this.

+1 on the fix, works for me.

#9Nathan Bossart
nathandbossart@gmail.com
In reply to: Corey Huinker (#8)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Thu, Aug 21, 2025 at 11:29:56AM -0400, Corey Huinker wrote:

On Thu, Aug 21, 2025 at 9:56 AM Nathan Bossart <nathandbossart@gmail.com>
wrote:

Since we're running out of time for v18, I went ahead and updated the
patch. I've also added an open item for this.

+1 on the fix, works for me.

Thanks. I'll plan on committing this in roughly 24 hours (barring
additional feedback).

--
nathan

#10Yugo Nagata
nagata@sraoss.co.jp
In reply to: Nathan Bossart (#9)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Thu, 21 Aug 2025 10:37:10 -0500
Nathan Bossart <nathandbossart@gmail.com> wrote:

On Thu, Aug 21, 2025 at 11:29:56AM -0400, Corey Huinker wrote:

On Thu, Aug 21, 2025 at 9:56 AM Nathan Bossart <nathandbossart@gmail.com>
wrote:

Since we're running out of time for v18, I went ahead and updated the
patch. I've also added an open item for this.

+1 on the fix, works for me.

Thanks. I'll plan on committing this in roughly 24 hours (barring
additional feedback).

Thank you for updating the patch.
I'm fine with your fixes, both in the test and in the additional change
for inheritance tables. I had overlooked the latter one.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

#11Fujii Masao
masao.fujii@gmail.com
In reply to: Yugo Nagata (#10)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Fri, Aug 22, 2025 at 2:23 AM Yugo Nagata <nagata@sraoss.co.jp> wrote:

On Thu, 21 Aug 2025 10:37:10 -0500
Nathan Bossart <nathandbossart@gmail.com> wrote:

On Thu, Aug 21, 2025 at 11:29:56AM -0400, Corey Huinker wrote:

On Thu, Aug 21, 2025 at 9:56 AM Nathan Bossart <nathandbossart@gmail.com>
wrote:

Since we're running out of time for v18, I went ahead and updated the
patch. I've also added an open item for this.

+1 on the fix, works for me.

Thanks. I'll plan on committing this in roughly 24 hours (barring
additional feedback).

Thanks a lot!

Thank you for updating the patch.
I'm fine with your fixes, both in the test and in the additional change
for inheritance tables. I had overlooked the latter one.

The patch looks good to me, too.

At first, I just wondered whether vacuumdb --missing-stats-only would work
on older servers, since the patch adds access to the attgenerated column,
which might not exist there. But that's not an issue, because
--missing-stats-only is supported only on servers version 15 or later,
where attgenerated is available.

Regards,

--
Fujii Masao

#12Nathan Bossart
nathandbossart@gmail.com
In reply to: Fujii Masao (#11)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

On Fri, Aug 22, 2025 at 10:19:32AM +0900, Fujii Masao wrote:

At first, I just wondered whether vacuumdb --missing-stats-only would work
on older servers, since the patch adds access to the attgenerated column,
which might not exist there. But that's not an issue, because
--missing-stats-only is supported only on servers version 15 or later,
where attgenerated is available.

Yeah, this crossed my mind, too, and I reached the same conclusion.

--
nathan

#13Nathan Bossart
nathandbossart@gmail.com
In reply to: Nathan Bossart (#12)
Re: Don't treat virtual generated columns as missing statistics in vacuumdb --missing-stats-only

Committed.

--
nathan