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 1wLaYr-001snG-1R for pgsql-hackers@arkaria.postgresql.org; Sat, 09 May 2026 05:49:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wLaXp-00CLRJ-0o for pgsql-hackers@arkaria.postgresql.org; Sat, 09 May 2026 05:48:09 +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 1wLaXo-00CLPV-2m for pgsql-hackers@lists.postgresql.org; Sat, 09 May 2026 05:48:08 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wLaXj-00000000wFz-0eNp for pgsql-hackers@lists.postgresql.org; Sat, 09 May 2026 05:48:07 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-364f7c42c62so2400904a91.0 for ; Fri, 08 May 2026 22:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778305681; x=1778910481; darn=lists.postgresql.org; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=/C59KCoSM/iE64N3mmracPCVQY9jLy580G4E+/kQBuo=; b=luhufq7unTfkApkljsZhVk2dJ7sw3Es0xC6LCPZHc8Nhf9e1Nd4HtncW2AAV4W2cDL lyAcLzqXZ82QmFZu4w7kP9Kc+Xhr+WXEBEXoY2+gmtejRbRpJWYtoQtxIuNBKLjmCT/2 VoYxFwBEesCxMOO2NfqXV8FPSJLaHxIWXzA5xrQh2w0HOX5ghnhbNaItD/HCjU9QMl78 zwrIGjfBwQ2wQCeMvC0psPr4e0wndPHAu91i9YriK8/IRyLsqchCm/oaVIaH3a1NJ+GL m1aVz+iA8rlEnCydcxMCqt/Xy5Xj6OOQjxJfv51iGnTwTBwtZ3Qn5h9wdU8hq3gk5VWx YUqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778305681; x=1778910481; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=/C59KCoSM/iE64N3mmracPCVQY9jLy580G4E+/kQBuo=; b=Iv5r+OfDFgwpENcnfj4NDq2ux4oHP9fT6TZFVkam0FXkEH2I1I5alEGRiTGQzbhMtv 3iKbqdSZnTKXUOv0mtplnRz8fE0vS0L8HcHHazDMrsDqtuKyWO+uIdn065HgOh0lAi0M gPSDH6jT80wTKhUiCKE38PfR4AE2PNzXtc9/O4B04gUrpup76N/CkVe5atBSQKMmcc6H 7+EqsgBct0DTqhuxSqgW2FwZgXDZfgdXt61Ld2PbJ6p98N53cMt9MFXEo8RUqqap+YPy N+cQbLQ2WV0GRUJU3b1CCubOWkpQ85dcadRYTy2CSQ2lQzuWKr0U+W91ng+sC+vZ6eo+ 3Rhw== X-Gm-Message-State: AOJu0Yy9MJe/SSSE1GEkOzxTFc9FulUOrg8cEggkw47i8HjmWI9g9RNx 5bR12T8Y9iQH+S8eroSLGBPUveytfL9VBVeej6z9wJtgfTzDOg+52qTm5dZxeanD X-Gm-Gg: Acq92OEwPH0BWO3J+2NCcN2bKXxw+0CVRvKRLUBtSDhphP1vIV2tKIdjFg0/l87o3Fb n/dHDYpgLr7ucG0jFU0vDBKiP4d9ZfoANjqXDi0Ldqb+tvcvDHq3AnF1+/iUdX45TH7K5VSFmGa K2NyLlepKXnwOOhSrMQhfwVA83cMafFo9PEkHsRNO3KDR0BY7fqpjG7EZy3tQhN2YjQGT0gQs5+ ppPoDJNTKlVcv/DtE8r7YybPAGqc3OIOMGgItINdCh8W3mYur0h739+i3J9UMm65i9rkgdmyywe Q6nwUfNxtjBygLXmkqo67mACKC6n+gZuJu/jJYgnr7CRPxTMDabpVAi7j6jF52m1jXzfSNYcD1T gAZHlk0DydtABVlDYkNf1AQQ12xI23Jm3Ifuc55+UJtcp87qN0G2+HwvFrjnQSCvcOGjqfJ39zM 18qVjuqhb5KFBovPuiW3KxK9dGpnc0e9k0JprgJJY2gw== X-Received: by 2002:a17:90b:2703:b0:35d:a5cb:95c1 with SMTP id 98e67ed59e1d1-365ac76b0ccmr14539900a91.23.1778305680956; Fri, 08 May 2026 22:48:00 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-367d629c17esm899171a91.6.2026.05.08.22.47.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 May 2026 22:48:00 -0700 (PDT) From: Chao Li Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Fix bug of UPDATE/DELETE FOR PORTION OF with inheritance tables Date: Sat, 9 May 2026 13:47:22 +0800 References: <4245F94D-84F1-4E05-BF81-C458A6CF9901@gmail.com> To: PostgreSQL Hackers In-Reply-To: <4245F94D-84F1-4E05-BF81-C458A6CF9901@gmail.com> Message-Id: <260A544F-FBD6-40CC-9449-5987049DD2D4@gmail.com> X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On May 7, 2026, at 11:40, Chao Li wrote: >=20 > Hi, >=20 > While testing UPDATE FOR PORTION OF, I found a bug with inheritance = tables. The following repro shows the problem more clearly than a = description in words: > ``` > evantest=3D# create table p (id int, valid_at daterange, name text); > CREATE TABLE > evantest=3D# create table c (extra text) inherits (p); > CREATE TABLE > evantest=3D# insert into c values (1, daterange('2000-01-01', = '2010-01-01'), 'old', 'x'); > INSERT 0 1 > evantest=3D# update p for portion of valid_at from '2001-01-01' to = '2002-01-01' set name =3D 'new' where id =3D 1; > UPDATE 1 > evantest=3D# select * from only p; > id | valid_at | name > ----+-------------------------+------ > 1 | [2000-01-01,2001-01-01) | old > 1 | [2002-01-01,2010-01-01) | old > (2 rows) >=20 > evantest=3D# select * from only c; > id | valid_at | name | extra > ----+-------------------------+------+------- > 1 | [2001-01-01,2002-01-01) | new | x > (1 row) > ``` >=20 > In this repro, the original tuple is inserted into the child table c, = while the parent table p is empty. After the update, the updated portion = is left in c, but the two leftover ranges are inserted into p, which is = clearly wrong. >=20 > The same bug exists for DELETE FOR PORTION OF with inheritance tables = as well: > ``` > evantest=3D# delete from p for portion of valid_at from '2001-01-01' = to '2002-01-01' where id =3D 1; > DELETE 1 > evantest=3D# select * from only p; > id | valid_at | name > ----+-------------------------+------ > 1 | [2000-01-01,2001-01-01) | old > 1 | [2002-01-01,2010-01-01) | old > (2 rows) >=20 > evantest=3D# select * from only c; > id | valid_at | name | extra > ----+----------+------+------- > (0 rows) > ``` >=20 > After looking into the code, I found that leftover row insertion only = considers the partitioned-table case, where leftovers need to be = inserted through the root relation for partition routing. Plain = inheritance is different, leftover rows should be inserted back into the = actual child relation. >=20 > While debugging this, I also noticed another issue around mapping the = range column=E2=80=99s attnum. In multiple-inheritance cases, the range = column=E2=80=99s attnum in a child table may be different from the one = in its parent, so we need to use the child=E2=80=99s actual attnum. >=20 > Please see the attached patch for the fix details and the new tests. = Since I believe this bug was introduced in 19, I=E2=80=99m going to add = it to the open items. >=20 > Best regards, > -- > Chao Li (Evan) > HighGo Software Co., Ltd. > https://www.highgo.com/ >=20 >=20 >=20 >=20 > Merged into [1]. [1] = https://postgr.es/m/CAHg+QDcd=3Dt69gLf9yQexO07EJ2mx0Z70NFHo6h94X1EDA=3DhM0= g@mail.gmail.com Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/