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/commands/cluster.c | |
parent | a30bc7c75a54910a78d1939bd32f5d91164ba8a4 (diff) | |
download | postgresql-6bfe64032efd043f80a495a495331dcfc2d9f05c.tar.gz postgresql-6bfe64032efd043f80a495a495331dcfc2d9f05c.zip |
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/commands/cluster.c')
-rw-r--r-- | src/backend/commands/cluster.c | 66 |
1 files changed, 12 insertions, 54 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 38539707cd8..5c176254d66 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.57 2000/07/04 06:11:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.58 2000/07/14 22:17:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -198,35 +198,31 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap) Relation OldIndex, NewHeap; HeapTuple Old_pg_index_Tuple, - Old_pg_index_relation_Tuple, - pg_proc_Tuple; + Old_pg_index_relation_Tuple; Form_pg_index Old_pg_index_Form; Form_pg_class Old_pg_index_relation_Form; - Form_pg_proc pg_proc_Form; + IndexInfo *indexInfo; char *NewIndexName; - AttrNumber *attnumP; - int natts; - FuncIndexInfo *finfo; NewHeap = heap_open(OIDNewHeap, AccessExclusiveLock); OldIndex = index_open(OIDOldIndex); /* * OK. Create a new (temporary) index for the one that's already here. - * To do this I get the info from pg_index, re-build the FunctInfo if - * I have to, and add a new index with a temporary name. + * To do this I get the info from pg_index, and add a new index with + * a temporary name. */ - Old_pg_index_Tuple = SearchSysCacheTuple(INDEXRELID, + Old_pg_index_Tuple = SearchSysCacheTupleCopy(INDEXRELID, ObjectIdGetDatum(RelationGetRelid(OldIndex)), - 0, 0, 0); - + 0, 0, 0); Assert(Old_pg_index_Tuple); Old_pg_index_Form = (Form_pg_index) GETSTRUCT(Old_pg_index_Tuple); - Old_pg_index_relation_Tuple = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(RelationGetRelid(OldIndex)), - 0, 0, 0); + indexInfo = BuildIndexInfo(Old_pg_index_Tuple); + Old_pg_index_relation_Tuple = SearchSysCacheTupleCopy(RELOID, + ObjectIdGetDatum(RelationGetRelid(OldIndex)), + 0, 0, 0); Assert(Old_pg_index_relation_Tuple); Old_pg_index_relation_Form = (Form_pg_class) GETSTRUCT(Old_pg_index_relation_Tuple); @@ -234,50 +230,12 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap) NewIndexName = palloc(NAMEDATALEN); /* XXX */ snprintf(NewIndexName, NAMEDATALEN, "temp_%x", OIDOldIndex); - /* - * Ugly as it is, the only way I have of working out the number of - * attribues is to count them. Mostly there'll be just one but I've - * got to be sure. - */ - for (attnumP = &(Old_pg_index_Form->indkey[0]), natts = 0; - natts < INDEX_MAX_KEYS && *attnumP != InvalidAttrNumber; - attnumP++, natts++); - - /* - * If this is a functional index, I need to rebuild the functional - * component to pass it to the defining procedure. - */ - if (Old_pg_index_Form->indproc != InvalidOid) - { - finfo = (FuncIndexInfo *) palloc(sizeof(FuncIndexInfo)); - FIgetnArgs(finfo) = natts; - FIgetProcOid(finfo) = Old_pg_index_Form->indproc; - - pg_proc_Tuple = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(Old_pg_index_Form->indproc), - 0, 0, 0); - - Assert(pg_proc_Tuple); - pg_proc_Form = (Form_pg_proc) GETSTRUCT(pg_proc_Tuple); - namecpy(&(finfo->funcName), &(pg_proc_Form->proname)); - natts = 1; /* function result is a single column */ - } - else - { - finfo = (FuncIndexInfo *) NULL; - } - index_create(RelationGetRelationName(NewHeap), NewIndexName, - finfo, - NULL, /* type info is in the old index */ + indexInfo, Old_pg_index_relation_Form->relam, - natts, - Old_pg_index_Form->indkey, Old_pg_index_Form->indclass, - (Node *) NULL, /* XXX where's the predicate? */ Old_pg_index_Form->indislossy, - Old_pg_index_Form->indisunique, Old_pg_index_Form->indisprimary, allowSystemTableMods); |