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 1x3mnb-006fRy-2v for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 03:47:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x3mna-003wBK-2s for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 03:47:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3mna-003wBB-20 for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2026 03:47:06 +0000 Received: from mail-pj2-x10.google.com ([2607:f8b0:4864:39::10]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x3mnY-00000004Wuy-2ZcO for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2026 03:47:05 +0000 Received: by mail-pj2-x10.google.com with SMTP id d9443c01a7336-2d747eefae4so1751445ad.0 for ; Mon, 07 Sep 2026 20:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788839223; x=1789444023; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=6YhdC7Cn8tScmzm2Z1+ncvO1heQwWsPJnGKK+aTeN6s=; b=gohMG+Dq5/r3HrHW8XXZag9VuoeE8YkIBdtUdrNTJqIR/WMW27L2bPMdIgVtAe5FHI prHKcu1NxALyjwFPGgEIpj+kJ1eLIcQonr9E6u1PiWlr8JAgFER82IQA444RYKGxmOkT b+BsbsUgPF76Z9VQ0E7ZK0Ts2/z2aVovoSS6wuAaasOq2IMVddzjJ2yhMSMnooNjsE8A OxcNL5V6KNKcN6HXIMxRxe8mEjcmT3FJ+xmVB197gUBIgTSuaSzTNQSfIK6TTvpz+wjW Xsz62X32bxvbsLMyrZAkt7TThV2Tk2C0mNTsTwEYCP/ETVApDEjCe9ntknNAtaFjj2Qd vNuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788839223; x=1789444023; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6YhdC7Cn8tScmzm2Z1+ncvO1heQwWsPJnGKK+aTeN6s=; b=f6e58wfQSoTdg9ITOE2e4B8ck/7OMyVQGgOwXMQpjAPsplh0k4ezAU6G5biojVqcKm Rs9tYr37owx83kq0qgRRaz0Pm4oD6LwzdNUoGdtmR3lRdOqVSLf1IY4SBuJK4svnG2l5 O6bYD0P2BmH0CFxu/kDXDsxDp/ucsuTxoB1R3NDC7IOf9pC2BLhcbkOlfeCW8y+5TGok L6JXFH4SGxX+ptGtEFTi/j6bsTA/mIZLzjRRZpyKS+rLslyouFTW7blDEeYM8HEd+01N 5FXI62rZj+BhO1CQuNQ3DFWrsDX5e4mPUtnEgWOaRL8UyMlTQfaambD25NEdAslhhoXL vLqQ== X-Gm-Message-State: AFuF++lSVbImxnfthYyI4F0DdGzV2vlVD576oMhrO6P9GiI6NggWyncE 2/nwaa5zCNoXhEVMR4dX/pGY7OYxxjz0dFz9S7j0CA7Eji2ypvBOWibm X-Gm-Gg: AYBFou0+t3Cv6vVCgzN/sTLybarE2xgYJlCKnDZ1ImGeoSBZgzygFPyvBLIjR4mdQod Ju8Mk05zZTh1mvkRybzqvrgZk5ecC0J2NcO4NOFTYdfThkyBRwnPF+6u0mDs1jkYQ/QgsbDsoDC BTpJ+h2MvYge2n+BPmZ13s/rsuNU3BDkAIABfUjNZcDN0UHHyyw4w9WhPH4T2BCJdXlXM7xsl22 ZsKTdlopt2/ifi6zOCxa2iVNczPdcUt+g4t2bps6jy269gb8dBBUIETpCIeVpTfpUU9TVhSES0v bf85ghnU3qgKVh1PBsz7hoa9Sppc8Ie4YTMq1zKV91fbDaggF1h8cKGuFaHL6o6KRDv9ot3CrfE aZvu3ePuwXb+Cm2krtpZFnZPUO1oneBgDIFoMpMeHRu5fka0ck9oPbHmzAjlRCEbqvxfCFY7QL4 pRgiHOv06dt2/AlYm0Bs1Q256SzYALhxZyUk4QVCBBPifYHMAD25w9XAIcuiZGbpu6R64EgceIN A== X-Received: by 2002:a17:903:2ec5:b0:2c9:d277:2cdb with SMTP id d9443c01a7336-2db701df8f1mr42769695ad.9.1788839223144; Mon, 07 Sep 2026 20:47:03 -0700 (PDT) Received: from smtpclient.apple ([2401:c080:1400:7d37:3eec:efff:feb9:f624]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2db14959954sm51405285ad.27.2026.09.07.20.46.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2026 20:47:02 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: Introducing find_all_inheritors_ordered() From: Chao Li In-Reply-To: Date: Tue, 8 Sep 2026 11:46:26 +0800 Cc: pgsql-hackers@lists.postgresql.org, Ewan Young Content-Transfer-Encoding: quoted-printable Message-Id: <478CC29D-1E62-4804-9FF0-C8E25E604FEE@gmail.com> References: <57100518-3FF1-48AD-B550-47B9A3E88688@gmail.com> <20EAC3F9-81A2-41DD-89FA-1539EA8ED11B@gmail.com> To: Zsolt Parragi X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Sep 8, 2026, at 06:16, Zsolt Parragi = wrote: >=20 > On Mon, 07 Sep 2026, Chao Li wrote: >> My understanding is that PG doesn=E2=80=99t intend to support cyclic = inheritance. The code explicitly rejects it: >=20 > To me it seems like that it discourages it and tries to prevent it > where it's possible to do so with reasonable effort, but it ends up > trying to support it because it's a valid scenario that can happen in > some workloads (as long as that also doesn't require too much effort). I think an important problem is that, in your earlier example, two users = independently execute ALTER TABLE =E2=80=A6 INHERIT, but the commands = together create an inheritance cycle without either user being notified. = Even if PG currently tolerates this, I think preventing it would be = preferable. As Tom pointed out, cycles can also cause problems elsewhere in the = system. So I agree that we should investigate whether we can prevent = their creation at a reasonable cost. >=20 >> A cycle can cause it to exceed the stack depth limit, so it is = reasonable to fail the command when a cycle is detected. >=20 > Or it might succeed in other cases. >=20 > Here's a repro with an isolation test. Perm 1 fails on master, works > with the patch. Perm 2 works on master, fails with the patch. > We could improve this by only using the new function in the enforced > direction, I don't have a better idea currently. With that, the > patched behavior would be the same as on master. >=20 This is a valid point. ENFORCED doesn=E2=80=99t need to check parents=E2=80= =99 enforceability, so we can still use find_all_inheritors() to = tolerate potential cycles and use find_all_inheritors_ordered() only for = NOT ENFORCED. This preserves master=E2=80=99s success/failure outcomes = in your test, while replacing the stack-depth error with an explicit = cycle error. I have updated the code in v3. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/