From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Returning NULL from satisfies_hash_partition() is a bad idea |
Date: | 2020-11-11 22:46:59 |
Message-ID: | 24067.1605134819@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
So far as I can tell, the partition machinery is critically dependent
on the idea that partition constraint conditions can never return
NULL, only true or false. This is explicitly noted in the comments in
get_qual_for_list, for instance, and it's visibly true by construction
for both list and range constraints.
But hash partition constraints are just calls to
satisfies_hash_partition(), and look what we've got there:
/* Return null if the parent OID, modulus, or remainder is NULL. */
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
PG_RETURN_NULL();
parent = try_relation_open(parentId, AccessShareLock);
if (parent == NULL)
PG_RETURN_NULL();
OK, the first one probably shouldn't happen, but it's far from clear that
the second cannot. If we did return NULL, that would be taken as a "pass"
of the constraint, possibly allowing a non-matching row to be inserted
into a partition.
So this seems like a seriously bad idea. I don't have a strong position
on whether it'd be better to return FALSE (causing a constraint failure
error) or just throw an error outright. But we can't leave it like this.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Dagfinn Ilmari Mannsåker | 2020-11-12 00:18:49 | Re: Proposition for autoname columns |
Previous Message | Andres Freund | 2020-11-11 22:46:30 | Re: PATCH: Batch/pipelining support for libpq |