Skip to content

Commit

Permalink
Merge 0186784 into c56862e
Browse files Browse the repository at this point in the history
  • Loading branch information
onderkalaci committed Jan 20, 2015
2 parents c56862e + 0186784 commit 7f5b717
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 28 deletions.
23 changes: 12 additions & 11 deletions expected/modifications.out.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,17 @@ INSERT INTO limit_orders VALUES (DEFAULT), (DEFAULT);
ERROR: multi-row INSERTs to distributed tables are not supported
-- insert from queries are unsupported
INSERT INTO limit_orders SELECT * FROM limit_orders;
ERROR: unsupported range table type: 1
ERROR: cannot perform distributed planning for the given query
DETAIL: Subqueries are not supported in distributed queries.
-- queries with a returning clause are unsupported
INSERT INTO limit_orders VALUES (7285, 'AMZN', 3278, '2016-01-05 02:07:36', 'sell', 0.00)
RETURNING *;
ERROR: cannot plan sharded modification that uses a RETURNING clause
-- queries containing a CTE are unsupported
WITH deleted_orders AS (DELETE FROM limit_orders RETURNING *)
INSERT INTO limit_orders DEFAULT VALUES;
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
ERROR: cannot perform distributed planning for the given query
DETAIL: Common table expressions are not supported in distributed queries.
-- test simple delete
INSERT INTO limit_orders VALUES (246, 'TSLA', 162, '2007-07-02 16:32:15', 'sell', 20.69);
SELECT COUNT(*) FROM limit_orders WHERE id = 246;
Expand Down Expand Up @@ -130,16 +131,16 @@ CREATE TABLE bidders ( name text, id bigint );
DELETE FROM limit_orders USING bidders WHERE limit_orders.id = 246 AND
limit_orders.bidder_id = bidders.id AND
bidders.name = 'Bernie Madoff';
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
ERROR: cannot perform distributed planning for the given query
DETAIL: Joins are not supported in distributed queries.
-- queries with a returning clause are unsupported
DELETE FROM limit_orders WHERE id = 246 RETURNING *;
ERROR: cannot plan sharded modification that uses a RETURNING clause
-- queries containing a CTE are unsupported
WITH deleted_orders AS (INSERT INTO limit_orders DEFAULT VALUES RETURNING *)
DELETE FROM limit_orders;
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
ERROR: cannot perform distributed planning for the given query
DETAIL: Common table expressions are not supported in distributed queries.
-- cursors are not supported
DELETE FROM limit_orders WHERE CURRENT OF cursor_name;
ERROR: cannot modify multiple shards during a single query
Expand Down Expand Up @@ -176,16 +177,16 @@ UPDATE limit_orders SET limit_price = 0.00 FROM bidders
WHERE limit_orders.id = 246 AND
limit_orders.bidder_id = bidders.id AND
bidders.name = 'Bernie Madoff';
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
ERROR: cannot perform distributed planning for the given query
DETAIL: Joins are not supported in distributed queries.
-- queries with a returning clause are unsupported
UPDATE limit_orders SET symbol = 'GM' WHERE id = 246 RETURNING *;
ERROR: cannot plan sharded modification that uses a RETURNING clause
-- queries containing a CTE are unsupported
WITH deleted_orders AS (INSERT INTO limit_orders DEFAULT VALUES RETURNING *)
UPDATE limit_orders SET symbol = 'GM';
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
ERROR: cannot perform distributed planning for the given query
DETAIL: Common table expressions are not supported in distributed queries.
-- cursors are not supported
UPDATE limit_orders SET symbol = 'GM' WHERE CURRENT OF cursor_name;
ERROR: cannot modify multiple shards during a single query
36 changes: 27 additions & 9 deletions expected/queries.out
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,38 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles
-- UNION/INTERSECT queries are unsupported
SELECT * FROM articles WHERE author_id = 10 UNION
SELECT * FROM articles WHERE author_id = 1;
ERROR: unsupported range table type: 1
ERROR: cannot perform distributed planning for the given query
DETAIL: Subqueries are not supported in distributed queries.
-- queries using CTEs are unsupported
CREATE TABLE authors ( name text, id bigint );
WITH long_names AS ( SELECT id FROM authors WHERE char_length(name) > 15 )
SELECT title FROM articles;
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
-- joins are unsupported
SELECT title, authors.name FROM authors, articles WHERE authors.id = articles.author_id;
ERROR: cannot perform distributed planning on this query
DETAIL: Joins are currently unsupported
-- subqueries are not supported
ERROR: cannot perform distributed planning for the given query
DETAIL: Common table expressions are not supported in distributed queries.
-- queries which involve functions in FROM clause are unsupported.
SELECT * FROM articles, position('om' in 'Thomas');
ERROR: cannot perform distributed planning for the given query
DETAIL: Functions must not appear in the FROM clause of a distributed query.
-- subqueries are not supported in WHERE clause
SELECT * FROM articles WHERE author_id IN (SELECT id FROM authors WHERE name LIKE '%a');
ERROR: unsupported range table type: 1
ERROR: cannot perform distributed planning for the given query
DETAIL: Subqueries are not supported in distributed queries.
-- subqueries are not supported in FROM clause
SELECT articles.id,test.word_count FROM articles, (SELECT id, word_count FROM articles) AS test where test.id = articles.id;
ERROR: cannot perform distributed planning for the given query
DETAIL: Subqueries are not supported in distributed queries.
-- subqueries are not supported in SELECT clause
SELECT a.title AS name,(SELECT a2.id FROM authors a2 WHERE a.id = a2.id LIMIT 1) AS special_price FROM articles a;
ERROR: cannot perform distributed planning for the given query
DETAIL: Subqueries are not supported in distributed queries.
-- joins are not supported in WHERE clause
SELECT title, authors.name FROM authors, articles WHERE authors.id = articles.author_id;
ERROR: cannot perform distributed planning for the given query
DETAIL: Joins are not supported in distributed queries.
-- joins are not supported in FROM clause
SELECT * FROM (articles INNER JOIN authors ON articles.id = authors.id);
ERROR: cannot perform distributed planning for the given query
DETAIL: Joins are not supported in distributed queries.
-- test cross-shard queries
SELECT COUNT(*) FROM articles;
count
Expand Down
63 changes: 58 additions & 5 deletions pg_shard.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,29 @@ ErrorIfQueryNotSupported(Query *queryTree)
errmsg("unsupported utility statement")));
}

/*
* Reject subqueries which are in SELECT or WHERE clause.
* Queries which include subqueries in FROM clauses are rejected below.
*/
if (queryTree->hasSubLinks == true)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform distributed planning for the given"
" query"),
errdetail("Subqueries are not supported in distributed"
" queries.")));
}

/* reject queries which include CommonTableExpr */
if (queryTree->cteList != NIL)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform distributed planning for the given"
" query"),
errdetail("Common table expressions are not supported in"
" distributed queries.")));
}

/* extract range table entries */
ExtractRangeTableEntryWalker((Node *) queryTree, &rangeTableList);

Expand All @@ -394,18 +417,48 @@ ErrorIfQueryNotSupported(Query *queryTree)
}
else
{
/* reject subquery, join, function or CTE range table entries */
ereport(ERROR, (errmsg("unsupported range table type: %d",
rangeTableEntry->rtekind)));
/*
* Error out for rangeTableEntries that we do not support.
* We do not explicitly specify "in FROM clause" in the error detail
* for the features that we do not support at all (SUBQUERY, JOIN).
* We do not need to check for RTE_CTE because all common table expressions
* are rejected above with queryTree->cteList check.
*/
char *rangeTableEntryErrorDetail = NULL;
if (rangeTableEntry->rtekind == RTE_SUBQUERY)
{
rangeTableEntryErrorDetail = "Subqueries are not supported in"
" distributed queries.";
}
else if (rangeTableEntry->rtekind == RTE_JOIN)
{
rangeTableEntryErrorDetail = "Joins are not supported in distributed"
" queries.";
}
else if (rangeTableEntry->rtekind == RTE_FUNCTION)
{
rangeTableEntryErrorDetail = "Functions must not appear in the FROM"
" clause of a distributed query.";
}
else
{
rangeTableEntryErrorDetail = "Unrecognized range table entry.";
}

ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform distributed planning for the given"
" query"),
errdetail("%s", rangeTableEntryErrorDetail)));
}
}

/* reject queries which involve joins */
if (queryTableCount != 1)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform distributed planning on this query"),
errdetail("Joins are currently unsupported")));
errmsg("cannot perform distributed planning for the given"
" query"),
errdetail("Joins are not supported in distributed queries.")));
}

/* reject queries which involve multi-row inserts */
Expand Down
18 changes: 15 additions & 3 deletions sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,24 @@ CREATE TABLE authors ( name text, id bigint );
WITH long_names AS ( SELECT id FROM authors WHERE char_length(name) > 15 )
SELECT title FROM articles;

-- joins are unsupported
SELECT title, authors.name FROM authors, articles WHERE authors.id = articles.author_id;
-- queries which involve functions in FROM clause are unsupported.
SELECT * FROM articles, position('om' in 'Thomas');

-- subqueries are not supported
-- subqueries are not supported in WHERE clause
SELECT * FROM articles WHERE author_id IN (SELECT id FROM authors WHERE name LIKE '%a');

-- subqueries are not supported in FROM clause
SELECT articles.id,test.word_count FROM articles, (SELECT id, word_count FROM articles) AS test where test.id = articles.id;

-- subqueries are not supported in SELECT clause
SELECT a.title AS name,(SELECT a2.id FROM authors a2 WHERE a.id = a2.id LIMIT 1) AS special_price FROM articles a;

-- joins are not supported in WHERE clause
SELECT title, authors.name FROM authors, articles WHERE authors.id = articles.author_id;

-- joins are not supported in FROM clause
SELECT * FROM (articles INNER JOIN authors ON articles.id = authors.id);

-- test cross-shard queries
SELECT COUNT(*) FROM articles;

Expand Down

0 comments on commit 7f5b717

Please sign in to comment.