Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WPcYm-0003Li-P9 for pgsql-bugs@arkaria.postgresql.org; Mon, 17 Mar 2014 18:46:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WPcYl-0001m0-7a for pgsql-bugs@arkaria.postgresql.org; Mon, 17 Mar 2014 18:46:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WPQQz-0007es-C5 for pgsql-bugs@postgresql.org; Mon, 17 Mar 2014 05:50:01 +0000 Received: from mail.valinux.co.jp ([210.128.90.3]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WPQQn-0002Et-Qh; Mon, 17 Mar 2014 05:49:58 +0000 Received: from kuma.localdomain (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with ESMTP id E28E148958; Mon, 17 Mar 2014 14:49:45 +0900 (JST) Received: by kuma.localdomain (Postfix, from userid 1000) id BD7AB71A4D; Mon, 17 Mar 2014 14:49:45 +0900 (JST) To: pgsql-bugs@postgresql.org Cc: kgrittn@postgresql.org Subject: relcache reference leak on refresh materialized view concurrently X-Mailer: Cue version 0.8 (140304-1800/takashi) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Message-Id: <20140317054945.BD7AB71A4D@kuma.localdomain> Date: Mon, 17 Mar 2014 14:49:45 +0900 (JST) From: yamamoto@valinux.co.jp (YAMAMOTO Takashi) X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org the following patch fixes missing index_close in case the mv has non-unique indexes. YAMAMOTO Takashi diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index d64f165..83efab1 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -611,6 +611,8 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid) Relation indexRel; HeapTuple indexTuple; Form_pg_index indexStruct; + int numatts; + int i; indexRel = index_open(indexoid, RowExclusiveLock); indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexoid)); @@ -619,61 +621,63 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid) indexStruct = (Form_pg_index) GETSTRUCT(indexTuple); /* We're only interested if it is unique and valid. */ - if (indexStruct->indisunique && IndexIsValid(indexStruct)) + if (!indexStruct->indisunique || !IndexIsValid(indexStruct)) { - int numatts = indexStruct->indnatts; - int i; - - /* Skip any index on an expression. */ - if (RelationGetIndexExpressions(indexRel) != NIL) - { - index_close(indexRel, NoLock); - ReleaseSysCache(indexTuple); - continue; - } + index_close(indexRel, NoLock); + ReleaseSysCache(indexTuple); + continue; + } - /* Skip partial indexes. */ - if (RelationGetIndexPredicate(indexRel) != NIL) - { - index_close(indexRel, NoLock); - ReleaseSysCache(indexTuple); - continue; - } + /* Skip any index on an expression. */ + if (RelationGetIndexExpressions(indexRel) != NIL) + { + index_close(indexRel, NoLock); + ReleaseSysCache(indexTuple); + continue; + } - /* Hold the locks, since we're about to run DML which needs them. */ + /* Skip partial indexes. */ + if (RelationGetIndexPredicate(indexRel) != NIL) + { index_close(indexRel, NoLock); + ReleaseSysCache(indexTuple); + continue; + } - /* Add quals for all columns from this index. */ - for (i = 0; i < numatts; i++) - { - int attnum = indexStruct->indkey.values[i]; - Oid type; - Oid op; - const char *colname; - - /* - * Only include the column once regardless of how many times - * it shows up in how many indexes. - */ - if (usedForQual[attnum - 1]) - continue; - usedForQual[attnum - 1] = true; - - /* - * Actually add the qual, ANDed with any others. - */ - if (foundUniqueIndex) - appendStringInfoString(&querybuf, " AND "); - - colname = quote_identifier(NameStr((tupdesc->attrs[attnum - 1])->attname)); - appendStringInfo(&querybuf, "newdata.%s ", colname); - type = attnumTypeId(matviewRel, attnum); - op = lookup_type_cache(type, TYPECACHE_EQ_OPR)->eq_opr; - mv_GenerateOper(&querybuf, op); - appendStringInfo(&querybuf, " mv.%s", colname); - - foundUniqueIndex = true; - } + /* Hold the locks, since we're about to run DML which needs them. */ + index_close(indexRel, NoLock); + + /* Add quals for all columns from this index. */ + numatts = indexStruct->indnatts; + for (i = 0; i < numatts; i++) + { + int attnum = indexStruct->indkey.values[i]; + Oid type; + Oid op; + const char *colname; + + /* + * Only include the column once regardless of how many times + * it shows up in how many indexes. + */ + if (usedForQual[attnum - 1]) + continue; + usedForQual[attnum - 1] = true; + + /* + * Actually add the qual, ANDed with any others. + */ + if (foundUniqueIndex) + appendStringInfoString(&querybuf, " AND "); + + colname = quote_identifier(NameStr((tupdesc->attrs[attnum - 1])->attname)); + appendStringInfo(&querybuf, "newdata.%s ", colname); + type = attnumTypeId(matviewRel, attnum); + op = lookup_type_cache(type, TYPECACHE_EQ_OPR)->eq_opr; + mv_GenerateOper(&querybuf, op); + appendStringInfo(&querybuf, " mv.%s", colname); + + foundUniqueIndex = true; } ReleaseSysCache(indexTuple); } -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs