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.94.2) (envelope-from ) id 1t8qvf-006KjV-1u for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 01:03:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t8qvb-00AXJe-Tr for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 01:03:16 +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.94.2) (envelope-from ) id 1t8qvb-00AXFk-EH for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 01:03:16 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t8qvX-000b25-SB for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 01:03:15 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2e2ad9825a7so332494a91.0 for ; Wed, 06 Nov 2024 17:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20230601.gappssmtp.com; s=20230601; t=1730941391; x=1731546191; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=K+OgVxrl8bObOFDwir6N4Kpmsa3TWwLsylnJ6k0Qm+o=; b=zV0dyo2i6fZoCd3CeaO1STj+0C7fFKUGTWFoVyyMHpr2SopVwQWa3jawomztNeyQ+k +Jg9VIKFPBsh4ikYiYd20soLkbYxLeKc5O9lZ8dLZH9hSNjq5pkM/f+woRxhtfzfTn77 xyt2S4H8nFmWuHfvnHSAAv5XPUkZblo6jKIiASQk3B3Zrnp0H3Zd8Utp9rPV3ZPBWiwV sSt7Q4QiP7HmZw6IKXiltpt49+JLyPAffMd3zYF9nwnLPnZEjlnXoYdbULLj+94jyPAM p2KE/0UOlJWlgftyfG9Eqiw3nIdL7Sob/D7u0uvga3RgXJ2/T+x3Tm8XhM/6TLGNNVm0 QN2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730941391; x=1731546191; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K+OgVxrl8bObOFDwir6N4Kpmsa3TWwLsylnJ6k0Qm+o=; b=T5ksCGvMhTLmOJIZ72dCT2wYE/CDqacfhBnfOJS2EKp2LuuPdQGCmQQq7+rorkMPYT khFXdZ58qQnrxNcqAUZVQysOV+4sdiZD85Fv8I0/coyklA9uiJp6BQdTwbAqh8Gr0jif aMZ1vt0zCiB51QHvStxF49ffqQqpdk2YruZK876jvXEyC5UnKsU7qCi+tIw4HXGsP39R Qp9Rt+HqXwLfhtK9A4ZFGcjfNLjIYKJsB4fEF+Wj06W0WBPvPKFRsZMU5puFPsmoUQhn rvTIqSjguAZfx7Qn2UXiROrwmlt4qHvVuAkF1PcbPSZDzhH0/lCQ00d3QYFmUNNlab0p D44A== X-Forwarded-Encrypted: i=1; AJvYcCV0achcHb9zsau7yIY2MyAdeZFF8NFaYdt/C6T8WrrlpDzzKf3+T2yL3KZsBIcMGmfaZzZoiC0tpYxyru3E@lists.postgresql.org X-Gm-Message-State: AOJu0Yz+GkcTJSVsoW22qGii6WrZVp7Hb5qM3nJLIxDMc0RCE63OdXMH ZOp3C8ASk/NrqbDd9agLsEJZvJ+S5yfUBDhzMPT0LysWBk2RcOgaMvRFzGigIGs= X-Google-Smtp-Source: AGHT+IFYsNV93zH4A0LbiPDFEWTDI+udv2n6BIBMsMeFoHU/E51bZnUNzLtoQiYKZ81YuTODs7gHFA== X-Received: by 2002:a17:90a:cb85:b0:2e2:e5d0:dabc with SMTP id 98e67ed59e1d1-2e8f10719e2mr47416158a91.11.1730941390726; Wed, 06 Nov 2024 17:03:10 -0800 (PST) Received: from [192.168.2.139] ([50.39.255.79]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2e99a544d82sm2481612a91.22.2024.11.06.17.03.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Nov 2024 17:03:10 -0800 (PST) Message-ID: <3b0e067d-9a78-46f7-8027-99c19e7cde44@illuminatedcomputing.com> Date: Wed, 6 Nov 2024 17:03:09 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: SQL:2011 application time To: Sam Gabrielsson Cc: Peter Eisentraut , jian he , Isaac Morland , Robert Haas , Jeff Davis , PostgreSQL Hackers References: <30dc3561-d7ab-42be-a1c5-096643423590@illuminatedcomputing.com> <73d09e24-b6b9-4c89-8c0a-8842ca0f81f9@illuminatedcomputing.com> <081aa43c-3a97-4bd5-a498-ba02e0a7570d@illuminatedcomputing.com> <54390149-11d6-4f52-bbe8-f69832ceb3bd@eisentraut.org> <9b7cb814-c78c-489f-85b2-32be4398647f@illuminatedcomputing.com> <95c6d49b-7d60-4ad0-820c-e00ae1b2a3d4@illuminatedcomputing.com> <57ea0668-5205-426e-b934-efc89f2186c2@illuminatedcomputing.com> Content-Language: en-US From: Paul Jungwirth In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/4/24 13:16, Sam Gabrielsson wrote: > Foreign key violation errors are incorrectly raised in a few cases for a temporal foreign key with > default ON UPDATE NO ACTION. Test is based on the commited v39 patches (used a snapshot version of > PG18 devel available from PGDG). Thank you for the report! I confirmed that this is a problem. In ri_restrict we fail if any fk records still match the being-changed pk, but for temporal if you're merely shrinking the pk range, fk references could still wind up being valid (if you're only shrinking it a little). So we need to do more work. > In the temporal NO ACTION case something similar to this (though with appropriate locks) could > perhaps be tested in ri_restrict (when ri_Check_Pk_Match returns false): > >   SELECT 1 >   FROM (SELECT range_agg(pkperiodatt) AS r >       FROM >       WHERE pkatt1 = $1 [AND ...] >       AND pkperiodatt && $n) AS pktable, >     (SELECT fkperiodatt AS r >       FROM >       WHERE fkatt1 = $1 [AND ...] >       AND fkperiodatt && $n) AS fktable >   WHERE NOT fktable.r <@ pktable.r This solution looks like it will work to me. Basically: find FKs that still match the PK, but only fail if they are no longer covered. IIRC for RESTRICT it is *correct* to reject the change, so we would want to keep the old SQL there, and only update it for NOACTION. I'll work on a fix and submit another set of patches. Yours, -- Paul ~{:-) pj@illuminatedcomputing.com