diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-05-03 22:45:26 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-05-03 22:45:26 +0000 |
commit | cb98e6fb8fd4f1ca955a85d5c0088e42e77a04f0 (patch) | |
tree | 8b7aa603d809eb71b48b923a299189a54e4df544 /src/backend/utils | |
parent | 5320c6cf6b21811eda1910a7df6f05b992fe2aea (diff) | |
download | postgresql-cb98e6fb8fd4f1ca955a85d5c0088e42e77a04f0.tar.gz postgresql-cb98e6fb8fd4f1ca955a85d5c0088e42e77a04f0.zip |
Create a syscache for pg_database-indexed-by-oid, and make use of it
in various places that were previously doing ad hoc pg_database searches.
This may speed up database-related privilege checks a little bit, but
the main motivation is to eliminate the performance reason for having
ReverifyMyDatabase do such a lot of stuff (viz, avoiding repeat scans
of pg_database during backend startup). The locking reason for having
that routine is about to go away, and it'd be good to have the option
to break it up.
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/cache/syscache.c | 13 | ||||
-rw-r--r-- | src/backend/utils/init/postinit.c | 17 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index 90b9c4cb053..ffcb26e3c55 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/syscache.c,v 1.102 2006/03/05 15:58:45 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/syscache.c,v 1.103 2006/05/03 22:45:26 tgl Exp $ * * NOTES * These routines allow the parser/planner/executor to perform @@ -31,6 +31,7 @@ #include "catalog/pg_auth_members.h" #include "catalog/pg_cast.h" #include "catalog/pg_conversion.h" +#include "catalog/pg_database.h" #include "catalog/pg_index.h" #include "catalog/pg_inherits.h" #include "catalog/pg_language.h" @@ -273,6 +274,16 @@ static const struct cachedesc cacheinfo[] = { 0, 0 }}, + {DatabaseRelationId, /* DATABASEOID */ + DatabaseOidIndexId, + 0, + 1, + { + ObjectIdAttributeNumber, + 0, + 0, + 0 + }}, {IndexRelationId, /* INDEXRELID */ IndexRelidIndexId, Anum_pg_index_indrelid, diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index e89df5bb3af..4ddc7f712af 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.164 2006/04/30 21:15:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.165 2006/05/03 22:45:26 tgl Exp $ * * *------------------------------------------------------------------------- @@ -195,19 +195,16 @@ ReverifyMyDatabase(const char *name, bool am_superuser) name))); /* - * Check privilege to connect to the database. To avoid making - * a whole extra search of pg_database here, we don't go through - * pg_database_aclcheck, but instead use a lower-level routine - * that we can pass the pg_database tuple to. + * Check privilege to connect to the database. (The am_superuser + * test is redundant, but since we have the flag, might as well + * check it and save a few cycles.) */ if (!am_superuser && - pg_database_tuple_aclmask(tup, RelationGetDescr(pgdbrel), - GetUserId(), - ACL_CONNECT, ACLMASK_ANY) == 0) + pg_database_aclcheck(MyDatabaseId, GetUserId(), + ACL_CONNECT) != ACLCHECK_OK) ereport(FATAL, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("permission denied for database %s", - NameStr(dbform->datname)), + errmsg("permission denied for database \"%s\"", name), errdetail("User does not have CONNECT privilege."))); /* |