Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZRs0-0005QU-Di for pgsql-bugs@arkaria.postgresql.org; Fri, 15 May 2020 04:22:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZRrz-0008M8-8Z for pgsql-bugs@arkaria.postgresql.org; Fri, 15 May 2020 04:22:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZRrz-0008KI-2D for pgsql-bugs@lists.postgresql.org; Fri, 15 May 2020 04:22:47 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jZRrx-00079U-2p for pgsql-bugs@postgresql.org; Fri, 15 May 2020 04:22:46 +0000 Received: by mail-pf1-x444.google.com with SMTP id y18so379129pfl.9 for ; Thu, 14 May 2020 21:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=sqahbMQttCueFtozGbjrnfjlrM1WaAPytqH/FPwcOUU=; b=VPL5TP/w6INSa9ojzVIgOj9YFPZJnpH4jkQkeKz1gUoRvn+N5IkuChP6SxKzs+ZbZI sY2e1ME4BkuyIUo4Cnkl4nKvFZxPnf3kPc0m6Vxn4Va+AadUflH1wVl2c0MhdYGxEAR2 QCxknPcN7Rz6Mu0Fixd/GAiHxHknIPvgE2+tJWp3fhLeQAxdtf/A4uSvlmUQcTYDLlio azdZM5XHfY8xPGhVfpb8asoRm+POOQuIG9lA+PTSfm4RyEEHVmTjnb48iHCp22CrmaF1 /A0mPdK9RMMhdprw8fEwLeWds8ki+Cab1OCnB/a5i4Lso49K6rg6sBJeJgaojuL7P/kD AcgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=sqahbMQttCueFtozGbjrnfjlrM1WaAPytqH/FPwcOUU=; b=dGgHPwJm3zzIBlQbGeN1x9+RL9zz5zEE5UTUUxqNNmR6NO2JiB4ZRxnuOU8p0YCW3F 4V2CSiiMyd/PSvm+qjAvG7n98MosP4b9nxu5YXo9pepicbBYX9WGyYfao94x12AXNt/p ki+kVXxU3SDD7au1NoR02N51xuD/OXRNS3uDLStdhVml/yncNlo4EARrGE64hliyJQEx EqDr8leU+VEdQ+hcf5J0xPeVWpk10EV/2jI14mPy2nwZ+KBq6u5foKu/Smx8wIr9WDml HZu5Q8VIaC5j0H9FBRizUm5HOzwLkhP4ZCse4wahAQZ0aj2DiHljPtG7oFxVaQHTNIA6 8P3Q== X-Gm-Message-State: AOAM5320RWM6KlrwC9nfcPyt0XOLQ4m6wBE9PNWsYR6e302SayA3ZC5/ 9ZTbV4KLu3LH9OXwxXYrIE0= X-Google-Smtp-Source: ABdhPJzQfSx7ozlDaMcig6YNU8EU8pZ+XV7YgrBT4l8BGRaCDgUoc+7Uo9dmuwb5oOrl8nD4EVzOZA== X-Received: by 2002:aa7:9832:: with SMTP id q18mr1965150pfl.179.1589516563062; Thu, 14 May 2020 21:22:43 -0700 (PDT) Received: from localhost (ag027197.dynamic.ppp.asahi-net.or.jp. [157.107.27.197]) by smtp.gmail.com with ESMTPSA id cp22sm438004pjb.28.2020.05.14.21.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 21:22:42 -0700 (PDT) Date: Fri, 15 May 2020 13:22:40 +0900 (JST) Message-Id: <20200515.132240.592308932233735849.horikyota.ntt@gmail.com> To: amitlangote09@gmail.com Cc: hlinnaka@iki.fi, pgsql-bugs@postgresql.org Subject: Re: Multi-parent inherited table with mixed storage options cannot be restored From: Kyotaro Horiguchi In-Reply-To: References: User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk At Fri, 15 May 2020 11:54:09 +0900, Amit Langote wrote in > On Thu, May 14, 2020 at 7:31 PM Heikki Linnakangas wrote: > > > > CREATE TABLE parent1 ( > > col text > > ); > > > > CREATE TABLE parent2 ( > > col text > > ); > > > > CREATE TABLE child () INHERITS (parent1, parent2); > > > > ALTER TABLE ONLY parent1 ALTER COLUMN col SET STORAGE EXTERNAL; > > ALTER TABLE ONLY parent2 ALTER COLUMN col SET STORAGE MAIN; > > > > > > pg_dump dumps those commands in different order (dump attached), with > > the SET STORAGE commands before creating the child table. But that's not > > allowed: > > > > psql:mixed-storage-inheritance.sql:53: ERROR: inherited column "col" > > has a storage parameter conflict > > DETAIL: EXTERNAL versus MAIN > > > > That's not good. > > > > What's the best way to fix it? Perhaps pg_dump should leave out the > > INHERITS clause from the CREATE TABLE statement, and dump separate > > "ALTER TABLE child INHERIT" commands to make it inherited? But then > > 'attislocal' is wrongly to false for the columns. Or perhaps relax the > > check for mixed storage options, so that the CREATE TABLE won't throw > > that error. > > Btw, inheriting from the parents using ALTER TABLE doesn't raise the error: I think there's no problem if a table in an inheritance tree has different storage type from others. It seems to me that the reason for the CREATE TABLE's behavior is that there's no reasonable criteria of from which parent the new child table ought to inherit a characteristic. I thought that just building inheritance tree without setting such characteristics, then later setting such characteristics for all participants of the tree would work but it seems too invasive. > CREATE TABLE public.parent1 (col text); > ALTER TABLE ONLY public.parent1 ALTER COLUMN col SET STORAGE MAIN; > > CREATE TABLE public.parent2 (col text); > ALTER TABLE ONLY public.parent2 ALTER COLUMN col SET STORAGE MAIN; > > CREATE TABLE public.child (col text); > > ALTER TABLE public.child INHERIT public.parent1; > ALTER TABLE public.child INHERIT public.parent2; > > It seems that MergeAttributes() (used by CREATE TABLE INHERITS) and > MergeAttributesIntoExisting() (used by ALTER TABLE INHERIT) disagree > as to what the rule regarding attstorage is: > > MergeAttributes() has: > > /* Copy storage parameter */ > if (def->storage == 0) > def->storage = attribute->attstorage; > else if (def->storage != attribute->attstorage) > ereport(ERROR, > (errcode(ERRCODE_DATATYPE_MISMATCH), > errmsg("inherited column \"%s\" has a > storage parameter conflict", > attributeName), > errdetail("%s versus %s", > storage_name(def->storage), > storage_name(attribute->attstorage)))) > > MergeAttributesInfoExisting() has nothing. > > But instead of fixing the latter to enforce the same rule, I'd say we > should relax the check in the former. > > If someone wants to say that we should enforce that all the tables > involved in an inheritance relationship have the same attstorage, then > maybe we have more work to do than simply fixing > MergeAttributesIntoExisting(). We will also have to fix > ATExecSetStorage() to check if the table it's operating on is part of > some inheritance tree and prevent attstorage from being changed if it > is, because that table's attstorage will become out of step with its > inheritance peers. I'd say that's overkill though, so prefer the > other solution. regards. -- Kyotaro Horiguchi NTT Open Source Software Center