From 42749a65dbf1a38238775258bea53594fa803212 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Fri, 17 Apr 2015 14:27:31 -0600 Subject: [PATCH] Explicitly handle all partition types Error out if we see a partition type we don't understand. --- distribution_metadata.c | 36 +++++++++++++++++++++++++----------- distribution_metadata.h | 1 + prune_shard_list.c | 39 +++++++++++++++++++++++++-------------- prune_shard_list.h | 3 --- 4 files changed, 51 insertions(+), 28 deletions(-) diff --git a/distribution_metadata.c b/distribution_metadata.c index c2a140f..3e5f504 100644 --- a/distribution_metadata.c +++ b/distribution_metadata.c @@ -512,19 +512,33 @@ TupleToShardInterval(HeapTuple heapTuple, TupleDesc tupleDescriptor) Oid relationId = DatumGetObjectId(relationIdDatum); char partitionType = DatumGetChar(partitionTypeDatum); - if (partitionType == HASH_PARTITION_TYPE) + switch (partitionType) { - intervalTypeId = INT4OID; - } - else - { - Datum keyDatum = SPI_getbinval(heapTuple, tupleDescriptor, - TLIST_NUM_SHARD_KEY, &isNull); - char *partitionColumnName = TextDatumGetCString(keyDatum); + case APPEND_PARTITION_TYPE: + case RANGE_PARTITION_TYPE: + { + Datum keyDatum = SPI_getbinval(heapTuple, tupleDescriptor, + TLIST_NUM_SHARD_KEY, &isNull); + char *partitionColumnName = TextDatumGetCString(keyDatum); + + Var *partitionColumn = ColumnNameToColumn(relationId, partitionColumnName); + intervalTypeId = partitionColumn->vartype; + intervalTypeMod = partitionColumn->vartypmod; + break; + } - Var *partitionColumn = ColumnNameToColumn(relationId, partitionColumnName); - intervalTypeId = partitionColumn->vartype; - intervalTypeMod = partitionColumn->vartypmod; + case HASH_PARTITION_TYPE: + { + intervalTypeId = INT4OID; + break; + } + + default: + { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("unsupported table partition type: %c", + partitionType))); + } } getTypeInputInfo(intervalTypeId, &inputFunctionId, &typeIoParam); diff --git a/distribution_metadata.h b/distribution_metadata.h index 23c01eb..d44c269 100644 --- a/distribution_metadata.h +++ b/distribution_metadata.h @@ -52,6 +52,7 @@ #define TLIST_NUM_SHARD_PLACEMENT_NODE_PORT 5 /* denotes partition type of the distributed table */ +#define APPEND_PARTITION_TYPE 'a' #define HASH_PARTITION_TYPE 'h' #define RANGE_PARTITION_TYPE 'r' diff --git a/prune_shard_list.c b/prune_shard_list.c index 78fc08c..d14de5a 100644 --- a/prune_shard_list.c +++ b/prune_shard_list.c @@ -82,23 +82,34 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList) char partitionMethod = PartitionType(relationId); /* build the filter clause list for the partition method */ - if (partitionMethod == DISTRIBUTE_BY_HASH) + switch (partitionMethod) { - Node *hashedNode = HashableClauseMutator((Node *) whereClauseList, - partitionColumn); + case APPEND_PARTITION_TYPE: + case RANGE_PARTITION_TYPE: + { + restrictInfoList = BuildRestrictInfoList(whereClauseList); + break; + } - List *hashedClauseList = (List *) hashedNode; - restrictInfoList = BuildRestrictInfoList(hashedClauseList); - } - else - { - restrictInfoList = BuildRestrictInfoList(whereClauseList); - } + case HASH_PARTITION_TYPE: + { + Node *hashedNode = HashableClauseMutator((Node *) whereClauseList, + partitionColumn); - /* override the partition column for hash partitioning */ - if (partitionMethod == DISTRIBUTE_BY_HASH) - { - partitionColumn = MakeInt4Column(); + List *hashedClauseList = (List *) hashedNode; + restrictInfoList = BuildRestrictInfoList(hashedClauseList); + + /* override the partition column for hash partitioning */ + partitionColumn = MakeInt4Column(); + break; + } + + default: + { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("unsupported table partition type: %c", + partitionMethod))); + } } /* build the base expression for constraint */ diff --git a/prune_shard_list.h b/prune_shard_list.h index 7457016..d65103a 100644 --- a/prune_shard_list.h +++ b/prune_shard_list.h @@ -21,9 +21,6 @@ #include "nodes/primnodes.h" -/* character used to indicate a hash-partitioned table */ -#define DISTRIBUTE_BY_HASH 'h' - /* * Column ID used to signify that a partition column value has been replaced by * its hashed value.