Re: Allow to collect statistics on virtual generated columns

From: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
To: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allow to collect statistics on virtual generated columns
Date: 2026-03-26 15:09:31
Message-ID: 20260327000931.d2303c198c7c9445e90aeab7@sraoss.co.jp
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 25 Mar 2026 13:01:27 +0900
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:

> On Tue, 24 Mar 2026 11:43:47 +0000
> Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>
> > On Tue, 24 Mar 2026 at 10:57, Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> wrote:
> > >
> > > One concern is that CREATE STATISTICS does not allow creating extended
> > > statistics on a single colmun. If we try this, it raises the following error:
> > >
> > > ERROR: extended statistics require at least 2 columns
> > >
> > > Therefore, if we take this approach, we would need to add an exception
> > > to this rule for virtual columns.
> >
> > I think that would be fine. It makes sense because a virtual column
> > expands to an expression, and we already allow CREATE STATISTICS on a
> > single expression.
>
> I've attached a patch updated along these lines.
>
> This allows users to define extended statistics on virtual generated
> columns. Expressions including such columns are stored in the catalog
> as-is, and expanded at ANALYZE time. Extended statistics on a single
> virtual generated column are also allowed, since it is treated as a
> single expression.
>
> To enable the optimizer to make use of these statistics, expressions
> are also expanded at planning time.
>
> Additional documentation and tests are needed, but are not yet included.
>
> Is this approach better then the previous one?

I've attached an updated patch including the documentation and tests.

Regards,
Yugo Nagata

--
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>

Attachment Content-Type Size
v7-0001-Allow-creating-extended-statistics-on-virtual-gen.patch text/x-diff 17.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Borisov 2026-03-26 15:13:36 Re: Improve the performance of Unicode Normalization Forms.
Previous Message Melanie Plageman 2026-03-26 14:51:25 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)