Re: use indnkeyatts not indnatts in loops that read rd_indcollation

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: use indnkeyatts not indnatts in loops that read rd_indcollation
Date: 2026-11-25 17:51:56
Message-ID: awcfebBV2WrnKzqR@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2026-Oct-09, Matthias van de Meent wrote:

> On Fri, 9 Oct 2026 at 10:41, jian he <jian(dot)universality(at)gmail(dot)com> wrote:

> > In RelationInitIndexAccessInfo, we have
> > ```
> > relation->rd_indcollation = (Oid *)
> > MemoryContextAllocZero(indexcxt, indnkeyatts * sizeof(Oid));
> > ```
> > rd_indcollation is corresponds to indnkeyatts, *not* indnatts.
> > Therefore any rd_indcollation related places loop using indnatts if
> > is there is wrong.
> > For example, below infer_collation_opclass_match is wrong.
> > ```
> > for (natt = 1; natt <= idxRel->rd_att->natts; natt++)
> > ```

AFAICT this is correct. I have pushed this change to all branches.

> I think the changes to BRIN are meaningless churn; it can never
> support INCLUDE columns.
>
> GIN could eventually support amgettuple again (which was removed way
> back when the pending list was introduced, with ff301d6e690b), and
> with even more effort and community goodwill might eventually get
> INCLUDE support, so changing its code is not the worst choice, but
> feels a lot like it's just churn to get it in line with other AMs.

Right. Bloom does not support include columns either. I left out all
the AMs in the patch. Adding INCLUDE column support for any of those
AMs wouldn't be patch-free, so adding one more line to change is not
really a huge issue; and TBH I find it hard to believe that we would
fail to notice.

Thanks

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Through AI, we have democratized bureaucracy. It's Kafka-as-a-service."
("The world has moved on", Cory Doctorow)
https://pluralistic.net/2026/06/11/lapsarianism/#nostalgia-is-a-toxic-impulse

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-11-25 17:52:50 Re: Fix OOM when rendering large geometry arrays
Previous Message Ayush Tiwari 2026-11-25 17:47:33 Re: pg_rewind: Fix buffer size passed when building WAL file name