diff options
Diffstat (limited to 'src/backend/commands/vacuum.c')
-rw-r--r-- | src/backend/commands/vacuum.c | 87 |
1 files changed, 20 insertions, 67 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 1ee4e28f210..5eed27387a7 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.159 2000/05/29 17:40:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.160 2000/06/17 21:48:43 tgl Exp $ * *------------------------------------------------------------------------- @@ -72,7 +72,7 @@ static void update_relstats(Oid relid, int num_pages, int num_tuples, bool hasin static VacPage tid_reaped(ItemPointer itemptr, VacPageList vacpagelist); static void reap_page(VacPageList vacpagelist, VacPage vacpage); static void vpage_insert(VacPageList vacpagelist, VacPage vpnew); -static void get_indices(Oid relid, int *nindices, Relation **Irel); +static void get_indices(Relation relation, int *nindices, Relation **Irel); static void close_indices(int nindices, Relation *Irel); static void get_index_desc(Relation onerel, int nindices, Relation *Irel, IndDesc **Idesc); static void *vac_find_eq(void *bot, int nelem, int size, void *elm, @@ -416,7 +416,7 @@ vacuum_rel(Oid relid, bool analyze) /* Now open indices */ nindices = 0; Irel = (Relation *) NULL; - get_indices(vacrelstats->relid, &nindices, &Irel); + get_indices(onerel, &nindices, &Irel); if (!Irel) reindex = false; else if (!RelationGetForm(onerel)->relhasindex) @@ -2331,80 +2331,33 @@ CommonSpecialPortalIsOpen(void) return CommonSpecialPortalInUse; } + static void -get_indices(Oid relid, int *nindices, Relation **Irel) +get_indices(Relation relation, int *nindices, Relation **Irel) { - Relation pgindex; - Relation irel; - TupleDesc tupdesc; - HeapTuple tuple; - HeapScanDesc scan; - Datum d; - int i, - k; - bool n; - ScanKeyData key; - Oid *ioid; - - *nindices = i = 0; - - ioid = (Oid *) palloc(10 * sizeof(Oid)); - - /* prepare a heap scan on the pg_index relation */ - pgindex = heap_openr(IndexRelationName, AccessShareLock); - tupdesc = RelationGetDescr(pgindex); - - ScanKeyEntryInitialize(&key, 0x0, Anum_pg_index_indrelid, - F_OIDEQ, - ObjectIdGetDatum(relid)); - - scan = heap_beginscan(pgindex, false, SnapshotNow, 1, &key); - - while (HeapTupleIsValid(tuple = heap_getnext(scan, 0))) - { - d = heap_getattr(tuple, Anum_pg_index_indexrelid, - tupdesc, &n); - i++; - if (i % 10 == 0) - ioid = (Oid *) repalloc(ioid, (i + 10) * sizeof(Oid)); - ioid[i - 1] = DatumGetObjectId(d); - } + List *indexoidlist, + *indexoidscan; + int i; - heap_endscan(scan); - heap_close(pgindex, AccessShareLock); + indexoidlist = RelationGetIndexList(relation); - if (i == 0) - { /* No one index found */ - pfree(ioid); - return; - } + *nindices = length(indexoidlist); - if (Irel != (Relation **) NULL) - *Irel = (Relation *) palloc(i * sizeof(Relation)); + if (*nindices > 0) + *Irel = (Relation *) palloc(*nindices * sizeof(Relation)); + else + *Irel = NULL; - for (k = 0; i > 0;) + i = 0; + foreach(indexoidscan, indexoidlist) { - irel = index_open(ioid[--i]); - if (irel != (Relation) NULL) - { - if (Irel != (Relation **) NULL) - (*Irel)[k] = irel; - else - index_close(irel); - k++; - } - else - elog(NOTICE, "CAN'T OPEN INDEX %u - SKIP IT", ioid[i]); - } - *nindices = k; - pfree(ioid); + Oid indexoid = lfirsti(indexoidscan); - if (Irel != (Relation **) NULL && *nindices == 0) - { - pfree(*Irel); - *Irel = (Relation *) NULL; + (*Irel)[i] = index_open(indexoid); + i++; } + freeList(indexoidlist); } |