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 1sXEt8-002dQv-SW for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2024 06:57:14 +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 1sXEt6-006uMb-PT for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jul 2024 06:57:12 +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 1sXEt6-006uMS-FP for pgsql-hackers@lists.postgresql.org; Fri, 26 Jul 2024 06:57:12 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sXEsz-001Wq5-HQ for pgsql-hackers@postgresql.org; Fri, 26 Jul 2024 06:57:11 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-52efd530a4eso1408547e87.0 for ; Thu, 25 Jul 2024 23:57:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721977024; x=1722581824; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uw/RgJMvhYeBUZdnQn3P/2Umc+CjNeQPmFmxp24gQaM=; b=MARcernLuVEgMnVuwvdymOdwcX5YNr7p/yI5+eVyaRJBgdl4KwhNqcoARITLcpEi43 nJ8Uy5d76GYrJOM8zjx9oouDGjo1fhx3YnIhAmWB7u9it1t5sgR8HjvgmQiUa2+xLG7h zSCB+XAANOOLPx9KQJVs5jXZXYXe7YR9zgeADFMUB0quGynPguxZhyOYuwdh1/6+Jihp 93+hR8601BvEX5boAle6tIYdf6RHWXiacHTtAZL9QGHdy2joSOyJfcwqrg3khENVMbUf /25RNgLqbraFQhSvGohxHpZA7aweh4aL/o9bQz1aScUCRhEjLqe0fWahH7SRu/AvohB5 bzag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721977024; x=1722581824; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uw/RgJMvhYeBUZdnQn3P/2Umc+CjNeQPmFmxp24gQaM=; b=dWB0u/smNI2z/2Y7PNnY06CViJ6nDAQqTMQ5ezBKDF3ZfZ5KVB/MrL0ygQzS93mqCP 0S1MY7r55mljj5R9+3eUwGWdWYM5b9O98FyeuNrfga1mpYrps2FlMFC73iDOgZDyDKkN ZeXY9RxCk8tZWI801T67/RZqorKtQfvCP2aroPnuDGTe+4Cemi4et9S7eBORsgnMUuD7 x1EwddKi6CQ/Fm0/D+WriChDSG5OMzFrojQdlybYtA6L/+0CgMWnFzCXwKjrfMKct8BD clTJxOVUmm9SLgJPgj0YroTUA2uJ+zSHqftuIwNzC1g9JfP/KW4wpHbjPWaCA/ezTawa 5ybA== X-Forwarded-Encrypted: i=1; AJvYcCUQYSgSwbIqq41WsrXWRIgtws/oXIdgZWRFi74YS3RkAYbLa3uIqfHkIy1kx/qYUgHZSiPZRq9C8gjtmK1oC2qtX5shjD7PwCuGm4i/ X-Gm-Message-State: AOJu0YxNpA7wpCPaGzyE4Bz0ELO0WSRevTszhlocNZL9E55fxQ3Ibabq 9No381F3uq8QjKIFc1SYCC5y++8yLdN3HWrUCwykTwm3Z+2JzRQTsS7T04OUVZrvt36rGyEPLFg nfZ27xegf+5gtU8+fjh79uuq8pYU= X-Google-Smtp-Source: AGHT+IER1t4rMHPznERsucRSVPfZfEJiq8sT6Na/tYmQoxwZUib0lGUdjH4uDHR6Ww6BQApSBpe4SPUH7+HjIU0yKCk= X-Received: by 2002:a05:6512:3d21:b0:52c:d905:9645 with SMTP id 2adb3069b0e04-52fd60944ffmr3446647e87.13.1721977023779; Thu, 25 Jul 2024 23:57:03 -0700 (PDT) MIME-Version: 1.0 References: <202407191318.uecnw7oaidhu@alvherre.pgsql> In-Reply-To: From: Junwang Zhao Date: Fri, 26 Jul 2024 14:56:51 +0800 Message-ID: Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails To: Tender Wang Cc: Alvaro Herrera , Jehan-Guillaume de Rorthais , "pgsql-hackers@postgresql.org" , Alexander Lakhin Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jul 26, 2024 at 2:36=E2=80=AFPM Junwang Zhao wr= ote: > > On Mon, Jul 22, 2024 at 1:52=E2=80=AFPM Tender Wang = wrote: > > > > > > > > Alvaro Herrera =E4=BA=8E2024=E5=B9=B47=E6=9C= =8819=E6=97=A5=E5=91=A8=E4=BA=94 21:18=E5=86=99=E9=81=93=EF=BC=9A > >> > >> Hello, > >> > >> I think the fix for the check triggers should be as the attached. Ver= y > >> close to what you did, but you were skipping some operations that need= ed > >> to be kept. AFAICS this patch works correctly for the posted cases. > > > > > > After applying the attached, the r_1_p_id_fkey1 will have redundant act= ion > > triggers, as below: > > postgres=3D# select oid, conname, contype, conrelid, conindid,conparent= id, confrelid,conislocal,coninhcount, connoinherit from pg_constraint where= oid =3D 16402; > > oid | conname | contype | conrelid | conindid | conparentid |= confrelid | conislocal | coninhcount | connoinherit > > -------+----------------+---------+----------+----------+-------------+= -----------+------------+-------------+-------------- > > 16402 | r_1_p_id_fkey1 | f | 16394 | 16392 | 0 |= 16389 | t | 0 | f > > (1 row) > > > > postgres=3D# select oid, tgrelid, tgparentid, tgconstrrelid, tgconstrin= did, tgconstraint from pg_trigger where tgconstraint =3D 16402; > > oid | tgrelid | tgparentid | tgconstrrelid | tgconstrindid | tgconst= raint > > -------+---------+------------+---------------+---------------+--------= ------ > > 16403 | 16389 | 16400 | 16394 | 16392 | = 16402 > > 16404 | 16389 | 16401 | 16394 | 16392 | = 16402 > > 16422 | 16389 | 0 | 16394 | 16392 | = 16402 > > 16423 | 16389 | 0 | 16394 | 16392 | = 16402 > > (4 rows) > > > > Yes, seems Alvaro has mentioned that he hasn't looked at the > action triggers, in the attached patch, I add some logic that > first check if there exists action triggers, if yes, just update > their Parent Trigger to InvalidOid. > > > > > -- > > Tender Wang > > > > -- > Regards > Junwang Zhao There is a bug report[0] Tender comments might be the same issue as this one, but I tried Alvaro's and mine patch, neither could solve that problem, I did not tried Tender's earlier patch thought. I post the test script below in case you are interested. CREATE TABLE t1 (a int, PRIMARY KEY (a)); CREATE TABLE t (a int, PRIMARY KEY (a), FOREIGN KEY (a) REFERENCES t1) PARTITION BY LIST (a); ALTER TABLE t ATTACH PARTITION t1 FOR VALUES IN (1); ALTER TABLE t DETACH PARTITION t1; ALTER TABLE t ATTACH PARTITION t1 FOR VALUES IN (1); [0] https://www.postgresql.org/message-id/18541-628a61bc267cd2d3@postgresql= .org --=20 Regards Junwang Zhao