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

Commitf7271c4

Browse files
committed
Fix relcache reference leak in refresh_by_match_merge().
One path through the loop over indexes forgot to do index_close(). Ratherthan adding a fourth call, restructure slightly so that there's only one.In passing, get rid of an unnecessary syscache lookup: the pg_index structfor the index is already available from its relcache entry.Per report from YAMAMOTO Takashi, though this is a bit different from hissuggested patch. This is new code in HEAD, so no need for back-patch.
1 parent3bd261c commitf7271c4

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

‎src/backend/commands/matview.c

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -609,40 +609,23 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid)
609609
{
610610
Oidindexoid=lfirst_oid(indexoidscan);
611611
RelationindexRel;
612-
HeapTupleindexTuple;
613612
Form_pg_indexindexStruct;
614613

615614
indexRel=index_open(indexoid,RowExclusiveLock);
616-
indexTuple=SearchSysCache1(INDEXRELID,ObjectIdGetDatum(indexoid));
617-
if (!HeapTupleIsValid(indexTuple))/* should not happen */
618-
elog(ERROR,"cache lookup failed for index %u",indexoid);
619-
indexStruct= (Form_pg_index)GETSTRUCT(indexTuple);
620-
621-
/* We're only interested if it is unique and valid. */
622-
if (indexStruct->indisunique&&IndexIsValid(indexStruct))
615+
indexStruct=indexRel->rd_index;
616+
617+
/*
618+
* We're only interested if it is unique, valid, contains no
619+
* expressions, and is not partial.
620+
*/
621+
if (indexStruct->indisunique&&
622+
IndexIsValid(indexStruct)&&
623+
RelationGetIndexExpressions(indexRel)==NIL&&
624+
RelationGetIndexPredicate(indexRel)==NIL)
623625
{
624626
intnumatts=indexStruct->indnatts;
625627
inti;
626628

627-
/* Skip any index on an expression. */
628-
if (RelationGetIndexExpressions(indexRel)!=NIL)
629-
{
630-
index_close(indexRel,NoLock);
631-
ReleaseSysCache(indexTuple);
632-
continue;
633-
}
634-
635-
/* Skip partial indexes. */
636-
if (RelationGetIndexPredicate(indexRel)!=NIL)
637-
{
638-
index_close(indexRel,NoLock);
639-
ReleaseSysCache(indexTuple);
640-
continue;
641-
}
642-
643-
/* Hold the locks, since we're about to run DML which needs them. */
644-
index_close(indexRel,NoLock);
645-
646629
/* Add quals for all columns from this index. */
647630
for (i=0;i<numatts;i++)
648631
{
@@ -675,7 +658,9 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid)
675658
foundUniqueIndex= true;
676659
}
677660
}
678-
ReleaseSysCache(indexTuple);
661+
662+
/* Keep the locks, since we're about to run DML which needs them. */
663+
index_close(indexRel,NoLock);
679664
}
680665

681666
list_free(indexoidlist);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp