Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error for incompletely created tables #38

Merged
merged 5 commits into from Jan 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions expected/queries.out
Expand Up @@ -13,6 +13,11 @@ SELECT master_create_distributed_table('articles', 'author_id');

(1 row)

-- test when a table is distributed but no shards created yet
SELECT count(*) from articles;
ERROR: could not find any shards for query
DETAIL: No shards exist for distributed table "articles".
HINT: Run master_create_worker_shards to create shards and try again.
\set VERBOSITY terse
SELECT master_create_worker_shards('articles', 2, 1);
WARNING: Connection failed to adeadhost:5432
Expand Down
33 changes: 27 additions & 6 deletions pg_shard.c
Expand Up @@ -226,7 +226,10 @@ PgShardPlanner(Query *query, int cursorOptions, ParamListInfo boundParams)

ErrorIfQueryNotSupported(distributedQuery);

/* compute the list of shards this query needs to access */
/*
* Compute the list of shards this query needs to access.
* Error out if there are no existing shards for the table.
*/
queryShardList = DistributedQueryShardList(distributedQuery);

/*
Expand Down Expand Up @@ -530,17 +533,35 @@ 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.
* 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.
*/
static List *
DistributedQueryShardList(Query *query)
{
Oid distributedTableId = ExtractFirstDistributedTableId(query);
List *restrictClauseList = NIL;
List *prunedShardList = NIL;

List *restrictClauseList = QueryRestrictList(query);
Oid distributedTableId = ExtractFirstDistributedTableId(query);
List *shardIntervalList = LookupShardIntervalList(distributedTableId);
List *prunedShardList = PruneShardList(distributedTableId, restrictClauseList,
shardIntervalList);

/* error out if no shards exists for the table */
if (shardIntervalList == NIL)
{
char *relationName = get_rel_name(distributedTableId);

ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("could not find any shards for query"),
errdetail("No shards exist for distributed table \"%s\".",
relationName),
errhint("Run master_create_worker_shards to create shards "
"and try again.")));
}

restrictClauseList = QueryRestrictList(query);
prunedShardList = PruneShardList(distributedTableId, restrictClauseList,
shardIntervalList);

return prunedShardList;
}
Expand Down
3 changes: 3 additions & 0 deletions sql/queries.sql
Expand Up @@ -11,6 +11,9 @@ CREATE TABLE articles (

SELECT master_create_distributed_table('articles', 'author_id');

-- test when a table is distributed but no shards created yet
SELECT count(*) from articles;

\set VERBOSITY terse
SELECT master_create_worker_shards('articles', 2, 1);
\set VERBOSITY default
Expand Down