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 1st3H4-00D91L-I9 for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Sep 2024 11:00:07 +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 1st3H3-006Ozm-RG for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Sep 2024 11:00:05 +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 1st3H3-006Ozd-IZ for pgsql-bugs@lists.postgresql.org; Tue, 24 Sep 2024 11:00:05 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1st3H0-000pOD-Cb for pgsql-bugs@lists.postgresql.org; Tue, 24 Sep 2024 11:00:04 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2f7528f4658so46940561fa.3 for ; Tue, 24 Sep 2024 04:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727175603; x=1727780403; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Muy274rzPhmzCWnhC6uRKm719NQBvSoZ1F5N8FzxL1o=; b=moPn9BFEeTqSXKHyzVJ2s0Y3jfelElo+2jRB332Isu/5/1dgP1R6NLCalVH2v+sBWC hb85lFO8UuA8Sf2zTz9RNfeitCIwHPTJH7KFMUqRPONgyvoKhXUjvWg3LVkxjR7RL3gd ulnfdnfLWhObV3L7drFqyXJXeTtxKtit2zLPbSjEfvf00hu/S/IUWS35ssTopI8/cOpj A4C3Lg4EJiUHTqykKCSrsQO/B5B5sdegcbN4szL3DRLeIKkvN3uDZXeDa8GDjsDdnYaJ if4036Uz68xTrU/Y9lZmYbpaJGxivwRpi/dJT8ZsOsg46/OPOCU9JFAEka5flOk2o+VU RrMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727175603; x=1727780403; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Muy274rzPhmzCWnhC6uRKm719NQBvSoZ1F5N8FzxL1o=; b=fJ7hmKW8ML95EKDH+Z5S34uEFxETcji+LIl1EJ2NX7W631OsMwd13hWbZHOQkDDzcf QRUX2N3xY9C2ZI8M/VRFLspSFhw2WTdLtfl2xIEjgpJGoggL63/s5u3ZeUds5WZJlj9L gWV8IurhlLJ3j6eLF3K3oAI0SA51L5wxd8ohNn/f8jcD0+H7pHsXkbCOzKa+3/YRteaD RpisAAwhlk83s1pzeV8VbVctSG20nPXYyn1TLjY5DbyrlO4rIuxTtvpOqA3oinjtUbpP 7SUBztOkrdAeb0JoVO/kPt+RAvuVfuY4tOjeUyAVz7mtyCVXH6vgpgevlQrLMR7yKd0g aQKA== X-Gm-Message-State: AOJu0Yz85PpGEAoFb4nRSG/cqCV1ogIep2YYS32Sn9PH+D86KBc1nhRT 7fQm9EIaK4nLq2hhFz+9dP0ztqAqEqzbkApVJevO3K4eLyCYWQ/c0km83Q== X-Google-Smtp-Source: AGHT+IF/qKUPBiohE3CIIgIDR9bSzxctZz6Evfn/YYi8IdLef4ulmGbqGTNJO4vCn5KHawTtqb/E9w== X-Received: by 2002:a2e:70a:0:b0:2f7:4f46:8344 with SMTP id 38308e7fff4ca-2f7cb302396mr64510851fa.21.1727175602432; Tue, 24 Sep 2024 04:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.20.161]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f8d282fd34sm1828581fa.28.2024.09.24.04.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Sep 2024 04:00:01 -0700 (PDT) Message-ID: <2db29417-eac1-35b6-94e3-a9c0bdb9c035@gmail.com> Date: Tue, 24 Sep 2024 14:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #18628: Race condition during attach/detach partition breaks constraints of partition having foreign key Content-Language: en-US To: pgsql-bugs@lists.postgresql.org, Alvaro Herrera References: <18628-4f11be4e0b1c9002@postgresql.org> From: Alexander Lakhin In-Reply-To: <18628-4f11be4e0b1c9002@postgresql.org> 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 22.09.2024 17:00, PG Bug reporting form wrote: > The following script: > ... > ends up with: > ERROR: could not find ON INSERT check triggers of foreign key constraint > 16409 I'm sorry,  I' was too hasty to untangle those queries. Now I see that this error can be produced with this serial script: CREATE TABLE pt (id int PRIMARY KEY, rid int,   FOREIGN KEY (rid) REFERENCES pt(id)) PARTITION BY LIST (id); CREATE TABLE p1 PARTITION OF pt FOR VALUES IN (1); ALTER TABLE pt DETACH PARTITION p1; -- p1 gets a constraint: -- "pt_rid_fkey" FOREIGN KEY (rid) REFERENCES pt(id) CREATE TABLE p2 PARTITION OF pt FOR VALUES IN (2); -- CloneFkReferenced() -> addFkRecurseReferenced() clones the above -- constraint and creates another one: -- conname: p1_rid_fkey, conrelid: id of p1, confrelid: id of p2, -- conparentid: id of the above constraint -- (\d+ p2 doesn't show this constraint due to conparentid != 0) ALTER TABLE pt ATTACH PARTITION p1 FOR VALUES IN (1); -- p1 attached with no constraints added or removed ALTER TABLE pt DETACH PARTITION p1; -- DetachPartitionFinalize() gets the p1_rid_fkey constraint with -- RelationGetFKeyList(partRel) and then fails to find INSERT trigger for -- it, because the constraint has only DELETE and UPDATE triggers linked -- to the p2 relation. ERROR:  could not find ON INSERT check triggers of foreign key constraint 16410 Alvaro, could you please take a look at this? Best regards, Alexander