Skip to content

Commit

Permalink
Merge d5e772d into 036e3a8
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmp85 committed Feb 6, 2015
2 parents 036e3a8 + d5e772d commit e50b38e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
7 changes: 7 additions & 0 deletions expected/queries.out
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ INSERT INTO articles VALUES (47, 7, 'abeyance', 1772);
INSERT INTO articles VALUES (48, 8, 'alkylic', 18610);
INSERT INTO articles VALUES (49, 9, 'anyone', 2681);
INSERT INTO articles VALUES (50, 10, 'anjanette', 19519);
-- first, test zero-shard query
SELECT COUNT(*) FROM articles WHERE author_id = 1 AND author_id = 2;
count
-------
0
(1 row)

-- single-shard tests
-- test simple select for a single row
SELECT * FROM articles WHERE author_id = 10 AND id = 50;
Expand Down
26 changes: 16 additions & 10 deletions pg_shard.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,10 @@ ExtractRangeTableEntryWalker(Node *node, List **rangeTableList)

/*
* DistributedQueryShardList prunes the shards for the table in the query based
* on the query's restriction qualifiers, and returns this list. If the function
* cannot find any shards for the distributed table, it errors out. In other sense,
* the function errors out or returns a non-empty list.
* on the query's restriction qualifiers, and returns this list. It is possible
* that all shards will be pruned if a query's restrictions are unsatisfiable.
* In that case, this function can return an empty list; however, if the table
* being queried has no shards created whatsoever, this function errors out.
*/
static List *
DistributedQueryShardList(Query *query)
Expand Down Expand Up @@ -640,9 +641,6 @@ DistributedQueryShardList(Query *query)
prunedShardList = PruneShardList(distributedTableId, restrictClauseList,
shardIntervalList);

/* shouldn't be an empty list, but assert in case something's very wrong */
Assert(prunedShardList != NIL);

return prunedShardList;
}

Expand Down Expand Up @@ -1113,6 +1111,17 @@ PgShardExecutorStart(QueryDesc *queryDesc, int eflags)
bool topLevel = true;
LOCKMODE lockMode = NoLock;
EState *executorState = NULL;
bool zeroShardQuery = list_length(distributedPlan->taskList) == 0;

/* if query involves zero shards, just let it hit local table */
if (zeroShardQuery)
{
Plan *originalPlan = distributedPlan->originalPlan;
plannedStatement->planTree = originalPlan;

PgShardExecutorStart(queryDesc, eflags);
return;
}

/* disallow transactions and triggers during distributed commands */
PreventTransactionChain(topLevel, "distributed commands");
Expand Down Expand Up @@ -1778,10 +1787,7 @@ ExecuteSingleShardSelect(DistributedPlan *distributedPlan, EState *executorState
TupleTableSlot *tupleTableSlot = NULL;

List *taskList = distributedPlan->taskList;
if (list_length(taskList) != 1)
{
ereport(ERROR, (errmsg("cannot execute select over multiple shards")));
}
Assert(list_length(taskList) == 1);

task = (Task *) linitial(taskList);
tupleStore = tuplestore_begin_heap(false, false, work_mem);
Expand Down
3 changes: 3 additions & 0 deletions sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ INSERT INTO articles VALUES (48, 8, 'alkylic', 18610);
INSERT INTO articles VALUES (49, 9, 'anyone', 2681);
INSERT INTO articles VALUES (50, 10, 'anjanette', 19519);

-- first, test zero-shard query
SELECT COUNT(*) FROM articles WHERE author_id = 1 AND author_id = 2;

-- single-shard tests

-- test simple select for a single row
Expand Down

0 comments on commit e50b38e

Please sign in to comment.