Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kalzY-00024s-Tc for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Nov 2020 20:36:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kalzX-00009d-3j for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Nov 2020 20:36:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kalzW-00009N-O9 for pgsql-hackers@lists.postgresql.org; Thu, 05 Nov 2020 20:36:18 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kalzP-0001B0-Bz for pgsql-hackers@postgresql.org; Thu, 05 Nov 2020 20:36:18 +0000 Received: by mail-io1-xd31.google.com with SMTP id r9so3179257ioo.7 for ; Thu, 05 Nov 2020 12:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=gKHsA+TL+frQyYhVm+jBxL/Sho1F04RInmFI+sPoyi8=; b=Wv56GIn6QBPVrfARt7MukMTDinGHXIP7eyDa3W4f1rXcvKp5AeWKMyu4PIBCWf+69A 23sCDcI9Xatngz0+Pg3j9WM7eIbpJgkBrHRYXv6x7gJ045ZRW5m8I739LeuIV5f9ROqG COg9dvP45vc35TvKHVh7V0VDYq+DkWsj8LK1j9tjgeafuvy5Ozv8wgiXwczh4kYSRFJW jKBx5xcKbCkE4fvGbTgRzAz4AXX7gYOKIKf6jylWeo7rzkqWYawcSfZhMz+6Eo65q6s5 7Quso56PbcZwychfiber/MIx31qx8Q/8Ig8jHbCd0c8UWnyXBRlvI13ZXcW7yK91kCJO RbDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=gKHsA+TL+frQyYhVm+jBxL/Sho1F04RInmFI+sPoyi8=; b=Vf9k2BpmghKKiVWK2F8M00nT3eNfLGhF+CvXbrCBaodIrtPeyIEQHKvMz+bnTDEdzN +TlSJxG6eP+3zcKVxpxPR7CxOWbPTgRMVOYVRyZ5ZJviFjNAOIAaKk7U5ZxILXptw3ZQ 2p5iq8nWuq5MKIgeUVz2PWInZygHv5YgRebNVxzN0Ms0vlkYyzFiw4DCe1B86piwrhiP uzXi/cve2ep2BNYlIWQTWJ7HU2bka0QKCEEzGFEj0SXTQhRsWKZhq1Dok2C0GnNceg2t DIo5ZmE52EDmx3oGFwuXAh07vKrca7vxnXIAbjgLq3VUgbKUoTeO4e4IueiyNmpyY9fy Ca6g== X-Gm-Message-State: AOAM532XBaUuheMzOIJQBbHyOLEVuUZmaIHdEa92WYGij+dMZmylDLL9 yq2IRLDpbJzAJkIWsAInaFmM7A== X-Google-Smtp-Source: ABdhPJyyME+c/DpezT62QVkWzLknVUCZBVVwR7w8ZDVI2ujKL/q+hw+354VK+YFQQ8rKxfFHKYYDEQ== X-Received: by 2002:a6b:be02:: with SMTP id o2mr3323992iof.102.1604608568352; Thu, 05 Nov 2020 12:36:08 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id o124sm1772575ila.62.2020.11.05.12.36.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Nov 2020 12:36:07 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 595F5800689; Thu, 5 Nov 2020 14:36:06 -0600 (CST) Date: Thu, 5 Nov 2020 14:36:06 -0600 From: Justin Pryzby To: Alvaro Herrera Cc: pgsql-hackers@postgresql.org Subject: list_free() in index_get_partition() Message-ID: <20201105203606.GF22691@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="6K2R/cS9K4qvcBNq" Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --6K2R/cS9K4qvcBNq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Seems to be missing. The 2nd patch does some more cleanup - Before, a failed syscache lookup would ERROR, but I don't think that's supposed to happen. get_rel_relispartition() would instead return false, and we won't call get_partition_parent(). commit a8ad949f22b8dd7b23049b0b0704e5be9233e319 Author: Justin Pryzby Date: Thu Nov 5 12:06:49 2020 -0600 list_free() in index_get_partition() which was added at: a6da0047158b8a227f883aeed19eb7fcfbef11fb diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 239ac017fa..4dfac39adf 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -153,44 +153,45 @@ Oid index_get_partition(Relation partition, Oid indexId) { List *idxlist = RelationGetIndexList(partition); ListCell *l; foreach(l, idxlist) { Oid partIdx = lfirst_oid(l); HeapTuple tup; Form_pg_class classForm; bool ispartition; tup = SearchSysCache1(RELOID, ObjectIdGetDatum(partIdx)); if (!HeapTupleIsValid(tup)) elog(ERROR, "cache lookup failed for relation %u", partIdx); classForm = (Form_pg_class) GETSTRUCT(tup); ispartition = classForm->relispartition; ReleaseSysCache(tup); if (!ispartition) continue; - if (get_partition_parent(lfirst_oid(l)) == indexId) + if (get_partition_parent(partIdx) == indexId) { list_free(idxlist); return partIdx; } } + list_free(idxlist); return InvalidOid; } commit 0a01cb7561d6ec74aa5829040bd1478e7b113d89 Author: Justin Pryzby Date: Thu Nov 5 12:14:24 2020 -0600 index_get_partition(): use lsyscache ?? The old code failed when !HeapTupleIsValid(), the new code will return false - is that ok ?? Two of the existing callers error anyway. diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 4dfac39adf..3d78bc0872 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -28,6 +28,7 @@ #include "partitioning/partbounds.h" #include "rewrite/rewriteManip.h" #include "utils/fmgroids.h" +#include "utils/lsyscache.h" #include "utils/partcache.h" #include "utils/rel.h" #include "utils/syscache.h" @@ -158,17 +159,8 @@ index_get_partition(Relation partition, Oid indexId) foreach(l, idxlist) { Oid partIdx = lfirst_oid(l); - HeapTuple tup; - Form_pg_class classForm; - bool ispartition; - - tup = SearchSysCache1(RELOID, ObjectIdGetDatum(partIdx)); - if (!HeapTupleIsValid(tup)) - elog(ERROR, "cache lookup failed for relation %u", partIdx); - classForm = (Form_pg_class) GETSTRUCT(tup); - ispartition = classForm->relispartition; - ReleaseSysCache(tup); - if (!ispartition) + + if (!get_rel_relispartition(partIdx)) continue; if (get_partition_parent(partIdx) == indexId) { --6K2R/cS9K4qvcBNq Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Fixes-to-index_get_partition.patch" From 90e155f660314ec70de14177241dd1ec029d9311 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Thu, 5 Nov 2020 12:06:49 -0600 Subject: [PATCH 1/2] Fixes to index_get_partition() which was added at: a6da0047158b8a227f883aeed19eb7fcfbef11fb free list in cases where there's no parent use lsyscache: get_rel_relispartition() --- src/backend/catalog/partition.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 239ac017fa..4dfac39adf 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -170,13 +170,14 @@ index_get_partition(Relation partition, Oid indexId) ReleaseSysCache(tup); if (!ispartition) continue; - if (get_partition_parent(lfirst_oid(l)) == indexId) + if (get_partition_parent(partIdx) == indexId) { list_free(idxlist); return partIdx; } } + list_free(idxlist); return InvalidOid; } -- 2.17.0 --6K2R/cS9K4qvcBNq Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-index_get_partition-use-lsyscache.patch" From 768f91199b5e197759b2ead6d838a72974dca6b6 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Thu, 5 Nov 2020 12:14:24 -0600 Subject: [PATCH 2/2] index_get_partition(): use lsyscache ?? The old code failed when !HeapTupleIsValid(), the new code will return false - is that ok ?? --- src/backend/catalog/partition.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 4dfac39adf..3d78bc0872 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -28,6 +28,7 @@ #include "partitioning/partbounds.h" #include "rewrite/rewriteManip.h" #include "utils/fmgroids.h" +#include "utils/lsyscache.h" #include "utils/partcache.h" #include "utils/rel.h" #include "utils/syscache.h" @@ -158,17 +159,8 @@ index_get_partition(Relation partition, Oid indexId) foreach(l, idxlist) { Oid partIdx = lfirst_oid(l); - HeapTuple tup; - Form_pg_class classForm; - bool ispartition; - - tup = SearchSysCache1(RELOID, ObjectIdGetDatum(partIdx)); - if (!HeapTupleIsValid(tup)) - elog(ERROR, "cache lookup failed for relation %u", partIdx); - classForm = (Form_pg_class) GETSTRUCT(tup); - ispartition = classForm->relispartition; - ReleaseSysCache(tup); - if (!ispartition) + + if (!get_rel_relispartition(partIdx)) continue; if (get_partition_parent(partIdx) == indexId) { -- 2.17.0 --6K2R/cS9K4qvcBNq--