Re: BUG #17877: Referencing a system column in a foreign key leads to incorrect memory access

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: Re: BUG #17877: Referencing a system column in a foreign key leads to incorrect memory access
Date: 2023-04-01 13:56:08
Message-ID: CAEudQAq=q1xGR+Ju4L=ss+dv2-+PsPSqQbLuGUBKrOpKfxOz9g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em sex., 31 de mar. de 2023 às 16:25, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> escreveu:

> Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> writes:
> > I think that commit f0d65c0
> > <
> https://github.com/postgres/postgres/commit/f0d65c0eaf05d6acd3ae05cde4a31465eb3992b2
> >
> > has an oversight.
> > Attnum == 0, is system column too, right?
>
> No, it's not valid in pg_attribute rows.
>
> > All other places at tablecmds.c, has this test:
> > if (attnum <= 0)
> > ereport(ERROR,
>
> I was actually copying this code in indexcmds.c:
>
> if (attno < 0)
> ereport(ERROR,
> (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
> errmsg("index creation on system columns is not
> supported")));
>
> There's really no reason to prefer one over the other in this context.
>
I think the documentation is a bit confusing.
According to the current documentation:
/*
* attnum is the "attribute number" for the attribute: A value that
* uniquely identifies this attribute within its class. for user
* attributes, Attribute numbers are greater than 0 and not greater than
* the number of attributes in the class. i.e. if the Class pg_class says
* that Class XYZ has 10 attributes, then the user attribute numbers in
* Class pg_attribute must be 1-10.
*
* System attributes have attribute numbers less than 0 that are unique
* within the class, but not constrained to any particular range.
*
* Note that (attnum - 1) is often used as the index to an array.
Attributes equal to zero are in limbo.

IMO should be:
* System attributes have attribute numbers less or equal to 0 that are
* unique
* within the class, but not constrained to any particular range.

regards,
Ranier Vilela

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Lakhin 2023-04-01 16:00:00 Re: Non-superuser subscription owners
Previous Message Justin Pryzby 2023-04-01 13:36:44 Re: zstd compression for pg_dump