]> granicus.if.org Git - postgresql/commitdiff
Marginal speedup in RelationIsVisible and TypeIsVisible: avoid a redundant
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 6 Oct 2005 22:43:16 +0000 (22:43 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 6 Oct 2005 22:43:16 +0000 (22:43 +0000)
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.

src/backend/catalog/namespace.c

index e74b331e37653ea590ee8563a269b0e4784066a5..dc627e42880f3fd72d802f57938bd8fdd396bd84 100644 (file)
@@ -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);