88 * Darko Prenosil <Darko.Prenosil@finteh.hr>
99 * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
1010 *
11- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.68 2008/01/03 21:27:59 tgl Exp $
11+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.69 2008/01/14 02:49:47 tgl Exp $
1212 * Copyright (c) 2001-2008, PostgreSQL Global Development Group
1313 * ALL RIGHTS RESERVED;
1414 *
3838#include "fmgr.h"
3939#include "funcapi.h"
4040#include "miscadmin.h"
41+ #include "access/genam.h"
4142#include "access/heapam.h"
4243#include "access/tupdesc.h"
44+ #include "catalog/indexing.h"
4345#include "catalog/namespace.h"
4446#include "catalog/pg_index.h"
4547#include "catalog/pg_type.h"
@@ -1662,15 +1664,18 @@ static char **
16621664get_pkey_attnames (Oid relid ,int16 * numatts )
16631665{
16641666Relation indexRelation ;
1665- ScanKeyData entry ;
1666- HeapScanDesc scan ;
1667+ ScanKeyData skey ;
1668+ SysScanDesc scan ;
16671669HeapTuple indexTuple ;
16681670int i ;
16691671char * * result = NULL ;
16701672Relation rel ;
16711673TupleDesc tupdesc ;
16721674AclResult aclresult ;
16731675
1676+ /* initialize numatts to 0 in case no primary key exists */
1677+ * numatts = 0 ;
1678+
16741679/* open relation using relid, check permissions, get tupdesc */
16751680rel = relation_open (relid ,AccessShareLock );
16761681
@@ -1682,23 +1687,22 @@ get_pkey_attnames(Oid relid, int16 *numatts)
16821687
16831688tupdesc = rel -> rd_att ;
16841689
1685- /* initialize numatts to 0 in case no primary key exists */
1686- * numatts = 0 ;
1687-
1688- /* use relid to get all related indexes */
1690+ /* Prepare to scan pg_index for entries having indrelid = this rel. */
16891691indexRelation = heap_open (IndexRelationId ,AccessShareLock );
1690- ScanKeyInit (& entry ,
1692+ ScanKeyInit (& skey ,
16911693Anum_pg_index_indrelid ,
16921694BTEqualStrategyNumber ,F_OIDEQ ,
16931695ObjectIdGetDatum (relid ));
1694- scan = heap_beginscan (indexRelation ,SnapshotNow ,1 ,& entry );
16951696
1696- while ((indexTuple = heap_getnext (scan ,ForwardScanDirection ))!= NULL )
1697+ scan = systable_beginscan (indexRelation ,IndexIndrelidIndexId , true,
1698+ SnapshotNow ,1 ,& skey );
1699+
1700+ while (HeapTupleIsValid (indexTuple = systable_getnext (scan )))
16971701{
16981702Form_pg_index index = (Form_pg_index )GETSTRUCT (indexTuple );
16991703
17001704/* we're only interested if it is the primary key */
1701- if (index -> indisprimary == TRUE )
1705+ if (index -> indisprimary )
17021706{
17031707* numatts = index -> indnatts ;
17041708if (* numatts > 0 )
@@ -1711,7 +1715,8 @@ get_pkey_attnames(Oid relid, int16 *numatts)
17111715break ;
17121716}
17131717}
1714- heap_endscan (scan );
1718+
1719+ systable_endscan (scan );
17151720heap_close (indexRelation ,AccessShareLock );
17161721relation_close (rel ,AccessShareLock );
17171722