Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wFkgi-005VXg-1t for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2026 03:25:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wFkgh-00GbKg-1Y for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2026 03:25:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wFkgh-00GbKX-0b for pgsql-hackers@lists.postgresql.org; Thu, 23 Apr 2026 03:25:11 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wFkgf-00000002Zvy-09MM for pgsql-hackers@postgresql.org; Thu, 23 Apr 2026 03:25:10 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2ad21f437eeso40370805ad.0 for ; Wed, 22 Apr 2026 20:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776914706; x=1777519506; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TO5umsajGBv0VcUxjn3kV0t+RGwl/IImsgSd1AhRmw0=; b=syVbtuLg6VfiH7SD27euuDksslJ51WbytB31jlsra2m1zqWXowy+RwmMjD95Jn8hKx apHkNssEYeGLRBzQtLSNm4eaA901QnUjT+Jp0lb/kz7I5LswUlfUZne+mjFLqtoVcQ13 mo8IAnYL1ss/wLYZg4T90WhhF8FFcOcYrUo+ulcQsR671gb0UHtjT/XRXv1xkDTstca+ mad74gzcUB3vnypnb02mcnYdG043AAthW3V4EaIvN0uz2cn4HrFNvbLgBXIc8RUqEYI4 5FuHoMzhvxMPaKxGnGCS6qMO2jNtax6P0I69NYpISghzZgxeXKsXwq4OcSoDv2OBjdfy z7rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776914706; x=1777519506; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TO5umsajGBv0VcUxjn3kV0t+RGwl/IImsgSd1AhRmw0=; b=L+Kr+VSyM/Fky2MLakjv/U1bazTiLfEAOw8EIGusS3tidxcSxiuBj0VvUyE8qI2jCw lQmZpJPGYlk1ZpjmMPyHh7TkOuDtZomYGzAF3JYrN3kXhtghnpegTOUEfadImWwmuerG B3QrhfHkSzY4MCTqTr/ERnPc/LpUsPqk/s52gVw1iFYacZupDnONpzyHAp5J1NVDxhWi WX4e0WelJeImoy4kZp/Q6B/D/YfNbb/VJQ1YTHi8YNiY3dsmboWkDPOtSKjBPwP2xMxA X2Fq3kjlkDZKw3BkrvUOa6TSMbK2JBIvIh72xWvcyIBb1CnXSNuNSRV6ywN6ncU7kHdY SJbQ== X-Gm-Message-State: AOJu0YyY/Lah/60ENKmDAPqFbxJSKbrpD4aRcER/N7SysZg2hFCat6Tc bOSCHzOPRmweGIL8ckM+gg45KCnjWva9frZT27pddgH98Kh/5+7DI54w X-Gm-Gg: AeBDievxpAZ5SoyhWI3skHabYifQMjsvVNGlg+ZRDP0XTtzh8nwZCDrwlfLyqc/1ZRY fjCx2rucpztY1Q1raK/daHFZqSkbiDLMke0IHDRROLGQl7AVw6S9Pwl1DwKD/1WOvMHbxXcVXTi qdB9sR1PpIGcynkUZOf3WjI1pL5/HKK9jmxYxFYYB5crS91SCQazYohh/sdJYVaW5bSw9wqYjtT pN8yoAN9n5IvHIwRkrqTI+TqK5xtVqTCMA9gzcdRK0du293Ue/ZW5amTFH1JKYdAWfSKiE5wFJm Nw9SWJvmmmllqTapZB3BbAAM8nzisDantah34IEfTwx6nVOFEVBzsbCLwVHCXdUiO851Q9XUBYC cveXKgKJZEN3G+6V3Uyf03auwH+LfifJLOmqQZN8gStiJJK3MRXArX5nzvaIsMnNaOhzLgRSXbj ikjdHUO41lgrHmNj5MoBJLJQNKydXekmqMBip15G2BjA== X-Received: by 2002:a17:903:1ae7:b0:2b4:5e85:efc with SMTP id d9443c01a7336-2b5f9ea55b6mr216082175ad.18.1776914706069; Wed, 22 Apr 2026 20:25:06 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b7a9efd0f2sm3323335ad.31.2026.04.22.20.25.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2026 20:25:05 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: CheckAttributeType() forgot to recurse into multiranges From: Chao Li In-Reply-To: <93ce56cd-02a6-4db1-8224-c8999372facc@iki.fi> Date: Thu, 23 Apr 2026 11:24:26 +0800 Cc: "pgsql-hackers@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <0B5FC478-013D-45D1-876A-AD3FE0C21E7C@gmail.com> References: <93ce56cd-02a6-4db1-8224-c8999372facc@iki.fi> To: Heikki Linnakangas X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Apr 23, 2026, at 04:56, Heikki Linnakangas wrote: >=20 > Happened to spot this little bug: >=20 > create type two_ints as (a int, b int); > create type two_ints_range as range (subtype =3D two_ints); >=20 > -- CheckAttributeType() forbids this: > alter type two_ints add attribute c two_ints_range; > ERROR: composite type two_ints cannot be made a member of itself >=20 > -- But the same with a multirange is allowed: > alter type two_ints add attribute c two_ints_multirange; > ALTER TYPE >=20 > That looks like a straightforward oversight in CheckAttributeType(). = When multiranges were introduced, it didn't get the memo. >=20 > Fix attached. Assuming no objections, I'll commit and backpatch that. >=20 > While working on the fix, I noticed that in case of dropped columns, = CheckAttributeType() is called with InvalidOid. It tolerates that, but = it seems accidental and it performs a bunch of futile syscache lookups = with InvalidOid, so it would be better to not do that. The second patch = fixes that. >=20 > - Heikki > = <0001-Don-t-allow-composite-type-to-be-member-of-itself-vi.patch><0002-Don= -t-call-CheckAttributeType-with-InvalidOid-on-dro.patch> I traced this patch set, 0002 looks good, but I have a suspicion about = 0001. ``` + else if (att_typtype =3D=3D TYPTYPE_MULTIRANGE) + { + /* + * If it's a multirange, recurse to check its plain = range type. + */ + CheckAttributeType(attname, = get_multirange_range(atttypid), + = get_range_collation(atttypid), + containing_rowtypes, + flags); + } ``` Looking at get_range_collation(), it only searches for RANGETYPE, so = get_range_collation(atttypid) here will always return InvalidOid. This = does not seem to cause a problem, because CheckAttributeType() will = recurse into the TYPTYPE_RANGE path, and the collation will be evaluated = there. But to make the logic clearer, I think we could just pass InvalidOid as = the collation OID in the TYPTYPE_MULTIRANGE case. If we really want to = pass the actual collation OID here, I think it would need to be done = more like this: ``` else if (att_typtype =3D=3D TYPTYPE_MULTIRANGE) { Oid multirange_range_typid =3D = get_multirange_range(atttypid); Oid collation =3D = get_range_collation(multirange_range_typid); /* * If it's a multirange, recurse to check its plain = range type. */ CheckAttributeType(attname, multirange_range_typid, collation, containing_rowtypes, flags); } ``` Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/