Avoid invalid array accesses to partitionFileArray

pull/2890/head
Philip Dubé 2019-08-15 15:56:40 +00:00
parent 519dc8329b
commit 9777f22e1e
3 changed files with 17 additions and 1 deletions

View File

@ -917,8 +917,13 @@ FilterAndPartitionTable(const char *filterQuery,
if (SPI_processed > 0)
{
TupleDesc rowDescriptor = SPI_tuptable->tupdesc;
partitionColumnIndex = ColumnIndex(rowDescriptor, partitionColumnName);
if (fileCount == 0)
{
ereport(ERROR, (errmsg("no partition to read into")));
}
partitionColumnIndex = ColumnIndex(rowDescriptor, partitionColumnName);
partitionColumnTypeId = SPI_gettypeid(rowDescriptor, partitionColumnIndex);
if (partitionColumnType != partitionColumnTypeId)
{
@ -942,6 +947,7 @@ FilterAndPartitionTable(const char *filterQuery,
while (SPI_processed > 0)
{
int rowIndex = 0;
for (rowIndex = 0; rowIndex < SPI_processed; rowIndex++)
{
HeapTuple row = SPI_tuptable->vals[rowIndex];
@ -964,6 +970,10 @@ FilterAndPartitionTable(const char *filterQuery,
if (!partitionKeyNull)
{
partitionId = (*PartitionIdFunction)(partitionKey, partitionIdContext);
if (partitionId == INVALID_SHARD_INDEX)
{
ereport(ERROR, (errmsg("invalid distribution column value")));
}
}
else
{

View File

@ -256,6 +256,9 @@ SELECT * FROM squares ORDER BY x;
5 | 25
(5 rows)
-- empty shard interval array should raise error
SELECT worker_hash_partition_table(42,1,'SELECT a FROM generate_series(1,100) AS a', 'a', 23, ARRAY[0]);
ERROR: invalid distribution column value
DROP SCHEMA intermediate_results CASCADE;
NOTICE: drop cascades to 5 other objects
DETAIL: drop cascades to table interesting_squares

View File

@ -141,4 +141,7 @@ WITH (FORMAT text);
SELECT * FROM squares ORDER BY x;
-- empty shard interval array should raise error
SELECT worker_hash_partition_table(42,1,'SELECT a FROM generate_series(1,100) AS a', 'a', 23, ARRAY[0]);
DROP SCHEMA intermediate_results CASCADE;