pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Tim Kane <tim.kane@gmail.com>
To: Ron <ronljohnsonjr@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Alter domain type / avoiding table rewrite
Date: Tue, 16 Apr 2019 10:04:48 -0700
Message-ID: <2f57aafd-f034-0f82-5739-614607e4ba0e@aklaver.com> (raw)
In-Reply-To: <CADVWZZ+E2GUPnj8_JoPkh05d9t31HqBs4SfSVHY8YWPJfKZ=Ug@mail.gmail.com>
References: <CADVWZZKjhV9fLpewPdQMZx7V6kvGJViwMEDrPAv9m50rGeK9UA@mail.gmail.com>
	<26216.1555423922@sss.pgh.pa.us>
	<9dc52f4b-94b5-813c-52ba-be22dec1cb93@aklaver.com>
	<27283.1555425748@sss.pgh.pa.us>
	<c2a2f6f0-9e85-3c43-54d5-b68c592695ed@gmail.com>
	<CADVWZZ+E2GUPnj8_JoPkh05d9t31HqBs4SfSVHY8YWPJfKZ=Ug@mail.gmail.com>

On 4/16/19 9:18 AM, Tim Kane wrote:
> Thanks everyone..
> 
> It seems that the first step:
> 
> old_type --> varchar(9)
> 
> still requires a table rewrite, while the reverse direction does not.

Hmm:

CREATE DOMAIN old_type AS varchar(9);

create table rewrite_test (id integer, fld_1 old_type);

insert into rewrite_test values (1, '123456789'), (2, '123');

select ctid from rewrite_test;
  ctid
-------
  (0,1)
  (0,2)

alter table rewrite_test alter COLUMN fld_1 set data type varchar(9);

select ctid from rewrite_test;
  ctid
-------
  (0,1)
  (0,2)

update rewrite_test set fld_1 = '1' where id =2;

select ctid from rewrite_test; 
 

  ctid 
 
 

------- 
 
 

  (0,1) 
 
 

  (0,3)

Where are you seeing the rewrite in your case?

> 
> 
> I'm curious about the performance implication of domain types, i expect 
> that cost is only at insert/update time? I guess we've been wearing that 
> cost up until now.
> 
> Adrian is correct - the intention for the DOMAIN with CHECK approach was 
> to allow flexibility moving forward, as the data set is particularly 
> large...
> 
> I'm now thinking that since promotion to a larger size is a non-issue, 
> and domain type seems to be not quite the panacea I hoped, then the use 
> of varchar(n) is perhaps not so terrible!
> 
> Thanks for the advice/suggestions/discussion :)
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (16+ messages)  latest in thread

Message-ID: <2f57aafd-f034-0f82-5739-614607e4ba0e@aklaver.com>
Permalink:  ../2f57aafd-f034-0f82-5739-614607e4ba0e@aklaver.com/
Also on:    postgresql.org/message-id/2f57aafd-f034-0f82-5739-614607e4ba0e@aklaver.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: adrian.klaver@aklaver.com, tim.kane@gmail.com, ronljohnsonjr@gmail.com
  Subject: Re: Alter domain type / avoiding table rewrite
  In-Reply-To: <2f57aafd-f034-0f82-5739-614607e4ba0e@aklaver.com>
  References: <CADVWZZKjhV9fLpewPdQMZx7V6kvGJViwMEDrPAv9m50rGeK9UA@mail.gmail.com> <26216.1555423922@sss.pgh.pa.us> <9dc52f4b-94b5-813c-52ba-be22dec1cb93@aklaver.com> <27283.1555425748@sss.pgh.pa.us> <c2a2f6f0-9e85-3c43-54d5-b68c592695ed@gmail.com> <CADVWZZ+E2GUPnj8_JoPkh05d9t31HqBs4SfSVHY8YWPJfKZ=Ug@mail.gmail.com> <2f57aafd-f034-0f82-5739-614607e4ba0e@aklaver.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