Re: Cases where alter table set type varchar(longer length) still needs table rewrite

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Jeremy Finzel <finzelj(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Cases where alter table set type varchar(longer length) still needs table rewrite
Date: 2020-02-17 18:19:52
Message-ID: 9756.1581963592@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> writes:
> On 2/17/20 7:01 AM, Jeremy Finzel wrote:
>> I'm still not sure why a rebuild of this index would be required,
>> technically speaking. But perhaps in any case the docs should have
>> something to the effect that expression indexes may require rebuild
>> under specific circumstances?

> [ it is already ]

Yeah. In principle, we wouldn't need to rebuild the indexes in this
case, since there's no semantic difference between a value sourced
from a varchar(N) column and a varchar(some-other-N) column. In general,
though, ALTER COLUMN TYPE doesn't know whether that's true; and there
are definitely binary-compatible cases where it *does* matter.
(An example is that coercing integer to OID is allowed without a
table rewrite, but an index rebuild is needed because the sort
order is different.) So right now, any index mentioning the altered
column has to be rebuilt.

Maybe someday we'll figure out how to do better. I'm kind of wondering
whether it wouldn't be safe to assume that changes that only change the
typmod and not the type OID don't require index rebuilds.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeremy Finzel 2020-02-17 18:39:02 Re: Cases where alter table set type varchar(longer length) still needs table rewrite
Previous Message Jeremy Schneider 2020-02-17 18:17:26 Re: PL/pgSQL question about EXCEPTION clause & corrupt records