pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Cases where alter table set type varchar(longer length) still needs table rewrite
Date: Mon, 17 Feb 2020 09:08:03 -0600
Message-ID: <d51cdfcc-2cbb-c23b-0590-434931a85905@gmail.com> (raw)
In-Reply-To: <CAMa1XUgLD7kr55ZmwdgtvY9e26WMv4MA5H7aDfG1_Ar7TRGw6Q@mail.gmail.com>
References: <CAMa1XUiqdpJZHq_bDAsvbEZw=RjtOuH3z1xz-Xd27a6b1Pf9xA@mail.gmail.com>
	<573.1581949272@sss.pgh.pa.us>
	<CAMa1XUgLD7kr55ZmwdgtvY9e26WMv4MA5H7aDfG1_Ar7TRGw6Q@mail.gmail.com>

On 2/17/20 9:01 AM, Jeremy Finzel wrote:
> On Mon, Feb 17, 2020 at 8:21 AM Tom Lane <tgl@sss.pgh.pa.us 
> <mailto:tgl@sss.pgh.pa.us>> wrote:
>
>     Jeremy Finzel <finzelj@gmail.com <mailto:finzelj@gmail.com>> writes:
>     > I have a table foo with 100 million rows, and a column:
>     >    - id character varying(20)
>     > The following command is the one that we expect to execute very
>     quickly (we
>     > are not seeing any locking), but it is instead taking a very long time:
>     >    - ALTER TABLE foo ALTER COLUMN id TYPE varchar(100);
>
>     Hm, the code is supposed to avoid a table rewrite, but I wonder if
>     there's something else that's not being avoided, such as an index
>     rebuild or foreign-key verification.  Could we see the whole table
>     definition, eg from psql \d+ ?
>
>                             regards, tom lane
>
>
> Based on your feedback, I quickly identified that indeed, the following 
> index is causing the re-type to be slow:
>
> "id_idx" btree ("substring"(id::text, 4, 7))
>
> 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?

How much faster would "it" be if you dropped the index, ran ALTER and 
rebuilt the index?  Or is it too late?

-- 
Angular momentum makes the world go 'round.

view thread (7+ messages)  latest in thread

Message-ID: <d51cdfcc-2cbb-c23b-0590-434931a85905@gmail.com>
Permalink:  ../d51cdfcc-2cbb-c23b-0590-434931a85905@gmail.com/
Also on:    postgresql.org/message-id/d51cdfcc-2cbb-c23b-0590-434931a85905@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Cases where alter table set type varchar(longer length) still needs table rewrite
  In-Reply-To: <d51cdfcc-2cbb-c23b-0590-434931a85905@gmail.com>
  References: <CAMa1XUiqdpJZHq_bDAsvbEZw=RjtOuH3z1xz-Xd27a6b1Pf9xA@mail.gmail.com> <573.1581949272@sss.pgh.pa.us> <CAMa1XUgLD7kr55ZmwdgtvY9e26WMv4MA5H7aDfG1_Ar7TRGw6Q@mail.gmail.com> <d51cdfcc-2cbb-c23b-0590-434931a85905@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox