diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 7f2fd58..1a4dd12 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -667,7 +667,7 @@ partition_bounds_equal(PartitionKey key, void check_new_partition_bound(char *relname, Relation parent, Node *bound) { - PartitionBoundSpec *spec = (PartitionBoundSpec *) bound; + PartitionBoundSpec *spec = castNode(PartitionBoundSpec, bound); PartitionKey key = RelationGetPartitionKey(parent); PartitionDesc partdesc = RelationGetPartitionDesc(parent); ParseState *pstate = make_parsestate(NULL); @@ -891,7 +891,7 @@ get_partition_parent(Oid relid) List * get_qual_from_partbound(Relation rel, Relation parent, Node *bound) { - PartitionBoundSpec *spec = (PartitionBoundSpec *) bound; + PartitionBoundSpec *spec = castNode(PartitionBoundSpec, bound); PartitionKey key = RelationGetPartitionKey(parent); List *my_qual = NIL; @@ -1300,11 +1300,10 @@ static List * get_qual_for_list(PartitionKey key, PartitionBoundSpec *spec) { List *result; + List *datums = NIL; ArrayExpr *arr; Expr *opexpr; - ListCell *cell, - *prev, - *next; + ListCell *cell; Expr *keyCol; bool list_has_null = false; NullTest *nulltest1 = NULL, @@ -1322,24 +1321,17 @@ get_qual_for_list(PartitionKey key, PartitionBoundSpec *spec) keyCol = (Expr *) copyObject(linitial(key->partexprs)); /* - * We must remove any NULL value in the list; we handle it separately + * Create a list of datums without NULL; as we handle it separately * below. */ - prev = NULL; - for (cell = list_head(spec->listdatums); cell; cell = next) + foreach (cell, spec->listdatums) { Const *val = (Const *) lfirst(cell); - next = lnext(cell); - if (val->constisnull) - { list_has_null = true; - spec->listdatums = list_delete_cell(spec->listdatums, - cell, prev); - } else - prev = cell; + datums = lappend(datums, lfirst(cell)); } if (!list_has_null) @@ -1373,7 +1365,7 @@ get_qual_for_list(PartitionKey key, PartitionBoundSpec *spec) : key->parttypid[0]; arr->array_collid = key->parttypcoll[0]; arr->element_typeid = key->parttypid[0]; - arr->elements = spec->listdatums; + arr->elements = datums; arr->multidims = false; arr->location = -1;