Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6b9254

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 wherethe given relation is far down the search path, but it does not hurt inany cases either; and it requires only a little new code. Per gripe fromJim Nasby about slowness of \d with many tables.
1 parentf59175d commite6b9254

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+
OidnamespaceId=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+
OidnamespaceId=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)

[8]ページ先頭

©2009-2025 Movatter.jp