diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/partitioning/partbounds.c | 15 | ||||
-rw-r--r-- | src/test/regress/expected/hash_part.out | 10 |
2 files changed, 10 insertions, 15 deletions
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index c8f708be125..e6f3068d66e 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -2104,6 +2104,8 @@ compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc, * * Returns true if remainder produced when this computed single hash value is * divided by the given modulus is equal to given remainder, otherwise false. + * NB: it's important that this never return null, as the constraint machinery + * would consider that to be a "pass". * * See get_qual_for_hash() for usage. */ @@ -2127,9 +2129,9 @@ satisfies_hash_partition(PG_FUNCTION_ARGS) ColumnsHashData *my_extra; uint64 rowHash = 0; - /* Return null if the parent OID, modulus, or remainder is NULL. */ + /* Return false if the parent OID, modulus, or remainder is NULL. */ if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2)) - PG_RETURN_NULL(); + PG_RETURN_BOOL(false); parentId = PG_GETARG_OID(0); modulus = PG_GETARG_INT32(1); remainder = PG_GETARG_INT32(2); @@ -2158,15 +2160,12 @@ satisfies_hash_partition(PG_FUNCTION_ARGS) PartitionKey key; int j; - /* Open parent relation and fetch partition keyinfo */ - parent = try_relation_open(parentId, AccessShareLock); - if (parent == NULL) - PG_RETURN_NULL(); + /* Open parent relation and fetch partition key info */ + parent = relation_open(parentId, AccessShareLock); key = RelationGetPartitionKey(parent); /* Reject parent table that is not hash-partitioned. */ - if (parent->rd_rel->relkind != RELKIND_PARTITIONED_TABLE || - key->strategy != PARTITION_STRATEGY_HASH) + if (key == NULL || key->strategy != PARTITION_STRATEGY_HASH) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("\"%s\" is not a hash partitioned table", diff --git a/src/test/regress/expected/hash_part.out b/src/test/regress/expected/hash_part.out index 247dec50dc2..8d4b337e62a 100644 --- a/src/test/regress/expected/hash_part.out +++ b/src/test/regress/expected/hash_part.out @@ -10,11 +10,7 @@ CREATE TABLE mchash1 PARTITION OF mchash FOR VALUES WITH (MODULUS 4, REMAINDER 0); -- invalid OID, no such table SELECT satisfies_hash_partition(0, 4, 0, NULL); - satisfies_hash_partition --------------------------- - -(1 row) - +ERROR: could not open relation with OID 0 -- not partitioned SELECT satisfies_hash_partition('tenk1'::regclass, 4, 0, NULL); ERROR: "tenk1" is not a hash partitioned table @@ -34,14 +30,14 @@ ERROR: remainder for hash partition must be less than modulus SELECT satisfies_hash_partition('mchash'::regclass, NULL, 0, NULL); satisfies_hash_partition -------------------------- - + f (1 row) -- remainder is null SELECT satisfies_hash_partition('mchash'::regclass, 4, NULL, NULL); satisfies_hash_partition -------------------------- - + f (1 row) -- too many arguments |