diff options
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/commands/analyze.c | 43 | ||||
| -rw-r--r-- | src/backend/utils/cache/relcache.c | 134 | ||||
| -rw-r--r-- | src/backend/utils/init/postinit.c | 8 |
3 files changed, 129 insertions, 56 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index c584d97220..757003f811 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.3 2000/07/05 23:11:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.4 2000/08/06 04:40:08 tgl Exp $ * *------------------------------------------------------------------------- @@ -106,7 +106,7 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL) elog(NOTICE, "Skipping \"%s\" --- only table owner can VACUUM it", RelationGetRelationName(onerel)); */ - heap_close(onerel, AccessExclusiveLock); + heap_close(onerel, NoLock); CommitTransactionCommand(); return; } @@ -220,7 +220,8 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL) heap_endscan(scan); - heap_close(onerel, AccessShareLock); + /* close rel, but keep lock so it doesn't go away before commit */ + heap_close(onerel, NoLock); /* update statistics in pg_class */ update_attstats(relid, attr_cnt, vacattrstats); @@ -388,8 +389,8 @@ bucketcpy(Form_pg_attribute attr, Datum value, Datum *bucket, int *bucket_len) /* * update_attstats() -- update attribute statistics for one relation * - * Updates of pg_attribute statistics are handled by over-write. - * for reasons described above. + * Updates of pg_attribute statistics are handled by over-write, + * for reasons described above. pg_statistic rows are added normally. * * To keep things simple, we punt for pg_statistic, and don't try * to compute or store rows for pg_statistic itself in pg_statistic. @@ -510,7 +511,7 @@ update_attstats(Oid relid, int natts, VacAttrStats *vacattrstats) * deleted all the pg_statistic tuples for the rel, so we * just have to insert new ones here. * - * Note vacuum_rel() has seen to it that we won't come here + * Note analyze_rel() has seen to it that we won't come here * when vacuuming pg_statistic itself. */ if (VacAttrStatsLtGtValid(stats) && stats->initialized) @@ -524,6 +525,7 @@ update_attstats(Oid relid, int natts, VacAttrStats *vacattrstats) nonnull_cnt_d = stats->nonnull_cnt; /* prevent overflow */ Datum values[Natts_pg_statistic]; char nulls[Natts_pg_statistic]; + Relation irelations[Num_pg_statistic_indices]; nullratio = null_cnt_d / (nonnull_cnt_d + null_cnt_d); bestratio = best_cnt_d / (nonnull_cnt_d + null_cnt_d); @@ -567,31 +569,12 @@ update_attstats(Oid relid, int natts, VacAttrStats *vacattrstats) stup = heap_formtuple(sd->rd_att, values, nulls); - /* ---------------- - * Watch out for oversize tuple, which can happen if - * all three of the saved data values are long. - * Our fallback strategy is just to not store the - * pg_statistic tuple at all in that case. (We could - * replace the values by NULLs and still store the - * numeric stats, but presently selfuncs.c couldn't - * do anything useful with that case anyway.) - * - * We could reduce the probability of overflow, but not - * prevent it, by storing the data values as compressed - * text; is that worth doing? The problem should go - * away whenever long tuples get implemented... - * ---------------- - */ - if (MAXALIGN(stup->t_len) <= MaxTupleSize) - { - /* OK, store tuple and update indexes too */ - Relation irelations[Num_pg_statistic_indices]; + /* store tuple and update indexes too */ + heap_insert(sd, stup); - heap_insert(sd, stup); - CatalogOpenIndices(Num_pg_statistic_indices, Name_pg_statistic_indices, irelations); - CatalogIndexInsert(irelations, Num_pg_statistic_indices, sd, stup); - CatalogCloseIndices(Num_pg_statistic_indices, irelations); - } + CatalogOpenIndices(Num_pg_statistic_indices, Name_pg_statistic_indices, irelations); + CatalogIndexInsert(irelations, Num_pg_statistic_indices, sd, stup); + CatalogCloseIndices(Num_pg_statistic_indices, irelations); /* release allocated space */ pfree(DatumGetPointer(values[Anum_pg_statistic_stacommonval - 1])); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 84f20757d6..59758adb62 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,13 +8,14 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.108 2000/07/30 22:13:55 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.109 2000/08/06 04:39:03 tgl Exp $ * *------------------------------------------------------------------------- */ /* * INTERFACE ROUTINES - * RelationInitialize - initialize relcache + * RelationCacheInitialize - initialize relcache + * RelationCacheInitializePhase2 - finish initializing relcache * RelationIdCacheGetRelation - get a reldesc from the cache (id) * RelationNameCacheGetRelation - get a reldesc from the cache (name) * RelationIdGetRelation - get a reldesc by relation id @@ -217,6 +218,7 @@ static void write_irels(void); static void formrdesc(char *relationName, int natts, FormData_pg_attribute *att); +static void fixrdesc(char *relationName); static HeapTuple ScanPgRelation(RelationBuildDescInfo buildinfo); static HeapTuple scan_pg_rel_seq(RelationBuildDescInfo buildinfo); @@ -1081,8 +1083,9 @@ IndexedAccessMethodInitialize(Relation relation) * formrdesc * * This is a special cut-down version of RelationBuildDesc() - * used by RelationInitialize() in initializing the relcache. - * The relation descriptor is built just from the supplied parameters. + * used by RelationCacheInitialize() in initializing the relcache. + * The relation descriptor is built just from the supplied parameters, + * without actually looking at any system table entries. * * NOTE: we assume we are already switched into CacheMemoryContext. * -------------------------------- @@ -1115,18 +1118,23 @@ formrdesc(char *relationName, RelationSetReferenceCount(relation, 1); /* ---------------- - * initialize relation tuple form + * all entries built with this routine are nailed-in-cache * ---------------- */ - relation->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE); - MemSet(relation->rd_rel, 0, CLASS_TUPLE_SIZE); - strcpy(RelationGetPhysicalRelationName(relation), relationName); + relation->rd_isnailed = true; /* ---------------- - * initialize attribute tuple form + * initialize relation tuple form + * + * The data we insert here is pretty incomplete/bogus, but it'll + * serve to get us launched. RelationCacheInitializePhase2() will + * read the real data from pg_class and replace what we've done here. * ---------------- */ - relation->rd_att = CreateTemplateTupleDesc(natts); + relation->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE); + MemSet(relation->rd_rel, 0, CLASS_TUPLE_SIZE); + + strcpy(RelationGetPhysicalRelationName(relation), relationName); /* * For debugging purposes, it's important to distinguish between @@ -1134,23 +1142,21 @@ formrdesc(char *relationName, * code in the buffer manager that traces allocations that has to know * about this. */ - if (IsSystemRelationName(relationName)) - { - relation->rd_rel->relowner = 6; /* XXX use sym const */ relation->rd_rel->relisshared = IsSharedSystemRelationName(relationName); - } else - { - relation->rd_rel->relowner = 0; relation->rd_rel->relisshared = false; - } - relation->rd_rel->relpages = 1; /* XXX */ - relation->rd_rel->reltuples = 1; /* XXX */ + relation->rd_rel->relpages = 1; + relation->rd_rel->reltuples = 1; relation->rd_rel->relkind = RELKIND_RELATION; relation->rd_rel->relnatts = (int16) natts; - relation->rd_isnailed = true; + + /* ---------------- + * initialize attribute tuple form + * ---------------- + */ + relation->rd_att = CreateTemplateTupleDesc(natts); /* ---------------- * initialize tuple desc info @@ -1187,8 +1193,8 @@ formrdesc(char *relationName, * the rdesc for pg_class must already exist. Therefore we must do * the check (and possible set) after cache insertion. * - * XXX I believe the above comment is misguided; we should be - * running in bootstrap or init processing mode, and CatalogHasIndex + * XXX I believe the above comment is misguided; we should be running + * in bootstrap or init processing mode here, and CatalogHasIndex * relies on hard-wired info in those cases. */ relation->rd_rel->relhasindex = @@ -1196,6 +1202,56 @@ formrdesc(char *relationName, } +/* -------------------------------- + * fixrdesc + * + * Update the phony data inserted by formrdesc() with real info + * from pg_class. + * -------------------------------- + */ +static void +fixrdesc(char *relationName) +{ + RelationBuildDescInfo buildinfo; + HeapTuple pg_class_tuple; + Form_pg_class relp; + Relation relation; + + /* ---------------- + * find the tuple in pg_class corresponding to the given relation name + * ---------------- + */ + buildinfo.infotype = INFO_RELNAME; + buildinfo.i.info_name = relationName; + + pg_class_tuple = ScanPgRelation(buildinfo); + + if (!HeapTupleIsValid(pg_class_tuple)) + elog(FATAL, "fixrdesc: no pg_class entry for %s", + relationName); + relp = (Form_pg_class) GETSTRUCT(pg_class_tuple); + + /* ---------------- + * find the pre-made relcache entry (better be there!) + * ---------------- + */ + relation = RelationNameCacheGetRelation(relationName); + if (!RelationIsValid(relation)) + elog(FATAL, "fixrdesc: no existing relcache entry for %s", + relationName); + + /* ---------------- + * and copy pg_class_tuple to relation->rd_rel. + * (See notes in AllocateRelationDesc()) + * ---------------- + */ + Assert(relation->rd_rel != NULL); + memcpy((char *) relation->rd_rel, (char *) relp, CLASS_TUPLE_SIZE); + + heap_freetuple(pg_class_tuple); +} + + /* ---------------------------------------------------------------- * Relation Descriptor Lookup Interface * ---------------------------------------------------------------- @@ -1829,7 +1885,7 @@ RelationPurgeLocalRelation(bool xactCommitted) } /* -------------------------------- - * RelationInitialize + * RelationCacheInitialize * * This initializes the relation descriptor cache. * -------------------------------- @@ -1838,7 +1894,7 @@ RelationPurgeLocalRelation(bool xactCommitted) #define INITRELCACHESIZE 400 void -RelationInitialize(void) +RelationCacheInitialize(void) { MemoryContext oldcxt; HASHCTL ctl; @@ -1870,6 +1926,8 @@ RelationInitialize(void) * initialize the cache with pre-made relation descriptors * for some of the more important system relations. These * relations should always be in the cache. + * + * NB: see also the list in RelationCacheInitializePhase2(). * ---------------- */ formrdesc(RelationRelationName, Natts_pg_class, Desc_pg_class); @@ -1892,6 +1950,34 @@ RelationInitialize(void) MemoryContextSwitchTo(oldcxt); } +/* -------------------------------- + * RelationCacheInitializePhase2 + * + * This completes initialization of the relcache after catcache + * is functional and we are able to actually load data from pg_class. + * -------------------------------- + */ +void +RelationCacheInitializePhase2(void) +{ + /* + * Get the real pg_class tuple for each nailed-in-cache relcache entry + * that was made by RelationCacheInitialize(), and replace the phony + * rd_rel entry made by formrdesc(). This is necessary so that we have, + * for example, the correct toast-table info for tables that have such. + */ + if (!IsBootstrapProcessingMode()) + { + fixrdesc(RelationRelationName); + fixrdesc(AttributeRelationName); + fixrdesc(ProcedureRelationName); + fixrdesc(TypeRelationName); + /* We don't bother to update the entries for pg_variable or pg_log. */ + } +} + + + static void AttrDefaultFetch(Relation relation) { diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index ba0e2dd97a..f63590cdb9 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.63 2000/07/08 03:04:16 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.64 2000/08/06 04:39:10 tgl Exp $ * * *------------------------------------------------------------------------- @@ -313,7 +313,8 @@ InitPostgres(const char *dbname) * it to examine AMI transaction status, and this is never written * after initdb is done. -mer 15 June 1992 */ - RelationInitialize(); /* pre-allocated reldescs created here */ + RelationCacheInitialize(); /* pre-allocated reldescs created here */ + InitializeTransactionSystem(); /* pg_log,etc init/crash recovery * here */ @@ -362,6 +363,9 @@ InitPostgres(const char *dbname) if (!bootstrap) StartTransactionCommand(); + /* replace faked-up relcache entries with the real info */ + RelationCacheInitializePhase2(); + /* * Set ourselves to the proper user id and figure out our postgres * user id. If we ever add security so that we check for valid |
