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

Commit 04abb54

Browse files
committed
Fix for indexing problem (?): heap tuple was pfree-d before CatalogIndexInsert()...
1 parent b5ed4be commit 04abb54

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/backend/catalog/index.c

+21-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.61 1998/09/07 05:35:37 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.62 1998/09/09 03:42:52 vadim Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -64,19 +64,21 @@
6464
#define NTUPLES_PER_PAGE(natts) (BLCKSZ/((natts)*AVG_TUPLE_SIZE))
6565

6666
/* non-export function prototypes */
67-
static Oid RelationNameGetObjectId(char *relationName, Relation pg_class);
67+
static Oid
68+
RelationNameGetObjectId(char *relationName, Relation pg_class);
6869
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName);
6970
static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo);
7071
static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation,
7172
List *attributeList,
7273
int numatts, AttrNumber *attNums);
7374

7475
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
75-
static Oid UpdateRelationRelation(Relation indexRelation);
76+
static Oid UpdateRelationRelation(Relation indexRelation);
7677
static void InitializeAttributeOids(Relation indexRelation,
7778
int numatts,
7879
Oid indexoid);
79-
static void AppendAttributeTuples(Relation indexRelation, int numatts);
80+
static void
81+
AppendAttributeTuples(Relation indexRelation, int numatts);
8082
static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
8183
FuncIndexInfo *funcInfo, int natts,
8284
AttrNumber *attNums, Oid *classOids, Node *predicate,
@@ -550,9 +552,11 @@ UpdateRelationRelation(Relation indexRelation)
550552
sizeof(*indexRelation->rd_rel),
551553
(char *) indexRelation->rd_rel);
552554

553-
/*
554-
* The new tuple must have the same oid as the heap_create() we just
555-
* did.
555+
/* ----------------
556+
* the new tuple must have the same oid as the relcache entry for the
557+
* index. sure would be embarassing to do this sort of thing in polite
558+
* company.
559+
* ----------------
556560
*/
557561
tuple->t_oid = RelationGetRelid(indexRelation);
558562
heap_insert(pg_class, tuple);
@@ -1074,7 +1078,7 @@ index_create(char *heapRelationName,
10741078

10751079
/* ----------------
10761080
* add index to catalogs
1077-
* (INSERT pg_class tuple)
1081+
* (append RELATION tuple)
10781082
* ----------------
10791083
*/
10801084
indexoid = UpdateRelationRelation(indexRelation);
@@ -1260,7 +1264,8 @@ FormIndexDatum(int numberOfAttributes,
12601264
char *nullv,
12611265
FuncIndexInfoPtr fInfo)
12621266
{
1263-
AttrNumber attOff;
1267+
AttrNumber i;
1268+
int offset;
12641269
bool isNull;
12651270

12661271
/* ----------------
@@ -1270,16 +1275,18 @@ FormIndexDatum(int numberOfAttributes,
12701275
* ----------------
12711276
*/
12721277

1273-
for (attOff = 0; attOff < numberOfAttributes; attOff++)
1278+
for (i = 1; i <= numberOfAttributes; i++)
12741279
{
1275-
datum[attOff] = PointerGetDatum(GetIndexValue(heapTuple,
1280+
offset = AttrNumberGetAttrOffset(i);
1281+
1282+
datum[offset] = PointerGetDatum(GetIndexValue(heapTuple,
12761283
heapDescriptor,
1277-
attOff,
1284+
offset,
12781285
attributeNumber,
12791286
fInfo,
12801287
&isNull));
12811288

1282-
nullv[attOff] = (isNull) ? 'n' : ' ';
1289+
nullv[offset] = (isNull) ? 'n' : ' ';
12831290
}
12841291
}
12851292

@@ -1417,10 +1424,10 @@ UpdateStats(Oid relid, long reltuples, bool hasindex)
14171424

14181425
newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace);
14191426
heap_replace(pg_class, &tuple->t_ctid, newtup);
1420-
pfree(newtup);
14211427
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
14221428
CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, newtup);
14231429
CatalogCloseIndices(Num_pg_class_indices, idescs);
1430+
pfree(newtup);
14241431
}
14251432

14261433
if (!IsBootstrapProcessingMode())

0 commit comments

Comments
 (0)