diff options
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/dbcommands.c | 59 | ||||
-rw-r--r-- | src/backend/commands/vacuum.c | 25 |
2 files changed, 33 insertions, 51 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 209362782a8..b21d750394d 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.179 2006/03/29 21:17:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.180 2006/05/03 22:45:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -556,8 +556,6 @@ dropdb(const char *dbname, bool missing_ok) Oid db_id; bool db_istemplate; Relation pgdbrel; - SysScanDesc pgdbscan; - ScanKeyData key; HeapTuple tup; PreventTransactionChain((void *) dbname, "DROP DATABASE"); @@ -629,31 +627,17 @@ dropdb(const char *dbname, bool missing_ok) dbname))); /* - * Find the database's tuple by OID (should be unique). + * Remove the database's tuple from pg_database. */ - ScanKeyInit(&key, - ObjectIdAttributeNumber, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(db_id)); - - pgdbscan = systable_beginscan(pgdbrel, DatabaseOidIndexId, true, - SnapshotNow, 1, &key); - - tup = systable_getnext(pgdbscan); + tup = SearchSysCache(DATABASEOID, + ObjectIdGetDatum(db_id), + 0, 0, 0); if (!HeapTupleIsValid(tup)) - { - /* - * This error should never come up since the existence of the database - * is checked earlier - */ - elog(ERROR, "database \"%s\" doesn't exist despite earlier reports to the contrary", - dbname); - } + elog(ERROR, "cache lookup failed for database %u", db_id); - /* Remove the database's tuple from pg_database */ simple_heap_delete(pgdbrel, &tup->t_self); - systable_endscan(pgdbscan); + ReleaseSysCache(tup); /* * Delete any comments associated with the database @@ -1262,7 +1246,10 @@ get_database_oid(const char *dbname) HeapTuple dbtuple; Oid oid; - /* There's no syscache for pg_database, so must look the hard way */ + /* + * There's no syscache for pg_database indexed by name, + * so we must look the hard way. + */ pg_database = heap_open(DatabaseRelationId, AccessShareLock); ScanKeyInit(&entry[0], Anum_pg_database_datname, @@ -1296,32 +1283,20 @@ get_database_oid(const char *dbname) char * get_database_name(Oid dbid) { - Relation pg_database; - ScanKeyData entry[1]; - SysScanDesc scan; HeapTuple dbtuple; char *result; - /* There's no syscache for pg_database, so must look the hard way */ - pg_database = heap_open(DatabaseRelationId, AccessShareLock); - ScanKeyInit(&entry[0], - ObjectIdAttributeNumber, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(dbid)); - scan = systable_beginscan(pg_database, DatabaseOidIndexId, true, - SnapshotNow, 1, entry); - - dbtuple = systable_getnext(scan); - - /* We assume that there can be at most one matching tuple */ + dbtuple = SearchSysCache(DATABASEOID, + ObjectIdGetDatum(dbid), + 0, 0, 0); if (HeapTupleIsValid(dbtuple)) + { result = pstrdup(NameStr(((Form_pg_database) GETSTRUCT(dbtuple))->datname)); + ReleaseSysCache(dbtuple); + } else result = NULL; - systable_endscan(scan); - heap_close(pg_database, AccessShareLock); - return result; } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index a5d704c1d86..7f13bae8099 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.328 2006/05/02 22:25:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.329 2006/05/03 22:45:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -28,6 +28,7 @@ #include "access/subtrans.h" #include "access/xlog.h" #include "catalog/catalog.h" +#include "catalog/indexing.h" #include "catalog/namespace.h" #include "catalog/pg_database.h" #include "catalog/pg_index.h" @@ -767,27 +768,33 @@ vac_update_dbstats(Oid dbid, { Relation relation; ScanKeyData entry[1]; - HeapScanDesc scan; + SysScanDesc scan; HeapTuple tuple; + Buffer buf; Form_pg_database dbform; relation = heap_open(DatabaseRelationId, RowExclusiveLock); - /* Must use a heap scan, since there's no syscache for pg_database */ ScanKeyInit(&entry[0], ObjectIdAttributeNumber, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(dbid)); - scan = heap_beginscan(relation, SnapshotNow, 1, entry); + scan = systable_beginscan(relation, DatabaseOidIndexId, true, + SnapshotNow, 1, entry); - tuple = heap_getnext(scan, ForwardScanDirection); + tuple = systable_getnext(scan); if (!HeapTupleIsValid(tuple)) elog(ERROR, "could not find tuple for database %u", dbid); + if (scan->irel) + buf = scan->iscan->xs_cbuf; + else + buf = scan->scan->rs_cbuf; + /* ensure no one else does this at the same time */ - LockBuffer(scan->rs_cbuf, BUFFER_LOCK_EXCLUSIVE); + LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); dbform = (Form_pg_database) GETSTRUCT(tuple); @@ -795,14 +802,14 @@ vac_update_dbstats(Oid dbid, dbform->datvacuumxid = vacuumXID; dbform->datfrozenxid = frozenXID; - MarkBufferDirty(scan->rs_cbuf); + MarkBufferDirty(buf); - LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK); + LockBuffer(buf, BUFFER_LOCK_UNLOCK); /* invalidate the tuple in the cache so we'll see the change in cache */ CacheInvalidateHeapTuple(relation, tuple); - heap_endscan(scan); + systable_endscan(scan); heap_close(relation, RowExclusiveLock); |