use indnkeyatts not indnatts in loops that read rd_indcollation - Mailing list pgsql-hackers

From jian he
Subject use indnkeyatts not indnatts in loops that read rd_indcollation
Date
Msg-id CACJufxGWVB6dwPaQz25eXm-sdcxOWNfbfTHUd5wG41-zDcG6OA@mail.gmail.com
Whole thread
Responses Re: use indnkeyatts not indnatts in loops that read rd_indcollation
List pgsql-hackers
Hi

While reivew
https://www.postgresql.org/message-id/CAGRkXqR7VXacmRP41UBaM5u4aseeCH5ECVmQgn_YS%3DL7%3DxdhTw%40mail.gmail.com
I accidentally made Claude discover this issue. (At that time, I was
asking Claude about a collation-related issue.)

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++)
```

Some index type does not support INCLUDE index, but to be
future-proof, if somewhere rd_indcollation related, loop should using
indnkeyatts.



--
jian
https://www.enterprisedb.com/

Attachment

pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: PSQL schema "describe" \dn is not escaping quotes
Next
From: David Geier
Date:
Subject: Re: [PATCH v1] Batch B-tree TIDs when building a bitmap