Content-Length: 374697 | pFad | http://github.com/postgrespro/postgres/commit/e6b92542a39b50d0c02f90ef56aa6930e26eca81

91 Marginal speedup in RelationIsVisible and TypeIsVisible: avoid a redu… · postgrespro/postgres@e6b9254 · GitHub
Skip to content

Commit e6b9254

Browse files
committed
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.
1 parent f59175d commit e6b9254

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/backend/catalog/namespace.c

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.77 2005/08/01 04:03:54 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.78 2005/10/06 22:43:16 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -335,12 +335,28 @@ RelationIsVisible(Oid relid)
335335
/*
336336
* If it is in the path, it might still not be visible; it could
337337
* be hidden by another relation of the same name earlier in the
338-
* path. So we must do a slow check to see if this rel would be
339-
* found by RelnameGetRelid.
338+
* path. So we must do a slow check for conflicting relations.
340339
*/
341340
char *relname = NameStr(relform->relname);
341+
ListCell *l;
342342

343-
visible = (RelnameGetRelid(relname) == relid);
343+
visible = false;
344+
foreach(l, namespaceSearchPath)
345+
{
346+
Oid namespaceId = lfirst_oid(l);
347+
348+
if (namespaceId == relnamespace)
349+
{
350+
/* Found it first in path */
351+
visible = true;
352+
break;
353+
}
354+
if (OidIsValid(get_relname_relid(relname, namespaceId)))
355+
{
356+
/* Found something else first in path */
357+
break;
358+
}
359+
}
344360
}
345361

346362
ReleaseSysCache(reltup);
@@ -417,12 +433,31 @@ TypeIsVisible(Oid typid)
417433
/*
418434
* If it is in the path, it might still not be visible; it could
419435
* be hidden by another type of the same name earlier in the path.
420-
* So we must do a slow check to see if this type would be found
421-
* by TypenameGetTypid.
436+
* So we must do a slow check for conflicting types.
422437
*/
423438
char *typname = NameStr(typform->typname);
439+
ListCell *l;
424440

425-
visible = (TypenameGetTypid(typname) == typid);
441+
visible = false;
442+
foreach(l, namespaceSearchPath)
443+
{
444+
Oid namespaceId = lfirst_oid(l);
445+
446+
if (namespaceId == typnamespace)
447+
{
448+
/* Found it first in path */
449+
visible = true;
450+
break;
451+
}
452+
if (SearchSysCacheExists(TYPENAMENSP,
453+
PointerGetDatum(typname),
454+
ObjectIdGetDatum(namespaceId),
455+
0, 0))
456+
{
457+
/* Found something else first in path */
458+
break;
459+
}
460+
}
426461
}
427462

428463
ReleaseSysCache(typtup);

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/e6b92542a39b50d0c02f90ef56aa6930e26eca81

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy