Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit edf0b5f

Browse files
committed
Get rid of IndexIsUniqueNoCache() kluge by the simple expedient of
passing the index-is-unique flag to index build routines (duh! ... why wasn't it done this way to begin with?). Aside from eliminating an eyesore, this should save a few milliseconds in btree index creation because a full scan of pg_index is not needed any more.
1 parent d03a933 commit edf0b5f

File tree

13 files changed

+89
-160
lines changed

13 files changed

+89
-160
lines changed

src/backend/access/gist/gist.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.58 2000/06/15 03:31:53 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.59 2000/06/17 23:41:12 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -67,13 +67,12 @@ gistbuild(PG_FUNCTION_ARGS)
6767
Relation index = (Relation) PG_GETARG_POINTER(1);
6868
int32 natts = PG_GETARG_INT32(2);
6969
AttrNumber *attnum = (AttrNumber *) PG_GETARG_POINTER(3);
70+
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(4);
71+
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(5);
7072
#ifdef NOT_USED
71-
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
72-
uint16 pcount = PG_GETARG_UINT16(5);
73-
Datum *params = (Datum *) PG_GETARG_POINTER(6);
73+
bool unique = PG_GETARG_BOOL(6);
74+
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(7);
7475
#endif
75-
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(7);
76-
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(8);
7776
HeapScanDesc scan;
7877
AttrNumber i;
7978
HeapTuple htup;

src/backend/access/hash/hash.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.39 2000/06/14 05:24:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.40 2000/06/17 23:41:13 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -43,13 +43,12 @@ hashbuild(PG_FUNCTION_ARGS)
4343
Relation index = (Relation) PG_GETARG_POINTER(1);
4444
int32 natts = PG_GETARG_INT32(2);
4545
AttrNumber *attnum = (AttrNumber *) PG_GETARG_POINTER(3);
46+
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(4);
47+
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(5);
4648
#ifdef NOT_USED
47-
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
48-
uint16 pcount = PG_GETARG_UINT16(5);
49-
Datum *params = (Datum *) PG_GETARG_POINTER(6);
49+
bool unique = PG_GETARG_BOOL(6);
50+
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(7);
5051
#endif
51-
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(7);
52-
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(8);
5352
HeapScanDesc hscan;
5453
HeapTuple htup;
5554
IndexTuple itup;

src/backend/access/nbtree/nbtree.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.58 2000/06/15 04:09:36 momjian Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.59 2000/06/17 23:41:16 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -47,13 +47,12 @@ btbuild(PG_FUNCTION_ARGS)
4747
Relation index = (Relation) PG_GETARG_POINTER(1);
4848
int32 natts = PG_GETARG_INT32(2);
4949
AttrNumber *attnum = (AttrNumber *) PG_GETARG_POINTER(3);
50+
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(4);
51+
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(5);
52+
bool unique = PG_GETARG_BOOL(6);
5053
#ifdef NOT_USED
51-
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
52-
uint16 pcount = PG_GETARG_UINT16(5);
53-
Datum *params = (Datum *) PG_GETARG_POINTER(6);
54+
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(7);
5455
#endif
55-
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(7);
56-
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(8);
5756
HeapScanDesc hscan;
5857
HeapTuple htup;
5958
IndexTuple itup;
@@ -76,7 +75,6 @@ btbuild(PG_FUNCTION_ARGS)
7675
Node *pred,
7776
*oldPred;
7877
BTSpool *spool = NULL;
79-
bool isunique;
8078
bool usefast;
8179

8280
/* note that this is a new btree */
@@ -98,9 +96,6 @@ btbuild(PG_FUNCTION_ARGS)
9896
ResetUsage();
9997
#endif /* BTREE_BUILD_STATS */
10098

101-
/* see if index is unique */
102-
isunique = IndexIsUniqueNoCache(RelationGetRelid(index));
103-
10499
/* initialize the btree index metadata page (if this is a new index) */
105100
if (oldPred == NULL)
106101
_bt_metapinit(index);
@@ -146,7 +141,7 @@ btbuild(PG_FUNCTION_ARGS)
146141

147142
if (usefast)
148143
{
149-
spool = _bt_spoolinit(index, isunique);
144+
spool = _bt_spoolinit(index, unique);
150145
res = (InsertIndexResult) NULL;
151146
}
152147

@@ -254,7 +249,7 @@ btbuild(PG_FUNCTION_ARGS)
254249
if (usefast)
255250
_bt_spool(btitem, spool);
256251
else
257-
res = _bt_doinsert(index, btitem, isunique, heap);
252+
res = _bt_doinsert(index, btitem, unique, heap);
258253

259254
pfree(btitem);
260255
pfree(itup);

src/backend/access/rtree/rtree.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.49 2000/06/14 05:24:43 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.50 2000/06/17 23:41:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -66,13 +66,12 @@ rtbuild(PG_FUNCTION_ARGS)
6666
Relation index = (Relation) PG_GETARG_POINTER(1);
6767
int32 natts = PG_GETARG_INT32(2);
6868
AttrNumber *attnum = (AttrNumber *) PG_GETARG_POINTER(3);
69+
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(4);
70+
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(5);
6971
#ifdef NOT_USED
70-
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
71-
uint16 pcount = PG_GETARG_UINT16(5);
72-
Datum *params = (Datum *) PG_GETARG_POINTER(6);
72+
bool unique = PG_GETARG_BOOL(6);
73+
IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(7);
7374
#endif
74-
FuncIndexInfo *finfo = (FuncIndexInfo *) PG_GETARG_POINTER(7);
75-
PredInfo *predInfo = (PredInfo *) PG_GETARG_POINTER(8);
7675
HeapScanDesc scan;
7776
AttrNumber i;
7877
HeapTuple htup;

src/backend/bootstrap/bootstrap.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.85 2000/06/05 07:28:40 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.86 2000/06/17 23:41:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -161,10 +161,9 @@ typedef struct _IndexList
161161
char *il_ind;
162162
int il_natts;
163163
AttrNumber *il_attnos;
164-
uint16 il_nparams;
165-
Datum *il_params;
166164
FuncIndexInfo *il_finfo;
167165
PredInfo *il_predInfo;
166+
bool il_unique;
168167
struct _IndexList *il_next;
169168
} IndexList;
170169

@@ -1071,12 +1070,10 @@ index_register(char *heap,
10711070
char *ind,
10721071
int natts,
10731072
AttrNumber *attnos,
1074-
uint16 nparams,
1075-
Datum *params,
10761073
FuncIndexInfo *finfo,
1077-
PredInfo *predInfo)
1074+
PredInfo *predInfo,
1075+
bool unique)
10781076
{
1079-
Datum *v;
10801077
IndexList *newind;
10811078
int len;
10821079
MemoryContext oldcxt;
@@ -1103,25 +1100,12 @@ index_register(char *heap,
11031100
len = natts * sizeof(AttrNumber);
11041101

11051102
newind->il_attnos = (AttrNumber *) palloc(len);
1106-
memmove(newind->il_attnos, attnos, len);
1103+
memcpy(newind->il_attnos, attnos, len);
11071104

1108-
if ((newind->il_nparams = nparams) > 0)
1109-
{
1110-
v = newind->il_params = (Datum *) palloc(2 * nparams * sizeof(Datum));
1111-
nparams *= 2;
1112-
while (nparams-- > 0)
1113-
{
1114-
*v = (Datum) palloc(strlen((char *) (*params)) + 1);
1115-
strcpy((char *) *v++, (char *) *params++);
1116-
}
1117-
}
1118-
else
1119-
newind->il_params = (Datum *) NULL;
1120-
1121-
if (finfo != (FuncIndexInfo *) NULL)
1105+
if (PointerIsValid(finfo))
11221106
{
11231107
newind->il_finfo = (FuncIndexInfo *) palloc(sizeof(FuncIndexInfo));
1124-
memmove(newind->il_finfo, finfo, sizeof(FuncIndexInfo));
1108+
memcpy(newind->il_finfo, finfo, sizeof(FuncIndexInfo));
11251109
}
11261110
else
11271111
newind->il_finfo = (FuncIndexInfo *) NULL;
@@ -1135,6 +1119,8 @@ index_register(char *heap,
11351119
else
11361120
newind->il_predInfo = NULL;
11371121

1122+
newind->il_unique = unique;
1123+
11381124
newind->il_next = ILHead;
11391125

11401126
ILHead = newind;
@@ -1155,8 +1141,8 @@ build_indices()
11551141
ind = index_openr(ILHead->il_ind);
11561142
Assert(ind);
11571143
index_build(heap, ind, ILHead->il_natts, ILHead->il_attnos,
1158-
ILHead->il_nparams, ILHead->il_params, ILHead->il_finfo,
1159-
ILHead->il_predInfo);
1144+
ILHead->il_finfo, ILHead->il_predInfo,
1145+
ILHead->il_unique);
11601146

11611147
/*
11621148
* In normal processing mode, index_build would close the heap and

src/backend/catalog/heap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.131 2000/06/15 03:32:01 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.132 2000/06/17 23:41:31 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1112,6 +1112,7 @@ RelationTruncateIndexes(Relation heapRelation)
11121112
AttrNumber *attributeNumberA;
11131113
FuncIndexInfo fInfo,
11141114
*funcInfo = NULL;
1115+
bool unique;
11151116
int i,
11161117
numberOfAttributes;
11171118
char *predString;
@@ -1134,6 +1135,7 @@ RelationTruncateIndexes(Relation heapRelation)
11341135
index = (Form_pg_index) GETSTRUCT(indexTuple);
11351136
indexId = index->indexrelid;
11361137
procId = index->indproc;
1138+
unique = index->indisunique;
11371139

11381140
for (i = 0; i < INDEX_MAX_KEYS; i++)
11391141
{
@@ -1201,7 +1203,7 @@ RelationTruncateIndexes(Relation heapRelation)
12011203
/* Initialize the index and rebuild */
12021204
InitIndexStrategy(numberOfAttributes, currentIndex, accessMethodId);
12031205
index_build(heapRelation, currentIndex, numberOfAttributes,
1204-
attributeNumberA, 0, NULL, funcInfo, predInfo);
1206+
attributeNumberA, funcInfo, predInfo, unique);
12051207

12061208
/*
12071209
* index_build will close both the heap and index relations (but

0 commit comments

Comments
 (0)