From 559f9882995c32c76423d92e9a602146408f7fe0 Mon Sep 17 00:00:00 2001 From: Amul Sul Date: Thu, 16 Nov 2017 19:44:52 +0530 Subject: [PATCH 3/3] replace erreport by return false --- src/backend/catalog/partition.c | 48 ++++++++------------------- src/test/regress/expected/func_sanity.out | 54 +++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index ea93646509..520c3a05e6 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -3113,7 +3113,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS) uint64 rowHash = 0; /*---------- - * Error out if any of the following violated: + * Return false if any of the following violated: * * 1. Parent id, modulus, and the remainder should not be null. * 2. Parent id must be valid relation id, @@ -3121,22 +3121,16 @@ satisfies_hash_partition(PG_FUNCTION_ARGS) * 4. Remainder must be a non-negative integer less than the modulus. *---------- */ - if (!(PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))) - { - parentId = PG_GETARG_OID(0); - modulus = PG_GETARG_INT32(1); - remainder = PG_GETARG_INT32(2); - - if (!OidIsValid(parentId) || modulus <= 0 || remainder < 0 || - modulus <= remainder) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid hash partition bound"))); - } - else - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("parent relation id, modulus and the remainder cannot be null"))); + if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2)) + PG_RETURN_BOOL(false); + + parentId = PG_GETARG_OID(0); + modulus = PG_GETARG_INT32(1); + remainder = PG_GETARG_INT32(2); + + if (!OidIsValid(parentId) || modulus <= 0 || remainder < 0 || + modulus <= remainder) + PG_RETURN_BOOL(false); /* * Cache hash function information. @@ -3154,27 +3148,13 @@ satisfies_hash_partition(PG_FUNCTION_ARGS) key = RelationGetPartitionKey(parent); if (parent->rd_rel->relkind != RELKIND_PARTITIONED_TABLE || - key->strategy != PARTITION_STRATEGY_HASH) + key->strategy != PARTITION_STRATEGY_HASH || + key->partnatts != nkeys) { heap_close(parent, AccessShareLock); - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("\"%s\" is not a hash partitioned table", - get_rel_name(parentId)))); + PG_RETURN_BOOL(false); } - /* complain if too few column values; we ignore extras, however */ - if (key->partnatts > nkeys) - { - heap_close(parent, AccessShareLock); - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("value missing for partition column %d", - (nkeys + 1)))); - } - else - nkeys = key->partnatts; - fcinfo->flinfo->fn_extra = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt, offsetof(ColumnsHashData, partsupfunc) + diff --git a/src/test/regress/expected/func_sanity.out b/src/test/regress/expected/func_sanity.out index 0f85e4a1a1..a3cbc33b39 100644 --- a/src/test/regress/expected/func_sanity.out +++ b/src/test/regress/expected/func_sanity.out @@ -8,28 +8,64 @@ CREATE TABLE hash_parted(a int, b int) PARTITION BY HASH(a, b); CREATE TABLE list_parted(a int, b int) PARTITION BY LIST(a); -- Parent relation id, modulus and the remainder should not be null SELECT satisfies_hash_partition(NULL, NULL, NULL, NULL, NULL); -ERROR: parent relation id, modulus and the remainder cannot be null + satisfies_hash_partition +-------------------------- + f +(1 row) + SELECT satisfies_hash_partition('hash_parted'::regclass, NULL, NULL, NULL, NULL); -ERROR: parent relation id, modulus and the remainder cannot be null + satisfies_hash_partition +-------------------------- + f +(1 row) + SELECT satisfies_hash_partition('hash_parted'::regclass, 5, NULL, NULL, NULL); -ERROR: parent relation id, modulus and the remainder cannot be null + satisfies_hash_partition +-------------------------- + f +(1 row) + -- Remainder is greater than modulus SELECT satisfies_hash_partition('hash_parted'::regclass, 5, 6, NULL, NULL); -ERROR: invalid hash partition bound + satisfies_hash_partition +-------------------------- + f +(1 row) + -- Invalid modulus SELECT satisfies_hash_partition('hash_parted'::regclass, 0, 0, NULL, NULL); -ERROR: invalid hash partition bound + satisfies_hash_partition +-------------------------- + f +(1 row) + -- Invalid parent relation id SELECT satisfies_hash_partition(0, 6, 0, NULL, NULL); -ERROR: invalid hash partition bound + satisfies_hash_partition +-------------------------- + f +(1 row) + -- Parent is not a hash partitioned table. SELECT satisfies_hash_partition('pg_class'::regclass, 7, 6, NULL, NULL); -ERROR: "pg_class" is not a hash partitioned table + satisfies_hash_partition +-------------------------- + f +(1 row) + SELECT satisfies_hash_partition('list_parted'::regclass, 6, 2, NULL, NULL); -ERROR: "list_parted" is not a hash partitioned table + satisfies_hash_partition +-------------------------- + f +(1 row) + -- Less column values than partition column SELECT satisfies_hash_partition('hash_parted'::regclass, 6, 2, NULL); -ERROR: value missing for partition column 2 + satisfies_hash_partition +-------------------------- + f +(1 row) + -- Clean up. DROP TABLE hash_parted; DROP TABLE list_parted; -- 2.14.1