diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-14 22:18:02 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-07-14 22:18:02 +0000 |
| commit | 6bfe64032efd043f80a495a495331dcfc2d9f05c (patch) | |
| tree | d0cc092d38bdea690a79e4aebfa4629e1db54e96 /src/backend/catalog/indexing.c | |
| parent | a30bc7c75a54910a78d1939bd32f5d91164ba8a4 (diff) | |
| download | postgresql-6bfe64032efd043f80a495a495331dcfc2d9f05c.tar.gz | |
Cleanup of code for creating index entries. Functional indexes with
pass-by-ref data types --- eg, an index on lower(textfield) --- no longer
leak memory during index creation or update. Clean up a lot of redundant
code ... did you know that copy, vacuum, truncate, reindex, extend index,
and bootstrap each basically duplicated the main executor's logic for
extracting information about an index and preparing index entries?
Functional indexes should be a little faster now too, due to removal
of repeated function lookups.
CREATE INDEX 'opt_type' clause is deimplemented by these changes,
but I haven't removed it from the parser yet (need to merge with
Thomas' latest change set first).
Diffstat (limited to 'src/backend/catalog/indexing.c')
| -rw-r--r-- | src/backend/catalog/indexing.c | 80 |
1 files changed, 32 insertions, 48 deletions
diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c index deb016e4a0..c2980f6fef 100644 --- a/src/backend/catalog/indexing.c +++ b/src/backend/catalog/indexing.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.66 2000/06/17 04:56:39 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.67 2000/07/14 22:17:41 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -83,9 +83,9 @@ static HeapTuple CatalogIndexFetchTuple(Relation heapRelation, /* - * Changes (appends) to catalogs can (and does) happen at various places + * Changes (appends) to catalogs can and do happen at various places * throughout the code. We need a generic routine that will open all of - * the indices defined on a given catalog a return the relation descriptors + * the indices defined on a given catalog and return the relation descriptors * associated with them. */ void @@ -115,9 +115,20 @@ CatalogCloseIndices(int nIndices, Relation *idescs) /* - * For the same reasons outlined above CatalogOpenIndices() we need a routine - * that takes a new catalog tuple and inserts an associated index tuple into - * each catalog index. + * For the same reasons outlined above for CatalogOpenIndices(), we need a + * routine that takes a new catalog tuple and inserts an associated index + * tuple into each catalog index. + * + * NOTE: since this routine looks up all the pg_index data on each call, + * it's relatively inefficient for inserting a large number of tuples into + * the same catalog. We use it only for inserting one or a few tuples + * in a given command. See ExecOpenIndices() and related routines if you + * are inserting tuples in bulk. + * + * NOTE: we do not bother to handle partial indices. Nor do we try to + * be efficient for functional indices (the code should work for them, + * but may leak memory intraquery). This should be OK for system catalogs, + * but don't use this routine for user tables! */ void CatalogIndexInsert(Relation *idescs, @@ -125,15 +136,9 @@ CatalogIndexInsert(Relation *idescs, Relation heapRelation, HeapTuple heapTuple) { - HeapTuple index_tup; TupleDesc heapDescriptor; - Form_pg_index index_form; Datum datum[INDEX_MAX_KEYS]; - char nulls[INDEX_MAX_KEYS]; - int natts; - AttrNumber *attnumP; - FuncIndexInfo finfo, - *finfoP; + char nullv[INDEX_MAX_KEYS]; int i; if (IsIgnoringSystemIndexes()) @@ -142,51 +147,30 @@ CatalogIndexInsert(Relation *idescs, for (i = 0; i < nIndices; i++) { + HeapTuple index_tup; + IndexInfo *indexInfo; InsertIndexResult indexRes; - index_tup = SearchSysCacheTupleCopy(INDEXRELID, - ObjectIdGetDatum(idescs[i]->rd_id), - 0, 0, 0); - Assert(index_tup); - index_form = (Form_pg_index) GETSTRUCT(index_tup); - - if (index_form->indproc != InvalidOid) - { - int fatts; - - /* - * Compute the number of attributes we are indexing upon. - */ - for (attnumP = index_form->indkey, fatts = 0; - fatts < INDEX_MAX_KEYS && *attnumP != InvalidAttrNumber; - attnumP++, fatts++) - ; - FIgetnArgs(&finfo) = fatts; - natts = 1; - FIgetProcOid(&finfo) = index_form->indproc; - *(FIgetname(&finfo)) = '\0'; - finfoP = &finfo; - } - else - { - natts = RelationGetDescr(idescs[i])->natts; - finfoP = (FuncIndexInfo *) NULL; - } + index_tup = SearchSysCacheTuple(INDEXRELID, + ObjectIdGetDatum(idescs[i]->rd_id), + 0, 0, 0); + if (!HeapTupleIsValid(index_tup)) + elog(ERROR, "CatalogIndexInsert: index %u not found", + idescs[i]->rd_id); + indexInfo = BuildIndexInfo(index_tup); - FormIndexDatum(natts, - (AttrNumber *) index_form->indkey, + FormIndexDatum(indexInfo, heapTuple, heapDescriptor, + CurrentMemoryContext, datum, - nulls, - finfoP); + nullv); - indexRes = index_insert(idescs[i], datum, nulls, + indexRes = index_insert(idescs[i], datum, nullv, &heapTuple->t_self, heapRelation); if (indexRes) pfree(indexRes); - - heap_freetuple(index_tup); + pfree(indexInfo); } } |
