From: | Justin Pryzby <pryzby(at)telsasoft(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | list_free() in index_get_partition() |
Date: | 2020-11-05 20:36:06 |
Message-ID: | 20201105203606.GF22691@telsasoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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 <pryzbyj(at)telsasoft(dot)com>
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 <pryzbyj(at)telsasoft(dot)com>
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)
{
Attachment | Content-Type | Size |
---|---|---|
0001-Fixes-to-index_get_partition.patch | text/x-diff | 994 bytes |
0002-index_get_partition-use-lsyscache.patch | text/x-diff | 1.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2020-11-05 20:48:55 | Re: default result formats setting |
Previous Message | Peter Eisentraut | 2020-11-05 19:22:10 | Re: libpq compression |