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 1mpByg-0008DJ-15 for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Nov 2021 16:15:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mpByf-0001Q7-1f for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Nov 2021 16:15:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mpBye-0001Px-Op for pgsql-bugs@lists.postgresql.org; Mon, 22 Nov 2021 16:15:32 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mpByc-0001tY-71 for pgsql-bugs@lists.postgresql.org; Mon, 22 Nov 2021 16:15:31 +0000 Received: by mail-wr1-x432.google.com with SMTP id u18so33739113wrg.5 for ; Mon, 22 Nov 2021 08:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; h=from:to:cc:subject:date:message-id:organization:in-reply-to :references:mime-version:content-transfer-encoding; bh=WrewKSss0yTPx41F3YNjawkSeVR55Cn8p/W+1noq/S0=; b=YkyEzZp76BhdbeXq5nj47EwiVX5Btwmuc9EU5p2UtaIlhnjP+jLAC6P+dN60UXa077 32Ub50EGlZWG1cSfayXiIsDWEJDMeQdExAjCQ5OOBIKCUmn9iYHFv6DE1WkD3QiZJsTp /m4TBfDVLnWAoZcnSj01fk+dcnWj2/LPAF7qI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :in-reply-to:references:mime-version:content-transfer-encoding; bh=WrewKSss0yTPx41F3YNjawkSeVR55Cn8p/W+1noq/S0=; b=pVJMvDJgy9Gm5xbXeMW9uVZaB4+vvg1Mg1rgUbPKZeFwFt35+l8QnFvDLAj5jrgPed ZQjR0oBwtiFZPmrAgt5VI5wVj0auvrONX6OmMyE6o1YQjgru+KyemLKL/gkNEV8AVJhg FkmfkpVw3LzcDpO7Xbf3nRxZGHNQ9FXIzBufmSnAPkyrZqQTYAd/D8KUzLszyB58GWln cja0Cf8kPnLA/fBi2Xm5pzEtm3mkjswCF0QueYsSFuS2PyJyE4GYRQysCn+wZsxyeRKU zWKKVQ1zu8Zggg7LvX4SgwuEHTe3j7b3xm39GcoqgE3TPl7i0e5AVDcZk+vURM8cFN55 ELOw== X-Gm-Message-State: AOAM533GP4s9JbWcuXCIrnbvzo6LXjuyoTJm+2QlMmtnmIx5t0ZxFri4 EPT7cn39TY4sZAgCYa64Sp+Y3Une5fw74A== X-Google-Smtp-Source: ABdhPJyN1krOh+SUz7HTaBDwZQxfgTNLeDZf6J0n3+ZpzRlleFyVJycDG4m/MOIYzrV33eo8L5y3Ig== X-Received: by 2002:a5d:4cd1:: with SMTP id c17mr39379955wrt.31.1637597728553; Mon, 22 Nov 2021 08:15:28 -0800 (PST) Received: from aivenronan.localnet (static-176-158-121-96.ftth.abo.bbox.fr. [176.158.121.96]) by smtp.gmail.com with ESMTPSA id t8sm11092467wmq.32.2021.11.22.08.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 08:15:26 -0800 (PST) From: Ronan Dunklau To: pgsql-bugs@lists.postgresql.org Cc: Miles Delahunty Subject: Re: table unreadable after altering related table embedded via a view Date: Mon, 22 Nov 2021 17:14:27 +0100 Message-ID: <7355541.EvYhyI6sBW@aivenronan> Organization: aiven In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Le lundi 22 novembre 2021, 03:44:37 CET Miles Delahunty a =E9crit : > $ ./record_type_not_registered.sh > + createdb mytest > + psql mytest > CREATE TABLE > CREATE VIEW > CREATE TABLE > ALTER TABLE > UPDATE 0 > UPDATE 0 > ALTER TABLE > ALTER TABLE > INSERT 0 1 > INSERT 0 1 > ts | what > ----------------------------+-------------- > 2021-11-22 13:29:46.775704 | ("(123456)") > (1 row >=20 > + psql mytest > ERROR: record type has not been registered >=20 I started to take a look at this, and while I haven't gotten to the bottom = of=20 it yet, here are my observations.=20 What I notice is that every field of the view type inserted before the chan= ge=20 is correctly typed as a composite, with type =3D foo_view, and it's content= is a=20 composite, with type =3D foo. But after the change, a newly inserted tuple in foo_log is still correctly= =20 identified as a composite of type foo_view, but it's content is now typed a= s=20 anonymous record (datum_typeid=3D2249, c9080000 on disk). Here is the slightly changed test case showing the difference in the stored= =20 datum_typeid stored before and after the base table change: create extension pageinspect; CREATE EXTENSION =2D-- foo is the main table create table foo (data int); CREATE TABLE create view foo_view as select foo from foo; CREATE VIEW create table foo_log (id serial, what foo_view); CREATE TABLE insert into foo values (1); INSERT 0 1 insert into foo_log (what) select foo_view from foo_view; INSERT 0 1 =2D- Now check the oids of various types. SELECT typname, oid FROM pg_type WHERE typname in ('record', 'foo'); typname | oid =20 =2D--------+-------- record | 2249 foo | 154218 (2 rows) =2D- Check what is the type stored for the composited type of what.foo =2D- It is the encoded representation of the oid of foo. select v from (select (encode(substr(t_data, 31, 4), 'hex')) as v from=20 heap_page_items(get_raw_page('foo_log', 0))) t; v =20 =2D--------- 6a5a0200 (1 row) alter table foo add column big_data bigint; ALTER TABLE update foo set big_data =3D data; UPDATE 1 update foo_log set what.foo.big_data =3D (what).foo.data; UPDATE 1 alter table foo drop column data; ALTER TABLE alter table foo rename column big_data to data; ALTER TABLE insert into foo values (2); INSERT 0 1 insert into foo_log (what) select foo_view from foo_view where (foo).data = =3D 2; INSERT 0 1 =2D- Now perform the same check =2D- The first tuple, and it's updated versions both have the correct value= s for =2D- the type of what.foo, but the newly inserted one has 'c9080000' which = is=20 the =2D- oid for record. select v from (select (encode(substr(t_data, 31, 4), 'hex')) as v from=20 heap_page_items(get_raw_page('foo_log', 0))) t; v =20 =2D--------- 6a5a0200 6a5a0200 c9080000 (3 rows) + psql -a mytest \set verbosity verbose =2D- This one is ok select * from foo_log where id =3D 1; id | what =20 =2D---+--------- 1 | ("(1)") (1 row) =2D- This one is unreadable select * from foo_log where id =3D 2; ERROR: record type has not been registered =2D-=20 Ronan Dunklau