Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j8tC2-0005fF-UV for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Mar 2020 22:05:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j8tC1-0003BD-L5 for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Mar 2020 22:05:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j8tC1-0003B6-8X for pgsql-hackers@lists.postgresql.org; Mon, 02 Mar 2020 22:05:41 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j8tBy-0001Q7-AS for pgsql-hackers@postgresql.org; Mon, 02 Mar 2020 22:05:39 +0000 Received: by mail-wr1-x442.google.com with SMTP id z11so1771916wro.9 for ; Mon, 02 Mar 2020 14:05:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=kEPeVADCIr//3+a8L+5s4QbtFAcdN7hnP/Qh3lfaBeU=; b=0JP5J7QPlm6B78OshX/UI3zHqvaI8lVrYLVfLlQR0pk0DDl8uPE3lHA+MKXrmYd+6w ZZ2ED81abrZ8KSJXKbJ28XldZ4JS9w05QvzuBdYi8meoICoEnyXPNFYvAYnIUZn9OZA6 3jfro9HMDrtFNy7FIoA03Kb8VeuV1/z6hKqrxL90MYvkcAFltev29K4TSuz7sQ6ku+WR RrnFlnSS+VyPdzLWfv9RIqGq2UfWokWwJfvigPBTaqpcP+6eC4YhvCy8zXA9IyDNdRqo nSi8nsb67RaGTyNiufJeonHn5spMLEWF2gzMPb1ecqkAG1mNrlEv7yu5hjczPPoxanBY 3mcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kEPeVADCIr//3+a8L+5s4QbtFAcdN7hnP/Qh3lfaBeU=; b=SatokevMZzY2CmhpgaEfDvre3jFLLyLy8tjpnrjb8piEqVM1WgVSsx7nwLluuctH1S es8fUGmzT0J+xLBCvdnRz7pgXTp3jYY1ge+1Qp5IkvtYITeWIRf1BdPBQsAhbWoNB/h2 Sfeyfdl8DNHyxaJW5HWcegFefqITpdvUYanDw2V5VBA43ujM+sPW2Q7bZFFVZx+KmSs2 4v+91waIsVhaUcJS7UPFxp9VShvqWW2H22WHVcC+oPiNNeBDygFQXi5Bl6ODZdiupAZ0 QVRjtwKfglh7GCCJRAvzwjoxFmnCQ2OpAYKXrGYDGdh18fOJwj6iPbRuSrcxa/0Jo04+ Lwhw== X-Gm-Message-State: ANhLgQ3KdLwjiXLTqay4J607VueJFLUm3FGFkG/KmspOZBuA+i6xmzF7 PMNyAZAJcnLeDS6DVAM17qpxTbvVq8k= X-Google-Smtp-Source: ADFU+vteOWW80JjHutAkJBPQS+0Hl+hYoGdVXLSZ+9CAlQgIpd6EgzZOFJ1cpgjFvf9rnqcWDb3Cvg== X-Received: by 2002:adf:90ee:: with SMTP id i101mr1467582wri.417.1583186735297; Mon, 02 Mar 2020 14:05:35 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id r19sm513168wmh.26.2020.03.02.14.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2020 14:05:33 -0800 (PST) Date: Mon, 2 Mar 2020 23:05:31 +0100 From: Tomas Vondra To: Tom Lane Cc: pgsql-hackers@postgresql.org Subject: Re: Allowing ALTER TYPE to change storage strategy Message-ID: <20200302220531.cdz4rlbw5gmcicsa@development> References: <20200228004440.b23ein4qvmxnlpht@development> <4872.1582916389@sss.pgh.pa.us> <20200229012511.7h23frunvvxwai7q@development> <9226.1582940133@sss.pgh.pa.us> <10968.1583176270@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <10968.1583176270@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Mar 02, 2020 at 02:11:10PM -0500, Tom Lane wrote: >I started to look at this patch with fresh eyes after reading the patch >for adding binary I/O for ltree, > >https://www.postgresql.org/message-id/flat/CANmj9Vxx50jOo1L7iSRxd142NyTz6Bdcgg7u9P3Z8o0=HGkYyQ@mail.gmail.com > >and realizing that the only reasonable way to tackle that problem is to >provide an ALTER TYPE command that can set the binary I/O functions for >an existing type. (One might think that it'd be acceptable to UPDATE >the pg_type row directly; but that wouldn't take care of dependencies >properly, and it also wouldn't handle the domain issues I discuss below.) >There are other properties too that can be set in CREATE TYPE but we >have no convenient way to adjust later, though it'd be reasonable to >want to do so. > >I do not think that we want to invent bespoke syntax for each property. >The more such stuff we cram into ALTER TYPE, the bigger the risk of >conflicting with some future SQL extension. Moreover, since CREATE TYPE >for base types already uses the "( keyword = value, ... )" syntax for >these properties, and we have a similar precedent in CREATE/ALTER >OPERATOR, it seems to me that the syntax we want here is > > ALTER TYPE typename SET ( keyword = value [, ... ] ) > Agreed, it seems reasonable to use the ALTER OPRATOR precedent. >Attached is a stab at doing it that way, and implementing setting of >the binary I/O functions for good measure. (It'd be reasonable to >add more stuff, like setting the other support functions, but this >is enough for the immediate discussion.) > >The main thing I'm not too happy about is what to do about domains. >Your v2 patch supposed that it's okay to allow ALTER TYPE on domains, >but I'm not sure we want to go that way, and if we do there's certainly >a bunch more work that has to be done. Up to now the system has >supposed that domains inherit all these properties from their base >types. I'm not certain exactly how far that assumption has propagated, >but there's at least one place that implicitly assumes it: pg_dump has >no logic for adjusting a domain to have different storage or support >functions than the base type had. So as v2 stands, a custom storage >option on a domain would be lost in dump/reload. > >Another issue that would become a big problem if we allow domains to >have custom I/O functions is that the wire protocol transmits the >base type's OID, not the domain's OID, for an output column that >is of a domain type. A client that expected a particular output >format on the strength of what it was told the column type was >would be in for a big surprise. > >Certainly we could fix pg_dump if we had a mind to, but changing >the wire protocol for this would have unpleasant ramifications. >And I'm worried about whether there are other places in the system >that are also making this sort of assumption. > >I'm also not very convinced that we *want* to allow domains to vary from >their base types in this way. The primary use-case I can think of for >ALTER TYPE SET is in extension update scripts, and an extension would >almost surely wish for any domains over its type to automatically absorb >whatever changes of this sort it wants to make. > >So I think there are two distinct paths we could take here: > >* Decide that it's okay to allow domains to vary from their base type >in these properties. Teach pg_dump to cope with that, and stand ready >to fix any other bugs we find, and have some story to tell the people >whose clients we break. Possibly add a CASCADE option to >ALTER TYPE SET, with the semantics of adjusting dependent domains >to match. (This is slightly less scary than the CASCADE semantics >you had in mind, because it would only affect pg_type entries not >tables.) > >* Decide that we'll continue to require domains to match their base >type in all these properties. That means refusing to allow ALTER >on a domain per se, and automatically cascading these changes to >dependent domains. > >In the v3 patch below, I've ripped out the ALTER DOMAIN syntax on >the assumption that we'd do the latter; but I've not written the >cascade recursion logic, because that seemed like a lot of work >to do in advance of having consensus on it being a good idea. > I do agree we should do the latter, i.e. maintain the assumption that domains have the same properties as their base type. I can't think of a use case for allowing them to differ, it just didn't occur to me there is this implicit assumption when writing the patch. >I've also restricted the code to work just on base types, because >it's far from apparent to me that it makes any sense to allow any >of these operations on derived types such as composites or ranges. >Again, there's a fair amount of code that is not going to be >prepared for such a type to have properties that it could not >have at creation, and I don't see a use-case that really justifies >breaking those expectations. > Yeah, that makes sense too, I think. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services