aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-10-06 22:43:16 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-10-06 22:43:16 +0000
commite6b92542a39b50d0c02f90ef56aa6930e26eca81 (patch)
treea8fa832b9f2e12ec3d9774896947971deba3c883 /src
parentf59175d72ff9b31b4bb486e5396815636abbcfe0 (diff)
downloadpostgresql-e6b92542a39b50d0c02f90ef56aa6930e26eca81.tar.gz
postgresql-e6b92542a39b50d0c02f90ef56aa6930e26eca81.zip
Marginal speedup in RelationIsVisible and TypeIsVisible: avoid a redundant
cache lookup in the success case. This won't help much for cases where the given relation is far down the search path, but it does not hurt in any cases either; and it requires only a little new code. Per gripe from Jim Nasby about slowness of \d with many tables.
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/namespace.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index e74b331e376..dc627e42880 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.77 2005/08/01 04:03:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.78 2005/10/06 22:43:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -335,12 +335,28 @@ RelationIsVisible(Oid relid)
/*
* If it is in the path, it might still not be visible; it could
* be hidden by another relation of the same name earlier in the
- * path. So we must do a slow check to see if this rel would be
- * found by RelnameGetRelid.
+ * path. So we must do a slow check for conflicting relations.
*/
char *relname = NameStr(relform->relname);
+ ListCell *l;
- visible = (RelnameGetRelid(relname) == relid);
+ visible = false;
+ foreach(l, namespaceSearchPath)
+ {
+ Oid namespaceId = lfirst_oid(l);
+
+ if (namespaceId == relnamespace)
+ {
+ /* Found it first in path */
+ visible = true;
+ break;
+ }
+ if (OidIsValid(get_relname_relid(relname, namespaceId)))
+ {
+ /* Found something else first in path */
+ break;
+ }
+ }
}
ReleaseSysCache(reltup);
@@ -417,12 +433,31 @@ TypeIsVisible(Oid typid)
/*
* If it is in the path, it might still not be visible; it could
* be hidden by another type of the same name earlier in the path.
- * So we must do a slow check to see if this type would be found
- * by TypenameGetTypid.
+ * So we must do a slow check for conflicting types.
*/
char *typname = NameStr(typform->typname);
+ ListCell *l;
- visible = (TypenameGetTypid(typname) == typid);
+ visible = false;
+ foreach(l, namespaceSearchPath)
+ {
+ Oid namespaceId = lfirst_oid(l);
+
+ if (namespaceId == typnamespace)
+ {
+ /* Found it first in path */
+ visible = true;
+ break;
+ }
+ if (SearchSysCacheExists(TYPENAMENSP,
+ PointerGetDatum(typname),
+ ObjectIdGetDatum(namespaceId),
+ 0, 0))
+ {
+ /* Found something else first in path */
+ break;
+ }
+ }
}
ReleaseSysCache(typtup);