@@ -175,14 +175,15 @@ BuildIndexValueDescription(Relation indexRelation,
175175StringInfoData buf ;
176176Form_pg_index idxrec ;
177177HeapTuple ht_idx ;
178- int natts = indexRelation -> rd_rel -> relnatts ;
179- int nkeyatts ;
178+ int indnkeyatts ;
180179int i ;
181180int keyno ;
182181Oid indexrelid = RelationGetRelid (indexRelation );
183182Oid indrelid ;
184183AclResult aclresult ;
185184
185+ indnkeyatts = IndexRelationGetNumberOfKeyAttributes (indexRelation );
186+
186187/*
187188 * Check permissions- if the user does not have access to view all of the
188189 * key columns then return NULL to avoid leaking data.
@@ -220,7 +221,7 @@ BuildIndexValueDescription(Relation indexRelation,
220221 * No table-level access, so step through the columns in the index and
221222 * make sure the user has SELECT rights on all of them.
222223 */
223- for (keyno = 0 ;keyno < idxrec -> indnatts ;keyno ++ )
224+ for (keyno = 0 ;keyno < idxrec -> indnkeyatts ;keyno ++ )
224225{
225226AttrNumber attnum = idxrec -> indkey .values [keyno ];
226227
@@ -246,8 +247,7 @@ BuildIndexValueDescription(Relation indexRelation,
246247appendStringInfo (& buf ,"(%s)=(" ,
247248pg_get_indexdef_columns (indexrelid , true));
248249
249- nkeyatts = IndexRelationGetNumberOfKeyAttributes (indexRelation );
250- for (i = 0 ;i < natts ;i ++ )
250+ for (i = 0 ;i < indnkeyatts ;i ++ )
251251{
252252char * val ;
253253
@@ -257,38 +257,25 @@ BuildIndexValueDescription(Relation indexRelation,
257257{
258258Oid foutoid ;
259259bool typisvarlena ;
260- TupleDesc tupdesc = RelationGetDescr (indexRelation );
261260/*
262- * For key attributes the provided data is not necessarily of the
263- * type stored in the index; rather it is of the index opclass's
264- * input type. So look at rd_opcintype not the index tupdesc.
265- *
266- * Note: this is a bit shaky for opclasses that have pseudotype
267- * input types such as ANYARRAY or RECORD. Currently, the
268- * typoutput functions associated with the pseudotypes will work
269- * okay, but we might have to try harder in future.
270- *
271- * For included attributes just use info stored in the index
272- * tupdesc.
273- */
274- if (i < nkeyatts )
275- {
276- getTypeOutputInfo (indexRelation -> rd_opcintype [i ],
277- & foutoid ,& typisvarlena );
278- val = OidOutputFunctionCall (foutoid ,values [i ]);
279- }
280- else
281- {
282- getTypeOutputInfo (tupdesc -> attrs [i ]-> atttypid ,& foutoid ,& typisvarlena );
283- val = OidOutputFunctionCall (foutoid ,values [i ]);
284- }
261+ * The provided data is not necessarily of the type stored in the
262+ * index; rather it is of the index opclass's input type. So look
263+ * at rd_opcintype not the index tupdesc.
264+ *
265+ * Note: this is a bit shaky for opclasses that have pseudotype
266+ * input types such as ANYARRAY or RECORD. Currently, the
267+ * typoutput functions associated with the pseudotypes will work
268+ * okay, but we might have to try harder in future.
269+ */
270+ getTypeOutputInfo (indexRelation -> rd_opcintype [i ],
271+ & foutoid ,& typisvarlena );
272+ val = OidOutputFunctionCall (foutoid ,values [i ]);
285273}
286274
287275if (i > 0 )
288276appendStringInfoString (& buf ,", " );
289277appendStringInfoString (& buf ,val );
290278}
291-
292279appendStringInfoChar (& buf ,')' );
293280
294281return buf .data ;
@@ -376,15 +363,15 @@ systable_beginscan(Relation heapRelation,
376363{
377364int j ;
378365
379- for (j = 0 ;j < irel -> rd_index -> indnatts ;j ++ )
366+ for (j = 0 ;j < IndexRelationGetNumberOfAttributes ( irel ) ;j ++ )
380367{
381368if (key [i ].sk_attno == irel -> rd_index -> indkey .values [j ])
382369{
383370key [i ].sk_attno = j + 1 ;
384371break ;
385372}
386373}
387- if (j == irel -> rd_index -> indnatts )
374+ if (j == IndexRelationGetNumberOfAttributes ( irel ) )
388375elog (ERROR ,"column is not in index" );
389376}
390377
@@ -578,15 +565,15 @@ systable_beginscan_ordered(Relation heapRelation,
578565{
579566int j ;
580567
581- for (j = 0 ;j < indexRelation -> rd_index -> indnatts ;j ++ )
568+ for (j = 0 ;j < IndexRelationGetNumberOfAttributes ( indexRelation ) ;j ++ )
582569{
583570if (key [i ].sk_attno == indexRelation -> rd_index -> indkey .values [j ])
584571{
585572key [i ].sk_attno = j + 1 ;
586573break ;
587574}
588575}
589- if (j == indexRelation -> rd_index -> indnatts )
576+ if (j == IndexRelationGetNumberOfAttributes ( indexRelation ) )
590577elog (ERROR ,"column is not in index" );
591578}
592579