8
8
* Darko Prenosil <Darko.Prenosil@finteh.hr>
9
9
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
10
10
*
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 $
12
12
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
13
13
* ALL RIGHTS RESERVED;
14
14
*
38
38
#include "fmgr.h"
39
39
#include "funcapi.h"
40
40
#include "miscadmin.h"
41
+ #include "access/genam.h"
41
42
#include "access/heapam.h"
42
43
#include "access/tupdesc.h"
44
+ #include "catalog/indexing.h"
43
45
#include "catalog/namespace.h"
44
46
#include "catalog/pg_index.h"
45
47
#include "catalog/pg_type.h"
@@ -1662,15 +1664,18 @@ static char **
1662
1664
get_pkey_attnames (Oid relid , int16 * numatts )
1663
1665
{
1664
1666
Relation indexRelation ;
1665
- ScanKeyData entry ;
1666
- HeapScanDesc scan ;
1667
+ ScanKeyData skey ;
1668
+ SysScanDesc scan ;
1667
1669
HeapTuple indexTuple ;
1668
1670
int i ;
1669
1671
char * * result = NULL ;
1670
1672
Relation rel ;
1671
1673
TupleDesc tupdesc ;
1672
1674
AclResult aclresult ;
1673
1675
1676
+ /* initialize numatts to 0 in case no primary key exists */
1677
+ * numatts = 0 ;
1678
+
1674
1679
/* open relation using relid, check permissions, get tupdesc */
1675
1680
rel = relation_open (relid , AccessShareLock );
1676
1681
@@ -1682,23 +1687,22 @@ get_pkey_attnames(Oid relid, int16 *numatts)
1682
1687
1683
1688
tupdesc = rel -> rd_att ;
1684
1689
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. */
1689
1691
indexRelation = heap_open (IndexRelationId , AccessShareLock );
1690
- ScanKeyInit (& entry ,
1692
+ ScanKeyInit (& skey ,
1691
1693
Anum_pg_index_indrelid ,
1692
1694
BTEqualStrategyNumber , F_OIDEQ ,
1693
1695
ObjectIdGetDatum (relid ));
1694
- scan = heap_beginscan (indexRelation , SnapshotNow , 1 , & entry );
1695
1696
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 )))
1697
1701
{
1698
1702
Form_pg_index index = (Form_pg_index ) GETSTRUCT (indexTuple );
1699
1703
1700
1704
/* we're only interested if it is the primary key */
1701
- if (index -> indisprimary == TRUE )
1705
+ if (index -> indisprimary )
1702
1706
{
1703
1707
* numatts = index -> indnatts ;
1704
1708
if (* numatts > 0 )
@@ -1711,7 +1715,8 @@ get_pkey_attnames(Oid relid, int16 *numatts)
1711
1715
break ;
1712
1716
}
1713
1717
}
1714
- heap_endscan (scan );
1718
+
1719
+ systable_endscan (scan );
1715
1720
heap_close (indexRelation , AccessShareLock );
1716
1721
relation_close (rel , AccessShareLock );
1717
1722
0 commit comments