mirror of https://github.com/citusdata/citus.git
Merge pull request #1598 from citusdata/fix_no_shards_bug
Fix a crash on zero-shard tablespull/1592/head
commit
b5109028bc
|
@ -216,12 +216,19 @@ List *
|
||||||
PruneShards(Oid relationId, Index rangeTableId, List *whereClauseList)
|
PruneShards(Oid relationId, Index rangeTableId, List *whereClauseList)
|
||||||
{
|
{
|
||||||
DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(relationId);
|
DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(relationId);
|
||||||
|
int shardCount = cacheEntry->shardIntervalArrayLength;
|
||||||
char partitionMethod = cacheEntry->partitionMethod;
|
char partitionMethod = cacheEntry->partitionMethod;
|
||||||
ClauseWalkerContext context = { 0 };
|
ClauseWalkerContext context = { 0 };
|
||||||
ListCell *pruneCell;
|
ListCell *pruneCell;
|
||||||
List *prunedList = NIL;
|
List *prunedList = NIL;
|
||||||
bool foundRestriction = false;
|
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 ..) */
|
/* always return empty result if WHERE clause is of the form: false (AND ..) */
|
||||||
if (ContainsFalseClause(whereClauseList))
|
if (ContainsFalseClause(whereClauseList))
|
||||||
{
|
{
|
||||||
|
|
|
@ -387,6 +387,46 @@ SELECT * FROM data_load_test ORDER BY col1;
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
DROP TABLE data_load_test;
|
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
|
-- ensure writes in the same transaction as create_distributed_table are visible
|
||||||
BEGIN;
|
BEGIN;
|
||||||
CREATE TABLE data_load_test (col1 int, col2 text, col3 serial);
|
CREATE TABLE data_load_test (col1 int, col2 text, col3 serial);
|
||||||
|
|
|
@ -206,6 +206,22 @@ SELECT create_distributed_table('data_load_test', 'col1');
|
||||||
SELECT * FROM data_load_test ORDER BY col1;
|
SELECT * FROM data_load_test ORDER BY col1;
|
||||||
DROP TABLE data_load_test;
|
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
|
-- ensure writes in the same transaction as create_distributed_table are visible
|
||||||
BEGIN;
|
BEGIN;
|
||||||
CREATE TABLE data_load_test (col1 int, col2 text, col3 serial);
|
CREATE TABLE data_load_test (col1 int, col2 text, col3 serial);
|
||||||
|
|
Loading…
Reference in New Issue