On Fri, Jan 6, 2023 at 12:28 AM Tom Lane <t...@sss.pgh.pa.us> wrote: > Amit Langote <amitlangot...@gmail.com> writes: > > On Thu, Jan 5, 2023 at 4:59 AM Tom Lane <t...@sss.pgh.pa.us> wrote: > >> I've not looked into what it'd take to back-patch this. We can't > >> add a field to ResultRelInfo in released branches (cf 4b3e37993), > >> but we might be able to repurpose RangeTblEntry.extraUpdatedCols. > > > I think we can make that work. Would you like me to give that a try? > > I'm on it already.
Thanks. What you committed seems fine to me. > AFAICT, the above won't actually work because > we don't have RTEs for all ResultRelInfos (per the > "relinfo->ri_RangeTableIndex != 0" test in ExecGetExtraUpdatedCols). Yeah, I noticed that too. I was thinking that that wouldn't be a problem, because it is only partitions that are execution-time routing targets that don't have their own RTEs and using a translated copy of the root parent's RTE's extraUpdatedCols for them as before isn't wrong. Note that partitions can't have generated columns that are not present in its parent. BTW, you wrote in the commit message: However, there's nothing that says a traditional-inheritance child can't have generated columns that aren't there in its parent, or that have different dependencies than are in the parent's expression. (At present it seems that we don't enforce that for partitioning either, which is likely wrong to some degree or other; but the case clearly needs to be handled with traditional inheritance.) Maybe I'm missing something, but AFICS, neither traditional-inheritance child tables nor partitions allow a generated column with an expression that is not the same as the parent's expression for the same generated column: -- traditional inheritance create table inhp (a int, b int generated always as (a+1) stored); create table inhc (b int generated always as (a+2) stored) inherits (inhp); NOTICE: moving and merging column "b" with inherited definition DETAIL: User-specified column moved to the position of the inherited column. ERROR: child column "b" specifies generation expression HINT: Omit the generation expression in the definition of the child table column to inherit the generation expression from the parent table. create table inhc (a int, b int); alter table inhc inherit inhp; ERROR: column "b" in child table must be a generated column alter table inhc drop b, add b int generated always as (a+2) stored; alter table inhc inherit inhp; ERROR: column "b" in child table has a conflicting generation expression -- partitioning create table partp (a int, b int generated always as (a+1) stored) partition by list (a); create table partc partition of partp (b generated always as (a+2) stored) for values in (1); ERROR: generated columns are not supported on partitions create table partc (a int, b int); alter table partp attach partition partc for values in (1); ERROR: column "b" in child table must be a generated column alter table partc drop b, add b int generated always as (a+2) stored; alter table partp attach partition partc for values in (1); ERROR: column "b" in child table has a conflicting generation expression -- Thanks, Amit Langote EDB: http://www.enterprisedb.com