Skip to content

Commit f7271c4

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

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
Oid indexoid = lfirst_oid(indexoidscan);
611611
Relation indexRel;
612-
HeapTuple indexTuple;
613612
Form_pg_index indexStruct;
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
int numatts = indexStruct->indnatts;
625627
int i;
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy