Re: support create index on virtual generated column. - Mailing list pgsql-hackers

From Corey Huinker
Subject Re: support create index on virtual generated column.
Date
Msg-id CADkLM=c09mZi_XFix5EyHXPz1Z0k7=-DBV+iAOicCrDiqCqFrw@mail.gmail.com
Whole thread Raw
In response to Re: support create index on virtual generated column.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers

On Tue, Jul 22, 2025 at 4:54 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Corey Huinker <corey.huinker@gmail.com> writes:
> I'm interested in this feature, specifically whether the optimizer uses the
> index in situations where the expression is used rather than the virtual
> column name.

Hmm, I kinda think we should not do this.  The entire point of a
virtual column is that its values are not stored and so you can
(for example) change the generation expression "for free".
If it's referenced in an index that advantage goes out the window
because we'll have to rebuild the index.

Don't we already have dependencies on altering a column if it's indexed? Wouldn't that be all the barrier we'd need?
 

Besides, this does nothing you haven't been able to do for
decades with expression indexes.

What I'm hoping for with this feature is a smoother transition when people start introducing virtual columns. If there was already an index on that expression, and some queries start using the new virtual column (with the same expression), will that cause those queries to miss the index we already have? If it doesn't, then a customer can roll out the query changes at will and not need to do some cut-over from using the expression to using the virtual column.
 

pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: vacuumdb changes for stats import/export
Next
From: Andrew Dunstan
Date:
Subject: Re: Non-text mode for pg_dumpall