From 04abb54197860c8882390db9af9606d7a50fb41b Mon Sep 17 00:00:00 2001 From: "Vadim B. Mikheev" Date: Wed, 9 Sep 1998 03:42:52 +0000 Subject: [PATCH] Fix for indexing problem (?): heap tuple was pfree-d before CatalogIndexInsert()... --- src/backend/catalog/index.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index e56deb9066..fbf9f30172 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.61 1998/09/07 05:35:37 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.62 1998/09/09 03:42:52 vadim Exp $ * * * INTERFACE ROUTINES @@ -64,7 +64,8 @@ #define NTUPLES_PER_PAGE(natts) (BLCKSZ/((natts)*AVG_TUPLE_SIZE)) /* non-export function prototypes */ -static Oid RelationNameGetObjectId(char *relationName, Relation pg_class); +static Oid + RelationNameGetObjectId(char *relationName, Relation pg_class); static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName); static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo); static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation, @@ -72,11 +73,12 @@ static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation, int numatts, AttrNumber *attNums); static void ConstructIndexReldesc(Relation indexRelation, Oid amoid); -static Oid UpdateRelationRelation(Relation indexRelation); +static Oid UpdateRelationRelation(Relation indexRelation); static void InitializeAttributeOids(Relation indexRelation, int numatts, Oid indexoid); -static void AppendAttributeTuples(Relation indexRelation, int numatts); +static void + AppendAttributeTuples(Relation indexRelation, int numatts); static void UpdateIndexRelation(Oid indexoid, Oid heapoid, FuncIndexInfo *funcInfo, int natts, AttrNumber *attNums, Oid *classOids, Node *predicate, @@ -550,9 +552,11 @@ UpdateRelationRelation(Relation indexRelation) sizeof(*indexRelation->rd_rel), (char *) indexRelation->rd_rel); - /* - * The new tuple must have the same oid as the heap_create() we just - * did. + /* ---------------- + * the new tuple must have the same oid as the relcache entry for the + * index. sure would be embarassing to do this sort of thing in polite + * company. + * ---------------- */ tuple->t_oid = RelationGetRelid(indexRelation); heap_insert(pg_class, tuple); @@ -1074,7 +1078,7 @@ index_create(char *heapRelationName, /* ---------------- * add index to catalogs - * (INSERT pg_class tuple) + * (append RELATION tuple) * ---------------- */ indexoid = UpdateRelationRelation(indexRelation); @@ -1260,7 +1264,8 @@ FormIndexDatum(int numberOfAttributes, char *nullv, FuncIndexInfoPtr fInfo) { - AttrNumber attOff; + AttrNumber i; + int offset; bool isNull; /* ---------------- @@ -1270,16 +1275,18 @@ FormIndexDatum(int numberOfAttributes, * ---------------- */ - for (attOff = 0; attOff < numberOfAttributes; attOff++) + for (i = 1; i <= numberOfAttributes; i++) { - datum[attOff] = PointerGetDatum(GetIndexValue(heapTuple, + offset = AttrNumberGetAttrOffset(i); + + datum[offset] = PointerGetDatum(GetIndexValue(heapTuple, heapDescriptor, - attOff, + offset, attributeNumber, fInfo, &isNull)); - nullv[attOff] = (isNull) ? 'n' : ' '; + nullv[offset] = (isNull) ? 'n' : ' '; } } @@ -1417,10 +1424,10 @@ UpdateStats(Oid relid, long reltuples, bool hasindex) newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace); heap_replace(pg_class, &tuple->t_ctid, newtup); - pfree(newtup); CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, newtup); CatalogCloseIndices(Num_pg_class_indices, idescs); + pfree(newtup); } if (!IsBootstrapProcessingMode()) -- 2.11.0