Fix a crash on zero-shard tables

pull/1598/head
Metin Doslu 2017-08-18 13:53:59 +03:00
parent 96391bea15
commit 0d052e9864
3 changed files with 63 additions and 0 deletions

View File

@ -216,12 +216,19 @@ List *
PruneShards(Oid relationId, Index rangeTableId, List *whereClauseList)
{
DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(relationId);
int shardCount = cacheEntry->shardIntervalArrayLength;
char partitionMethod = cacheEntry->partitionMethod;
ClauseWalkerContext context = { 0 };
ListCell *pruneCell;
List *prunedList = NIL;
bool foundRestriction = false;
/* there are no shards to return */
if (shardCount == 0)
{
return NIL;
}
/* always return empty result if WHERE clause is of the form: false (AND ..) */
if (ContainsFalseClause(whereClauseList))
{

View File

@ -387,6 +387,46 @@ SELECT * FROM data_load_test ORDER BY col1;
(2 rows)
DROP TABLE data_load_test;
-- test queries on distributed tables with no shards
CREATE TABLE no_shard_test (col1 int, col2 text);
SELECT create_distributed_table('no_shard_test', 'col1', 'append');
create_distributed_table
--------------------------
(1 row)
SELECT * FROM no_shard_test WHERE col1 > 1;
col1 | col2
------+------
(0 rows)
DROP TABLE no_shard_test;
CREATE TABLE no_shard_test (col1 int, col2 text);
SELECT create_distributed_table('no_shard_test', 'col1', 'range');
create_distributed_table
--------------------------
(1 row)
SELECT * FROM no_shard_test WHERE col1 > 1;
col1 | col2
------+------
(0 rows)
DROP TABLE no_shard_test;
CREATE TABLE no_shard_test (col1 int, col2 text);
SELECT master_create_distributed_table('no_shard_test', 'col1', 'hash');
master_create_distributed_table
---------------------------------
(1 row)
SELECT * FROM no_shard_test WHERE col1 > 1;
col1 | col2
------+------
(0 rows)
DROP TABLE no_shard_test;
-- ensure writes in the same transaction as create_distributed_table are visible
BEGIN;
CREATE TABLE data_load_test (col1 int, col2 text, col3 serial);

View File

@ -206,6 +206,22 @@ SELECT create_distributed_table('data_load_test', 'col1');
SELECT * FROM data_load_test ORDER BY col1;
DROP TABLE data_load_test;
-- test queries on distributed tables with no shards
CREATE TABLE no_shard_test (col1 int, col2 text);
SELECT create_distributed_table('no_shard_test', 'col1', 'append');
SELECT * FROM no_shard_test WHERE col1 > 1;
DROP TABLE no_shard_test;
CREATE TABLE no_shard_test (col1 int, col2 text);
SELECT create_distributed_table('no_shard_test', 'col1', 'range');
SELECT * FROM no_shard_test WHERE col1 > 1;
DROP TABLE no_shard_test;
CREATE TABLE no_shard_test (col1 int, col2 text);
SELECT master_create_distributed_table('no_shard_test', 'col1', 'hash');
SELECT * FROM no_shard_test WHERE col1 > 1;
DROP TABLE no_shard_test;
-- ensure writes in the same transaction as create_distributed_table are visible
BEGIN;
CREATE TABLE data_load_test (col1 int, col2 text, col3 serial);