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 2 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: cannot plan SELECT query
DETAIL: There are no existing shards for the distributed table.
HINT: Run "master_create_worker_shards" to create shards for the distributed table.
\set VERBOSITY terse
SELECT master_create_worker_shards('articles', 2, 1);
WARNING: Connection failed to adeadhost:5432
Expand Down
12 changes: 11 additions & 1 deletion pg_shard.c
Expand Up @@ -226,8 +226,18 @@ 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);
if (queryShardList == NIL)
{
ereport(ERROR, (errmsg("cannot plan SELECT query"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message could be generated by an INSERT, UPDATE, or DELETE as well…

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the style guide says this should be in past tense: could not plan query.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE here: we have an object (the distributed table) which hasn't been initialized yet (by creating shards). This code is used in PostgreSQL for other analogous situations, such as not calling nextval for a sequence before asking it what its current value is (grep for it).

errdetail("There are no existing shards for the distributed table."),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation here is off (should be aligned with parenthesis right before errmsg, not those before ERROR).

errhint("Run \"master_create_worker_shards\" to create shards "
"for the distributed table.")));
}

/*
* If a select query touches multiple shards, we don't push down the
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