Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6666185

Browse files
committed
Use an indexscan not a heapscan to search pg_index in get_pkey_attnames.
Noted while looking for heapscans that might need to start from blockzero.
1 parentd3b1b1f commit6666185

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

‎contrib/dblink/dblink.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
*
@@ -38,8 +38,10 @@
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 **
16621664
get_pkey_attnames(Oidrelid,int16*numatts)
16631665
{
16641666
RelationindexRelation;
1665-
ScanKeyDataentry;
1666-
HeapScanDescscan;
1667+
ScanKeyDataskey;
1668+
SysScanDescscan;
16671669
HeapTupleindexTuple;
16681670
inti;
16691671
char**result=NULL;
16701672
Relationrel;
16711673
TupleDesctupdesc;
16721674
AclResultaclresult;
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 */
16751680
rel=relation_open(relid,AccessShareLock);
16761681

@@ -1682,23 +1687,22 @@ get_pkey_attnames(Oid relid, int16 *numatts)
16821687

16831688
tupdesc=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. */
16891691
indexRelation=heap_open(IndexRelationId,AccessShareLock);
1690-
ScanKeyInit(&entry,
1692+
ScanKeyInit(&skey,
16911693
Anum_pg_index_indrelid,
16921694
BTEqualStrategyNumber,F_OIDEQ,
16931695
ObjectIdGetDatum(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
{
16981702
Form_pg_indexindex= (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;
17041708
if (*numatts>0)
@@ -1711,7 +1715,8 @@ get_pkey_attnames(Oid relid, int16 *numatts)
17111715
break;
17121716
}
17131717
}
1714-
heap_endscan(scan);
1718+
1719+
systable_endscan(scan);
17151720
heap_close(indexRelation,AccessShareLock);
17161721
relation_close(rel,AccessShareLock);
17171722

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp