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 1wKpbe-001KkF-1b for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 03:40:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKpbd-001klR-0O for pgsql-hackers@arkaria.postgresql.org; Thu, 07 May 2026 03:40:57 +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 1wKpbc-001klJ-1p for pgsql-hackers@lists.postgresql.org; Thu, 07 May 2026 03:40:56 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wKpbZ-00000000aI3-3t7f for pgsql-hackers@lists.postgresql.org; Thu, 07 May 2026 03:40:55 +0000 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-c8025500cc7so236259a12.1 for ; Wed, 06 May 2026 20:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778125253; x=1778730053; darn=lists.postgresql.org; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=DjQIal/BY1rfCdEJB247GjMBVbKHna9mR7g0s3EWeDM=; b=i64uBiV6KhtLYgPaoiLS6bZLdQpd3YSM4lbAfZPFK280GDsXANW5eblSerZDXddUrC RDJ06B9mPytsHYhy7qb39+YYoxjoe9UXT2+2Q61vdgUaQS7+tHzDuU/6Hivry86uJQO2 HB5eKJHPXghLt0h6Z/6IboJBpjyUYtpkvvivWN8ROARgzSv/JAz+uRmtUB43IJ5q5Hsl qNm6xq57Fj2okwf9wTVHaML1PmfbxEqcvHc59by5f+K7kO/9BiW+wZ0W7XNfk8I6wLu7 GnzdrsMlwMJPxEeYFyqWkVNg9UXumPX/d6TipgKtcg3pL2Z0cmgpN9A0MGTQrk584XKb pzZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778125253; x=1778730053; h=to:date:message-id:subject:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DjQIal/BY1rfCdEJB247GjMBVbKHna9mR7g0s3EWeDM=; b=gJDHEKOMgpa/06lH3/iu180uYucKtCf3NSRisogF8cIuBk0iN3e0IUOdJQ1x7o+SRI Iz1IbufpJSRzN+29K4pnQzAQbjO/8QjEtGmoDh6iHkqlO79DYAnL37fGZyuE3kDefbG9 GnIhJyju+fpn9nSsKUxLCfAvdAwI4dbKFUmaG0yieWomg29MQrbn5ueFhQSXCKQZnIEL o48X7Tc2L8i3r3RhBNu6U/ilpA+FZk2EgRE71y9xb5uLaHtnObczhDgUbvxoTyCgU4j7 QP6fSdM3lQ+h3vb0Qoj+JSq6G7hpNsZ2jxq1lLpjmNAyFzlqNXEuhih5n2P/SlKBlFN5 N2vg== X-Gm-Message-State: AOJu0YxikS6INQuBGdL8acWnxfccT/UMIIB0fuY82+Hx1+MiMCjrKKDM LWm9kds3QpVIf4T2L6aYa2RQzoQW3ERgs3MfS8HnKY3JcuP59UudN78jyNWBBbIJ X-Gm-Gg: AeBDieuAlZILxaLZyIvlLeeM7gpMPrP07qb2zDDwpPduynQ1BSLYaxDhWGh0SkKZOIm lOd1MTqLI2Jd/GXA492aLdlG5L8KjDpvg4l30FCWO7X6XFDEocUuIeeVpfCur+EitjJeCgdM3uP 2MweFvPqF8txHFc3gfm6zPCrVmL79GKMDmnInuSBsgTUrmXCBbtJqe5LVL+PK4T6D9qMpoUK1Oj dLV2tpQwm75fsr0k4DhYZ0RQRXtpPpAYw8n2RwTZ1Dj+E0XZHDC3HOq11ND8gNG5oB5dA6Dmr6v 77dY9kmVHAc+iC0NkOF0qd18EGHPGo8RPXufWNF6d9fT5Bd1hpdeE3/s4i4iy+jZT81aeACXNLq b8R7aFJM8eBEP/KCC0gEv6D2AfS9orVlxx96kEFwOi/NHoGCSTuuN9MU/gSfON3V8968yE0clCc FFen10+gu+/UZxsSwC3MTe8BZ4OsHiTi+NLF8YQRiR/w== X-Received: by 2002:a05:6a20:2443:b0:39b:ba95:b127 with SMTP id adf61e73a8af0-3aa5a83151bmr7382856637.4.1778125252667; Wed, 06 May 2026 20:40:52 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8253582936sm638923a12.3.2026.05.06.20.40.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 May 2026 20:40:51 -0700 (PDT) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_CFF5D747-860B-48D5-BFE7-16A0AF469020" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Fix bug of UPDATE/DELETE FOR PORTION OF with inheritance tables Message-Id: <4245F94D-84F1-4E05-BF81-C458A6CF9901@gmail.com> Date: Thu, 7 May 2026 11:40:12 +0800 To: PostgreSQL Hackers X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_CFF5D747-860B-48D5-BFE7-16A0AF469020 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, 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) evantest=3D# select * from only c; id | valid_at | name | extra ----+-------------------------+------+------- 1 | [2001-01-01,2002-01-01) | new | x (1 row) ``` 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. 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) evantest=3D# select * from only c; id | valid_at | name | extra ----+----------+------+------- (0 rows) ``` 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. 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. 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. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_CFF5D747-860B-48D5-BFE7-16A0AF469020 Content-Disposition: attachment; filename=v1-0001-Fix-FOR-PORTION-OF-leftovers-for-inheritance-chil.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-Fix-FOR-PORTION-OF-leftovers-for-inheritance-chil.patch" Content-Transfer-Encoding: quoted-printable =46rom=2092abeba40fb1ef795a7f0eea198d7c144aef20fe=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Thu,=207=20May=202026=2011:23:10=20+0800=0ASubject:=20[PATCH=20= v1]=20Fix=20FOR=20PORTION=20OF=20leftovers=20for=20inheritance=20= children=0A=0AExecForPortionOfLeftovers()=20assumed=20that=20any=20= result=20relation=20with=0Ari_RootResultRelInfo=20should=20reinsert=20= temporal=20leftovers=20through=20the=20root=0Arelation.=20=20That=20is=20= correct=20for=20partitioned=20tables,=20where=20tuple=20routing=20is=0A= needed,=20but=20it=20is=20wrong=20for=20plain=20inheritance.=0A=0AWhen=20= UPDATE/DELETE=20FOR=20PORTION=20OF=20is=20run=20on=20an=20inheritance=20= parent=20and=20a=0Achild=20row=20is=20split,=20the=20leftover=20rows=20= must=20be=20inserted=20back=20into=20the=20child=0Arelation.=20=20= Reinserting=20through=20the=20parent=20can=20lose=20child-only=20columns=20= and=0Aplace=20the=20leftover=20rows=20in=20the=20wrong=20relation.=0A=0A= Fix=20this=20by=20distinguishing=20partitioned-table=20routing=20from=20= plain=0Ainheritance.=20=20For=20partitioned=20tables,=20keep=20using=20= the=20root=20leftover=20slot=20and=0Ainsert=20through=20the=20root=20= relation.=20=20For=20plain=20inheritance=20children,=20use=20a=0A= leftover=20slot=20matching=20the=20child=20relation=20and=20insert=20= directly=20into=20the=0Achild.=20=20Also=20keep=20translating=20the=20= application-time=20column=20attno=20for=20child=0Arelations,=20so=20= multiple-inheritance=20cases=20with=20different=20attribute=20numbers=0A= are=20handled=20correctly.=0A=0AAdd=20regression=20tests=20for=20UPDATE=20= and=20DELETE=20FOR=20PORTION=20OF=20on=20inheritance=0Achildren,=20= including=20a=20multiple-inheritance=20case=20where=20the=20range=20= column=20has=0Aa=20different=20attnum=20in=20the=20parent=20and=20child.=0A= =0AAuthor:=20Chao=20Li=20=0AReviewed-by:=0ADiscussion:=20= https://postgr.es/m/=0A---=0A=20src/backend/executor/nodeModifyTable.c=20= =20=20=20=20=20=20|=20=2076=20++++++++----=0A=20= src/test/regress/expected/for_portion_of.out=20|=20119=20= +++++++++++++++++++=0A=20src/test/regress/sql/for_portion_of.sql=20=20=20= =20=20=20|=20=2080=20+++++++++++++=0A=203=20files=20changed,=20252=20= insertions(+),=2023=20deletions(-)=0A=0Adiff=20--git=20= a/src/backend/executor/nodeModifyTable.c=20= b/src/backend/executor/nodeModifyTable.c=0Aindex=20= 4cb057ca4f9..df3e3bb1b98=20100644=0A---=20= a/src/backend/executor/nodeModifyTable.c=0A+++=20= b/src/backend/executor/nodeModifyTable.c=0A@@=20-1409,7=20+1409,11=20@@=20= ExecForPortionOfLeftovers(ModifyTableContext=20*context,=0A=20=09= ModifyTableState=20*mtstate=20=3D=20context->mtstate;=0A=20=09= ModifyTable=20*node=20=3D=20(ModifyTable=20*)=20mtstate->ps.plan;=0A=20=09= ForPortionOfExpr=20*forPortionOf=20=3D=20(ForPortionOfExpr=20*)=20= node->forPortionOf;=0A-=09AttrNumber=09rangeAttno;=0A+=09AttrNumber=09= actualRangeAttno;=09/*=20attno=20of=20range=20column=20in=20the=20= current=0A+=09=09=09=09=09=09=09=09=09=20*=20result=20relation=20*/=0A+=09= AttrNumber=09targetRangeAttno;=09/*=20attno=20of=20range=20column=20in=20= the=20target=0A+=09=09=09=09=09=09=09=09=09=20*=20table=20of=20the=20= query=20*/=0A+=09AttrNumber=09leftoverRangeAttno;=0A=20=09Datum=09=09= oldRange;=0A=20=09TypeCacheEntry=20*typcache;=0A=20=09ForPortionOfState=20= *fpoState;=0A@@=20-1422,18=20+1426,30=20@@=20= ExecForPortionOfLeftovers(ModifyTableContext=20*context,=0A=20=09= FmgrInfo=09flinfo;=0A=20=09PgStat_FunctionCallUsage=20fcusage;=0A=20=09= ReturnSetInfo=20rsi;=0A+=09ResultRelInfo=20*rootRri=20=3D=20= resultRelInfo->ri_RootResultRelInfo;=0A=20=09bool=09=09didInit=20=3D=20= false;=0A=20=09bool=09=09shouldFree=20=3D=20false;=0A+=09bool=09=09= partitionRouting;=0A=20=0A=20=09LOCAL_FCINFO(fcinfo,=202);=0A=20=0A+=09= partitionRouting=20=3D=0A+=09=09rootRri=20!=3D=20NULL=20&&=0A+=09=09= rootRri->ri_RelationDesc->rd_rel->relkind=20=3D=3D=20= RELKIND_PARTITIONED_TABLE;=0A+=09targetRangeAttno=20=3D=20= forPortionOf->rangeVar->varattno;=0A+=0A=20=09if=20= (!resultRelInfo->ri_forPortionOf)=0A=20=09{=0A=20=09=09/*=0A-=09=09=20*=20= If=20we=20don't=20have=20a=20ForPortionOfState=20yet,=20we=20must=20be=20= a=20partition=0A-=09=09=20*=20child=20being=20hit=20for=20the=20first=20= time.=20Make=20a=20copy=20from=20the=20root,=20with=0A-=09=09=20*=20our=20= own=20TupleTableSlot.=20We=20do=20this=20lazily=20so=20that=20we=20don't=20= pay=20the=0A-=09=09=20*=20price=20of=20unused=20partitions.=0A+=09=09=20= *=20If=20we=20don't=20have=20a=20ForPortionOfState=20yet,=20we=20must=20= be=20a=20child=0A+=09=09=20*=20relation=20being=20hit=20for=20the=20= first=20time.=20Make=20a=20copy=20from=20the=20root,=0A+=09=09=20*=20= with=20slots=20matching=20the=20child's=20tuple=20descriptor.=0A+=09=09=20= *=0A+=09=09=20*=20Partitions=20share=20the=20root=20leftover=20slot,=20= since=20they=20must=20insert=20via=0A+=09=09=20*=20the=20root=20relation=20= to=20get=20tuple=20routing.=20Plain=20inheritance=20children=0A+=09=09=20= *=20must=20keep=20their=20own=20leftover=20slot=20and=20insert=20back=20= into=20the=20child,=0A+=09=09=20*=20or=20else=20child-only=20column=20= values=20and=20physical=20placement=20would=20be=0A+=09=09=20*=20lost.=0A= =20=09=09=20*/=0A=20=09=09ForPortionOfState=20*leafState=20=3D=20= makeNode(ForPortionOfState);=0A=20=0A@@=20-1447,8=20+1463,15=20@@=20= ExecForPortionOfLeftovers(ModifyTableContext=20*context,=0A=20=09=09= leafState->fp_rangeType=20=3D=20fpoState->fp_rangeType;=0A=20=09=09= leafState->fp_rangeAttno=20=3D=20fpoState->fp_rangeAttno;=0A=20=09=09= leafState->fp_targetRange=20=3D=20fpoState->fp_targetRange;=0A-=09=09= leafState->fp_Leftover=20=3D=20fpoState->fp_Leftover;=0A-=09=09/*=20Each=20= partition=20needs=20a=20slot=20matching=20its=20tuple=20descriptor=20*/=0A= +=09=09if=20(partitionRouting)=0A+=09=09=09leafState->fp_Leftover=20=3D=20= fpoState->fp_Leftover;=0A+=09=09else=0A+=09=09=09leafState->fp_Leftover=20= =3D=0A+=09=09=09=09ExecInitExtraTupleSlot(mtstate->ps.state,=0A+=09=09=09= =09=09=09=09=09=09=20=20=20resultRelInfo->ri_RelationDesc->rd_att,=0A+=09= =09=09=09=09=09=09=09=09=20=20=20&TTSOpsVirtual);=0A+=0A+=09=09/*=20Each=20= child=20relation=20needs=20a=20slot=20matching=20its=20tuple=20= descriptor=20*/=0A=20=09=09leafState->fp_Existing=20=3D=0A=20=09=09=09= table_slot_create(resultRelInfo->ri_RelationDesc,=0A=20=09=09=09=09=09=09= =09=20=20&mtstate->ps.state->es_tupleTable);=0A@@=20-1476,20=20+1499,22=20= @@=20ExecForPortionOfLeftovers(ModifyTableContext=20*context,=0A=20=09=09= elog(ERROR,=20"failed=20to=20fetch=20tuple=20for=20FOR=20PORTION=20OF");=0A= =20=0A=20=09/*=0A-=09=20*=20Get=20the=20old=20range=20of=20the=20record=20= being=20updated/deleted.=20Must=20read=20with=0A-=09=20*=20the=20attno=20= of=20the=20leaf=20partition=20being=20updated.=0A+=09=20*=20Get=20the=20= old=20range=20of=20the=20record=20being=20updated/deleted.=20The=20query=0A= +=09=20*=20expression=20uses=20the=20target=20relation's=20attno,=20but=20= the=20tuple=20slot=20may=0A+=09=20*=20belong=20to=20a=20child=20= relation.=20=20If=20so,=20translate=20it=20to=20the=20corresponding=0A+=09= =20*=20child=20attno.=0A=20=09=20*/=0A=20=0A-=09rangeAttno=20=3D=20= forPortionOf->rangeVar->varattno;=0A-=09if=20= (resultRelInfo->ri_RootResultRelInfo)=0A+=09actualRangeAttno=20=3D=20= targetRangeAttno;=0A+=09if=20(rootRri=20!=3D=20NULL)=0A=20=09=09map=20=3D=20= ExecGetChildToRootMap(resultRelInfo);=0A=20=09if=20(map=20!=3D=20NULL)=0A= -=09=09rangeAttno=20=3D=20map->attrMap->attnums[rangeAttno=20-=201];=0A+=09= =09actualRangeAttno=20=3D=20map->attrMap->attnums[actualRangeAttno=20-=20= 1];=0A=20=09slot_getallattrs(oldtupleSlot);=0A=20=0A-=09if=20= (oldtupleSlot->tts_isnull[rangeAttno=20-=201])=0A+=09if=20= (oldtupleSlot->tts_isnull[actualRangeAttno=20-=201])=0A=20=09=09= elog(ERROR,=20"found=20a=20NULL=20range=20in=20a=20temporal=20table");=0A= -=09oldRange=20=3D=20oldtupleSlot->tts_values[rangeAttno=20-=201];=0A+=09= oldRange=20=3D=20oldtupleSlot->tts_values[actualRangeAttno=20-=201];=0A=20= =0A=20=09/*=0A=20=09=20*=20Get=20the=20range's=20type=20cache=20entry.=20= This=20is=20worth=20caching=20for=20the=20whole=0A@@=20-1529,10=20= +1554,15=20@@=20ExecForPortionOfLeftovers(ModifyTableContext=20*context,=0A= =20=09/*=0A=20=09=20*=20If=20there=20are=20partitions,=20we=20must=20= insert=20into=20the=20root=20table,=20so=20we=20get=0A=20=09=20*=20tuple=20= routing.=20We=20already=20set=20up=20leftoverSlot=20with=20the=20root=20= tuple=0A-=09=20*=20descriptor.=0A+=09=20*=20descriptor=20for=20that=20= case.=0A=20=09=20*/=0A-=09if=20(resultRelInfo->ri_RootResultRelInfo)=0A-=09= =09resultRelInfo=20=3D=20resultRelInfo->ri_RootResultRelInfo;=0A+=09if=20= (partitionRouting)=0A+=09{=0A+=09=09resultRelInfo=20=3D=20rootRri;=0A+=09= =09leftoverRangeAttno=20=3D=20targetRangeAttno;=0A+=09}=0A+=09else=0A+=09= =09leftoverRangeAttno=20=3D=20actualRangeAttno;=0A=20=0A=20=09/*=0A=20=09= =20*=20Insert=20a=20leftover=20for=20each=20value=20returned=20by=20the=20= without_portion=20helper=0A@@=20-1574,11=20+1604,11=20@@=20= ExecForPortionOfLeftovers(ModifyTableContext=20*context,=0A=20=09=09{=0A=20= =09=09=09/*=0A=20=09=09=09=20*=20Make=20a=20copy=20of=20the=20pre-UPDATE=20= row.=20Then=20we'll=20overwrite=20the=0A-=09=09=09=20*=20range=20column=20= below.=20Convert=20oldtuple=20to=20the=20base=20table's=20format=0A-=09=09= =09=20*=20if=20necessary.=20We=20need=20to=20insert=20temporal=20= leftovers=20through=20the=0A-=09=09=09=20*=20root=20partition=20so=20= they=20get=20routed=20correctly.=0A+=09=09=09=20*=20range=20column=20= below.=20Only=20partitioned=20targets=20need=20conversion=20to=0A+=09=09=09= =20*=20the=20root=20table's=20format,=20because=20they=20reinsert=20= through=20the=20root=0A+=09=09=09=20*=20relation=20for=20tuple=20= routing.=0A=20=09=09=09=20*/=0A-=09=09=09if=20(map=20!=3D=20NULL)=0A+=09=09= =09if=20(partitionRouting=20&&=20map=20!=3D=20NULL)=0A=20=09=09=09{=0A=20= =09=09=09=09leftoverSlot=20=3D=20execute_attr_map_slot(map->attrMap,=0A=20= =09=09=09=09=09=09=09=09=09=09=09=09=09=20oldtupleSlot,=0A@@=20-1601,8=20= +1631,8=20@@=20ExecForPortionOfLeftovers(ModifyTableContext=20*context,=0A= =20=09=09=09didInit=20=3D=20true;=0A=20=09=09}=0A=20=0A-=09=09= leftoverSlot->tts_values[forPortionOf->rangeVar->varattno=20-=201]=20=3D=20= leftover;=0A-=09=09= leftoverSlot->tts_isnull[forPortionOf->rangeVar->varattno=20-=201]=20=3D=20= false;=0A+=09=09leftoverSlot->tts_values[leftoverRangeAttno=20-=201]=20=3D= =20leftover;=0A+=09=09leftoverSlot->tts_isnull[leftoverRangeAttno=20-=20= 1]=20=3D=20false;=0A=20=09=09ExecMaterializeSlot(leftoverSlot);=0A=20=0A=20= =09=09/*=0Adiff=20--git=20a/src/test/regress/expected/for_portion_of.out=20= b/src/test/regress/expected/for_portion_of.out=0Aindex=20= 0c0a205c44b..7d7847c9ad7=20100644=0A---=20= a/src/test/regress/expected/for_portion_of.out=0A+++=20= b/src/test/regress/expected/for_portion_of.out=0A@@=20-2097,6=20= +2097,125=20@@=20SELECT=20*=20FROM=20temporal_partitioned_5=20ORDER=20BY=20= id,=20valid_at;=0A=20(4=20rows)=0A=20=0A=20DROP=20TABLE=20= temporal_partitioned;=0A+--=20UPDATE/DELETE=20FOR=20PORTION=20OF=20with=20= inheritance=0A+CREATE=20TABLE=20fpo_parent=20(=0A+=20=20id=20int,=0A+=20=20= valid_at=20daterange,=0A+=20=20name=20text=0A+);=0A+CREATE=20TABLE=20= fpo_child=20(=0A+=20=20extra=20text=0A+)=20INHERITS=20(fpo_parent);=0A= +INSERT=20INTO=20fpo_child=20VALUES=0A+=20=20(1,=20= daterange('2000-01-01',=20'2010-01-01'),=20'old',=20'x');=0A+UPDATE=20= fpo_parent=20FOR=20PORTION=20OF=20valid_at=20FROM=20'2001-01-01'=20TO=20= '2002-01-01'=0A+=20=20SET=20name=20=3D=20'new'=0A+=20=20WHERE=20id=20=3D=20= 1;=0A+SELECT=20*=20FROM=20ONLY=20fpo_parent;=0A+=20id=20|=20valid_at=20|=20= name=20=0A+----+----------+------=0A+(0=20rows)=0A+=0A+SELECT=20*=20FROM=20= ONLY=20fpo_child;=0A+=20id=20|=20=20=20=20=20=20=20=20valid_at=20=20=20=20= =20=20=20=20=20|=20name=20|=20extra=20=0A= +----+-------------------------+------+-------=0A+=20=201=20|=20= [2001-01-01,2002-01-01)=20|=20new=20=20|=20x=0A+=20=201=20|=20= [2000-01-01,2001-01-01)=20|=20old=20=20|=20x=0A+=20=201=20|=20= [2002-01-01,2010-01-01)=20|=20old=20=20|=20x=0A+(3=20rows)=0A+=0A= +TRUNCATE=20TABLE=20fpo_child,=20fpo_parent;=0A+INSERT=20INTO=20= fpo_child=20VALUES=0A+=20=20(1,=20daterange('2000-01-01',=20= '2010-01-01'),=20'old',=20'x');=0A+DELETE=20FROM=20fpo_parent=20FOR=20= PORTION=20OF=20valid_at=20FROM=20'2001-01-01'=20TO=20'2002-01-01'=0A+=20=20= WHERE=20id=20=3D=201;=0A+SELECT=20*=20FROM=20ONLY=20fpo_parent;=0A+=20id=20= |=20valid_at=20|=20name=20=0A+----+----------+------=0A+(0=20rows)=0A+=0A= +SELECT=20*=20FROM=20ONLY=20fpo_child;=0A+=20id=20|=20=20=20=20=20=20=20=20= valid_at=20=20=20=20=20=20=20=20=20|=20name=20|=20extra=20=0A= +----+-------------------------+------+-------=0A+=20=201=20|=20= [2000-01-01,2001-01-01)=20|=20old=20=20|=20x=0A+=20=201=20|=20= [2002-01-01,2010-01-01)=20|=20old=20=20|=20x=0A+(2=20rows)=0A+=0A+DROP=20= TABLE=20fpo_child,=20fpo_parent;=0A+--=20UPDATE/DELETE=20FOR=20PORTION=20= OF=20with=20inheritance=20and=20differing=20attnos=0A+CREATE=20TABLE=20= temporal_parent=20(=0A+=20=20id=20int,=0A+=20=20valid_at=20daterange,=0A= +=20=20name=20text=0A+);=0A+CREATE=20TABLE=20other_parent=20(=0A+=20=20= prefix=20text,=0A+=20=20note=20text=0A+);=0A+CREATE=20TABLE=20mi_child=20= ()=20INHERITS=20(other_parent,=20temporal_parent);=0A+--=20attnum=20of=20= the=20range=20column=20is=20different=20in=20temporal_parent=20and=20= mi_child=0A+SELECT=20attnum,=20attname=0A+=20=20FROM=20pg_attribute=0A+=20= =20WHERE=20attrelid=20=3D=20'temporal_parent'::regclass=0A+=20=20=20=20= AND=20attnum=20>=200=20AND=20NOT=20attisdropped=0A+=20=20ORDER=20BY=20= attnum;=0A+=20attnum=20|=20attname=20=20=0A+--------+----------=0A+=20=20= =20=20=20=201=20|=20id=0A+=20=20=20=20=20=202=20|=20valid_at=0A+=20=20=20= =20=20=203=20|=20name=0A+(3=20rows)=0A+=0A+SELECT=20attnum,=20attname=0A= +=20=20FROM=20pg_attribute=0A+=20=20WHERE=20attrelid=20=3D=20= 'mi_child'::regclass=0A+=20=20=20=20AND=20attnum=20>=200=20AND=20NOT=20= attisdropped=0A+=20=20ORDER=20BY=20attnum;=0A+=20attnum=20|=20attname=20=20= =0A+--------+----------=0A+=20=20=20=20=20=201=20|=20prefix=0A+=20=20=20=20= =20=202=20|=20note=0A+=20=20=20=20=20=203=20|=20id=0A+=20=20=20=20=20=20= 4=20|=20valid_at=0A+=20=20=20=20=20=205=20|=20name=0A+(5=20rows)=0A+=0A= +INSERT=20INTO=20mi_child=20VALUES=0A+=20=20('pfx',=20'memo',=201,=20= daterange('2000-01-01',=20'2010-01-01'),=20'old');=0A+UPDATE=20= temporal_parent=20FOR=20PORTION=20OF=20valid_at=20FROM=20'2001-01-01'=20= TO=20'2002-01-01'=0A+=20=20SET=20name=20=3D=20'new'=0A+=20=20WHERE=20id=20= =3D=201;=0A+SELECT=20*=20FROM=20ONLY=20temporal_parent;=0A+=20id=20|=20= valid_at=20|=20name=20=0A+----+----------+------=0A+(0=20rows)=0A+=0A= +SELECT=20*=20FROM=20ONLY=20mi_child;=0A+=20prefix=20|=20note=20|=20id=20= |=20=20=20=20=20=20=20=20valid_at=20=20=20=20=20=20=20=20=20|=20name=20=0A= +--------+------+----+-------------------------+------=0A+=20pfx=20=20=20= =20|=20memo=20|=20=201=20|=20[2001-01-01,2002-01-01)=20|=20new=0A+=20pfx=20= =20=20=20|=20memo=20|=20=201=20|=20[2000-01-01,2001-01-01)=20|=20old=0A+=20= pfx=20=20=20=20|=20memo=20|=20=201=20|=20[2002-01-01,2010-01-01)=20|=20= old=0A+(3=20rows)=0A+=0A+TRUNCATE=20TABLE=20mi_child,=20other_parent,=20= temporal_parent;=0A+INSERT=20INTO=20mi_child=20VALUES=0A+=20=20('pfx',=20= 'memo',=201,=20daterange('2000-01-01',=20'2010-01-01'),=20'old');=0A= +DELETE=20FROM=20temporal_parent=20FOR=20PORTION=20OF=20valid_at=20FROM=20= '2001-01-01'=20TO=20'2002-01-01'=0A+=20=20WHERE=20id=20=3D=201;=0A= +SELECT=20*=20FROM=20ONLY=20temporal_parent;=0A+=20id=20|=20valid_at=20|=20= name=20=0A+----+----------+------=0A+(0=20rows)=0A+=0A+SELECT=20*=20FROM=20= ONLY=20mi_child;=0A+=20prefix=20|=20note=20|=20id=20|=20=20=20=20=20=20=20= =20valid_at=20=20=20=20=20=20=20=20=20|=20name=20=0A= +--------+------+----+-------------------------+------=0A+=20pfx=20=20=20= =20|=20memo=20|=20=201=20|=20[2000-01-01,2001-01-01)=20|=20old=0A+=20pfx=20= =20=20=20|=20memo=20|=20=201=20|=20[2002-01-01,2010-01-01)=20|=20old=0A= +(2=20rows)=0A+=0A+DROP=20TABLE=20mi_child,=20other_parent,=20= temporal_parent;=0A=20--=20UPDATE/DELETE=20FOR=20PORTION=20OF=20with=20= RULEs=0A=20CREATE=20TABLE=20fpo_rule=20(f1=20bigint,=20f2=20int4range);=0A= =20INSERT=20INTO=20fpo_rule=20VALUES=20(1,=20'[1,=2011)');=0Adiff=20= --git=20a/src/test/regress/sql/for_portion_of.sql=20= b/src/test/regress/sql/for_portion_of.sql=0Aindex=20= fd79a9b78e7..83a2bc9a82c=20100644=0A---=20= a/src/test/regress/sql/for_portion_of.sql=0A+++=20= b/src/test/regress/sql/for_portion_of.sql=0A@@=20-1365,6=20+1365,86=20@@=20= SELECT=20*=20FROM=20temporal_partitioned_5=20ORDER=20BY=20id,=20= valid_at;=0A=20=0A=20DROP=20TABLE=20temporal_partitioned;=0A=20=0A+--=20= UPDATE/DELETE=20FOR=20PORTION=20OF=20with=20inheritance=0A+CREATE=20= TABLE=20fpo_parent=20(=0A+=20=20id=20int,=0A+=20=20valid_at=20daterange,=0A= +=20=20name=20text=0A+);=0A+CREATE=20TABLE=20fpo_child=20(=0A+=20=20= extra=20text=0A+)=20INHERITS=20(fpo_parent);=0A+=0A+INSERT=20INTO=20= fpo_child=20VALUES=0A+=20=20(1,=20daterange('2000-01-01',=20= '2010-01-01'),=20'old',=20'x');=0A+=0A+UPDATE=20fpo_parent=20FOR=20= PORTION=20OF=20valid_at=20FROM=20'2001-01-01'=20TO=20'2002-01-01'=0A+=20=20= SET=20name=20=3D=20'new'=0A+=20=20WHERE=20id=20=3D=201;=0A+=0A+SELECT=20= *=20FROM=20ONLY=20fpo_parent;=0A+SELECT=20*=20FROM=20ONLY=20fpo_child;=0A= +=0A+TRUNCATE=20TABLE=20fpo_child,=20fpo_parent;=0A+=0A+INSERT=20INTO=20= fpo_child=20VALUES=0A+=20=20(1,=20daterange('2000-01-01',=20= '2010-01-01'),=20'old',=20'x');=0A+=0A+DELETE=20FROM=20fpo_parent=20FOR=20= PORTION=20OF=20valid_at=20FROM=20'2001-01-01'=20TO=20'2002-01-01'=0A+=20=20= WHERE=20id=20=3D=201;=0A+=0A+SELECT=20*=20FROM=20ONLY=20fpo_parent;=0A= +SELECT=20*=20FROM=20ONLY=20fpo_child;=0A+=0A+DROP=20TABLE=20fpo_child,=20= fpo_parent;=0A+=0A+--=20UPDATE/DELETE=20FOR=20PORTION=20OF=20with=20= inheritance=20and=20differing=20attnos=0A+CREATE=20TABLE=20= temporal_parent=20(=0A+=20=20id=20int,=0A+=20=20valid_at=20daterange,=0A= +=20=20name=20text=0A+);=0A+CREATE=20TABLE=20other_parent=20(=0A+=20=20= prefix=20text,=0A+=20=20note=20text=0A+);=0A+CREATE=20TABLE=20mi_child=20= ()=20INHERITS=20(other_parent,=20temporal_parent);=0A+=0A+--=20attnum=20= of=20the=20range=20column=20is=20different=20in=20temporal_parent=20and=20= mi_child=0A+SELECT=20attnum,=20attname=0A+=20=20FROM=20pg_attribute=0A+=20= =20WHERE=20attrelid=20=3D=20'temporal_parent'::regclass=0A+=20=20=20=20= AND=20attnum=20>=200=20AND=20NOT=20attisdropped=0A+=20=20ORDER=20BY=20= attnum;=0A+SELECT=20attnum,=20attname=0A+=20=20FROM=20pg_attribute=0A+=20= =20WHERE=20attrelid=20=3D=20'mi_child'::regclass=0A+=20=20=20=20AND=20= attnum=20>=200=20AND=20NOT=20attisdropped=0A+=20=20ORDER=20BY=20attnum;=0A= +=0A+INSERT=20INTO=20mi_child=20VALUES=0A+=20=20('pfx',=20'memo',=201,=20= daterange('2000-01-01',=20'2010-01-01'),=20'old');=0A+=0A+UPDATE=20= temporal_parent=20FOR=20PORTION=20OF=20valid_at=20FROM=20'2001-01-01'=20= TO=20'2002-01-01'=0A+=20=20SET=20name=20=3D=20'new'=0A+=20=20WHERE=20id=20= =3D=201;=0A+=0A+SELECT=20*=20FROM=20ONLY=20temporal_parent;=0A+SELECT=20= *=20FROM=20ONLY=20mi_child;=0A+=0A+TRUNCATE=20TABLE=20mi_child,=20= other_parent,=20temporal_parent;=0A+=0A+INSERT=20INTO=20mi_child=20= VALUES=0A+=20=20('pfx',=20'memo',=201,=20daterange('2000-01-01',=20= '2010-01-01'),=20'old');=0A+=0A+DELETE=20FROM=20temporal_parent=20FOR=20= PORTION=20OF=20valid_at=20FROM=20'2001-01-01'=20TO=20'2002-01-01'=0A+=20=20= WHERE=20id=20=3D=201;=0A+=0A+SELECT=20*=20FROM=20ONLY=20temporal_parent;=0A= +SELECT=20*=20FROM=20ONLY=20mi_child;=0A+=0A+DROP=20TABLE=20mi_child,=20= other_parent,=20temporal_parent;=0A+=0A=20--=20UPDATE/DELETE=20FOR=20= PORTION=20OF=20with=20RULEs=0A=20CREATE=20TABLE=20fpo_rule=20(f1=20= bigint,=20f2=20int4range);=0A=20INSERT=20INTO=20fpo_rule=20VALUES=20(1,=20= '[1,=2011)');=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_CFF5D747-860B-48D5-BFE7-16A0AF469020--