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 1wVIY8-001rVk-2u for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 00:36:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVIY7-009Svl-1a for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jun 2026 00:36:35 +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 1wVIY7-009Svc-0c for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 00:36:35 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wVIY5-000000019dw-1Nec for pgsql-hackers@lists.postgresql.org; Fri, 05 Jun 2026 00:36:34 +0000 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-36b9033d230so753243a91.1 for ; Thu, 04 Jun 2026 17:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780619792; x=1781224592; darn=lists.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=PbHTvWktnhmnS5QVCukhUWtcz01Qe/gjp0tCWy6BZAQ=; b=ItJl13x2TOh1ohGbg5ElSrG7qZ+w4DCz6pbI2waagoNXGAgPGwjs8IHYUlGAcRGO0A TsRO2xdjL7xjnnQ7+CvuQCBigY36iTXeprb0v8CxNInWaGVvN2zEovnPVDGv57FryYIJ z+Akz48a/MBtLCZhSwRkDSvA4ChcMAjqbs6/BC+Ktxhszd8rQ05y6iJIDajO19QNBXnn 3krQhJZ2qGcTY9iZyNbeyn9z1Dkc7oSYipVY8cMFasJ8VjFIaloRMTBpDNBs+1/OK67l boHbig+K++8YIlloqd6HaYcUNKT0hpmtxWUxFjxso17ogHz3fzQmwA7BR0AHuTtou+iD 2RGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780619792; x=1781224592; 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=PbHTvWktnhmnS5QVCukhUWtcz01Qe/gjp0tCWy6BZAQ=; b=eqqy3ZQCclT0NGjmOCba4X0R0dLjCcpCl6Ybql+2G+0Gm2ctOs/a/OMr91DLFBjant 1q+n909N31tmWG/V70qNm6X/rsEFD1zqN0vG8ECAYgo5Ea/J9FRj9KpLDku1peFAQJZH /Dn6UvigMsfmir9wu9sJTcnTRSdCakA5O3kCaEeWsnspxjmWTBuunMEr7yknQ1wNxciA t/YZU7eyXDxKhXP5p4M3ulBzmY/gv9dHZi6UU4ujy4Z7Y03X6iKf6qlYfCjbxF8+rgMf q2P1z2MZJPrkg2N9yr/2JSKarMK95wjf3SMnmI+Vg+97jg988HGCf7aHA5lG3MsrZ0mz kPQQ== X-Gm-Message-State: AOJu0YwWEMqjZWpgtZ+M0At/vjvWMApXoX6bFdrd6rr2RhtHyRgfiQD/ hdHS7idRxKg9E77uU/T6QIaW0gKtVAGq94N33tynStv7ldLOBa3xuHGUlU7ninfA X-Gm-Gg: Acq92OGZ/lesFhWfBlN657fbG3nK7qnvj8sxzovgLvV+4XPH4lxgpStamjr0j/xr/lS KMTzk0BYvX4P4m2zjd93UHxyu32PAtg91wyEDvwdcEJEOAbE+g/BxihFdkU1D5COWHHrebBggaV 1wEdH/EAWluoFj1frbVRnu04z84Ua6C07rHVOK6m4ch6kXPQNVdFbBjP0neWD4tUAT0AcrXmqzG 7dSBZY/zOaJeUtoZt2dUilcILSQoxYlL6oqEnaTHeo1kyW/j36KWw7IhAZYB4zF0i7KhKt2r3s+ nAH4kDkwVg6N4uscNfA3yWSGI1MBgCDWUVl/N7yOpIWvnFWXJIHR91LuOmuefsYEKMQEOgnG86S JgcP311Erfjny37Ng3uRDvdJW7K5df2BXiofeLfyqUUoIsYR6+PLaJSWAGY1eEMvnCeWm15ghlO GyYCYBCELLcPq9QYPKH4TH6uW8uyxBzUmqZ0j4vCrixrg= X-Received: by 2002:a17:90b:51cf:b0:36b:de66:92c3 with SMTP id 98e67ed59e1d1-371323bae8amr277391a91.10.1780619792198; Thu, 04 Jun 2026 17:36:32 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.161]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36f711e52b0sm4702879a91.15.2026.06.04.17.36.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2026 17:36:31 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: Fix bug of CHECK constraint enforceability recursion From: Chao Li In-Reply-To: Date: Fri, 5 Jun 2026 08:35:56 +0800 Cc: pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <684DCC2F-5982-4A5D-93F9-BD640B58B4BB@gmail.com> References: <33E9C4C2-B6A8-4FCC-BEEA-461EA5FB98C8@gmail.com> <7F0EA98A-6DBC-436A-8FF4-4A511A05ABE6@gmail.com> <7B7172F4-DB02-4259-997B-6AEF5ADF7FCE@gmail.com> <14E223D8-8425-446A-A36C-6B62BC334656@gmail.com> <9A3D388C-1DF4-4C43-9AB6-83529A8F48C8@gmail.com> <92CAD935-5ECE-46D8-B7D7-D8E3C991CC10@gmail.com> To: Zsolt Parragi X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 5, 2026, at 03:08, Zsolt Parragi = wrote: >=20 > The new version looks correct, I don't see any logic problem with it, > however, I do have a performance question: >=20 > + /* > + * A parent listed in changing_conids is being changed by the > + * same ALTER, but it may not have been updated yet. For > + * regular inheritance, recurse upward to check whether an > + * equivalent enforced parent outside the ALTER will make it > + * remain enforced. Partitions cannot have multiple parents, > + * so they do not need this check. > + */ > + if (!rel->rd_rel->relispartition && > + list_member_oid(changing_conids, parentcon->oid)) >=20 > Shouldn't the parent lookup use some form of caching? Otherwise we'll > end up reevaluating the same parents multiple times. I'm not sure if > it is needed or not, how much of a performance impact this can have in > a real-world server. Actually, after sending v7, I spent several hours trying to cache update = history, which could avoid some recurse-up lookups. But I was = uncomfortable with the resulting code and gave up on that approach. = There were several reasons: * Re-evaluation only happens in an edge case where all of the following = are true: - the constraint is altered from ENFORCED to NOT ENFORCED - the target is a regular inherited table, partitioned tables do not = go through this logic - the inheritance graph is complex, as in your test case, only tables = like e and f hit the re-evaluation case =20 * It is common for a partitioned table to have thousands of partitions, = but I rarely hear of a regular inherited table having thousands of = descendants. * This re-evaluation only reads catalog tables. Compared with ALTER = TABLE operations that rewrite table data, the cost should not be too = bad. * More importantly, I don=E2=80=99t think caching update results is the = right solution. The root cause is that find_all_inheritors() cannot = ensure that a child appears after all of its parents in the returned = list. We could add an alternative helper that returns inheritance = descendants in topological order. With that, the current recurse-up = logic could be avoided, and maybe the changing_oids list could be = avoided as well. But it is too late for v19. I have added this to my = TODO list and will work on it for v20. In summary, I think the current re-evaluation has very limited = performance impact and is acceptable for v19. We can improve the = algorithm with a better solution in v20. BTW, do you have any comments on the doc changes in 0002 and 0003? Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/