Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba5c4c7

Browse files
author
Svetlana Derevyanko
committed
[PGPRO-9874] Added check on SearchSysCache returning NULL
Tags: pg_pathman
1 parent a899f36 commit ba5c4c7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/partition_creation.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,8 @@ spawn_partitions_val(Oid parent_relid, /* parent's Oid */
606606

607607
/* Get typname of range_bound_type to perform cast */
608608
typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(range_bound_type));
609-
Assert(HeapTupleIsValid(typeTuple));
609+
if (!HeapTupleIsValid(typeTuple))
610+
elog(ERROR, "cache lookup failed for type %u", range_bound_type);
610611
typname = pstrdup(NameStr(((Form_pg_type) GETSTRUCT(typeTuple))->typname));
611612
ReleaseSysCache(typeTuple);
612613

src/relation_info.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ invalidate_bounds_cache(void)
11671167
/*
11681168
* Get constraint expression tree of a partition.
11691169
*
1170-
* build_check_constraint_name_internal() is used to build conname.
1170+
* build_check_constraint_name_relid_internal() is used to build conname.
11711171
*/
11721172
Expr *
11731173
get_partition_constraint_expr(Oid partition, bool raise_error)
@@ -1193,6 +1193,16 @@ get_partition_constraint_expr(Oid partition, bool raise_error)
11931193
}
11941194

11951195
con_tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(conid));
1196+
if (!HeapTupleIsValid(con_tuple))
1197+
{
1198+
if (!raise_error)
1199+
return NULL;
1200+
1201+
ereport(ERROR,
1202+
(errmsg("cache lookup failed for constraint \"%s\" of partition \"%s\"",
1203+
conname, get_rel_name_or_relid(partition))));
1204+
}
1205+
11961206
conbin_datum = SysCacheGetAttr(CONSTROID, con_tuple,
11971207
Anum_pg_constraint_conbin,
11981208
&conbin_isnull);
@@ -1204,9 +1214,6 @@ get_partition_constraint_expr(Oid partition, bool raise_error)
12041214
ereport(ERROR,
12051215
(errmsg("constraint \"%s\" of partition \"%s\" has NULL conbin",
12061216
conname, get_rel_name_or_relid(partition))));
1207-
pfree(conname);
1208-
1209-
return NULL; /* could not parse */
12101217
}
12111218
pfree(conname);
12121219

0 commit comments

Comments
 (0)