Allow CTEs

pull/896/head
Onder Kalaci 2016-10-21 14:23:33 +03:00
parent de6bce36c9
commit 726ea93ca0
3 changed files with 37 additions and 34 deletions

View File

@ -300,7 +300,7 @@ CreateMultiTaskRouterPlan(Query *originalQuery,
* placements.
*
* The function errors out if the subquery is not router select query (i.e.,
* subqueries with non euqi-joins.).
* subqueries with non equi-joins.).
*/
static Task *
RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInterval,
@ -602,15 +602,6 @@ ErrorIfInsertSelectQueryNotSupported(Query *queryTree, RangeTblEntry *insertRte,
"SELECT queries")));
}
if (queryTree->cteList != NULL)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform distributed planning for the given "
"modification"),
errdetail("Common table expressions are not allowed in "
"INSERT ... SELECT queries")));
}
/* we don't support LIMIT, OFFSET and WINDOW functions */
ErrorIfMultiTaskRouterSelectQueryUnsupported(subquery);
@ -681,19 +672,6 @@ ErrorIfMultiTaskRouterSelectQueryUnsupported(Query *query)
"INSERT ... SELECT queries")));
}
/*
* We currently do not support CTEs. In order to handle CTEs, consider expanding
* IsPartitionColumnRecursive() to handle CTEs.
*/
if (subquery->cteList != NULL)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot perform distributed planning for the given "
"modification"),
errdetail("Common table expressions are not allowed in "
"INSERT ... SELECT queries")));
}
/* see comment on AddUninstantiatedPartitionColumnEqualityQual() */
if (subquery->setOperations != NULL)
{
@ -781,9 +759,8 @@ ErrorIfInsertPartitionColumnDoesNotMatchSelect(Query *query, RangeTblEntry *inse
* AddUninstantiatedPartitionColumnEqualityQual adds an equality qual
* to the SELECT query of the given originalQuery. The function currently
* does NOT add the quals if
* (i) CTEs are present on the top level query
* (ii) Set operations are present on the top level query
* (iii) Target list does not include a bare partition column.
* (i) Set operations are present on the top level query
* (ii) Target list does not include a bare partition column.
*
* Note that if the input query is not an INSERT .. SELECT the assertion fails.
*/

View File

@ -975,7 +975,7 @@ DEBUG: sent COMMIT over connection 13300009
DEBUG: sent COMMIT over connection 13300009
DEBUG: sent COMMIT over connection 13300010
DEBUG: sent COMMIT over connection 13300010
-- We do not support CTEs
-- We do not support some CTEs
WITH fist_table_agg AS
(SELECT sum(value_1) as v1_agg, user_id FROM raw_events_first GROUP BY user_id)
INSERT INTO agg_events
@ -987,9 +987,8 @@ INSERT INTO agg_events
DEBUG: StartTransactionCommand
DEBUG: StartTransaction
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
ERROR: cannot perform distributed planning for the given modification
DETAIL: Common table expressions are not allowed in INSERT ... SELECT queries
-- We do not support CTEs in the INSERT as well
ERROR: SELECT query should return bare partition column on the same ordinal position with INSERT query's partition column
-- We do support some CTEs
INSERT INTO agg_events
WITH sub_cte AS (SELECT 1)
SELECT
@ -999,8 +998,35 @@ INSERT INTO agg_events
DEBUG: StartTransactionCommand
DEBUG: StartTransaction
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
ERROR: cannot perform distributed planning for the given modification
DETAIL: Common table expressions are not allowed in INSERT ... SELECT queries
DEBUG: predicate pruning for shardId 13300001
DEBUG: predicate pruning for shardId 13300002
DEBUG: predicate pruning for shardId 13300003
DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) WITH sub_cte AS (SELECT 1) SELECT user_id, (SELECT sub_cte."?column?" FROM sub_cte) FROM public.raw_events_first_13300000 raw_events_first WHERE ((hashint4(user_id) >= '-2147483648'::integer) AND (hashint4(user_id) <= '-1073741825'::integer))
DEBUG: predicate pruning for shardId 13300000
DEBUG: predicate pruning for shardId 13300002
DEBUG: predicate pruning for shardId 13300003
DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_table_alias (user_id, value_1_agg) WITH sub_cte AS (SELECT 1) SELECT user_id, (SELECT sub_cte."?column?" FROM sub_cte) FROM public.raw_events_first_13300001 raw_events_first WHERE ((hashint4(user_id) >= '-1073741824'::integer) AND (hashint4(user_id) <= '-1'::integer))
DEBUG: predicate pruning for shardId 13300000
DEBUG: predicate pruning for shardId 13300001
DEBUG: predicate pruning for shardId 13300003
DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id, value_1_agg) WITH sub_cte AS (SELECT 1) SELECT user_id, (SELECT sub_cte."?column?" FROM sub_cte) FROM public.raw_events_first_13300002 raw_events_first WHERE ((hashint4(user_id) >= 0) AND (hashint4(user_id) <= 1073741823))
DEBUG: predicate pruning for shardId 13300000
DEBUG: predicate pruning for shardId 13300001
DEBUG: predicate pruning for shardId 13300002
DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) WITH sub_cte AS (SELECT 1) SELECT user_id, (SELECT sub_cte."?column?" FROM sub_cte) FROM public.raw_events_first_13300003 raw_events_first WHERE ((hashint4(user_id) >= 1073741824) AND (hashint4(user_id) <= 2147483647))
DEBUG: ProcessQuery
DEBUG: Plan is router executable
DEBUG: CommitTransactionCommand
DEBUG: CommitTransaction
DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
DEBUG: sent COMMIT over connection 13300008
DEBUG: sent COMMIT over connection 13300008
DEBUG: sent COMMIT over connection 13300011
DEBUG: sent COMMIT over connection 13300011
DEBUG: sent COMMIT over connection 13300009
DEBUG: sent COMMIT over connection 13300009
DEBUG: sent COMMIT over connection 13300010
DEBUG: sent COMMIT over connection 13300010
-- We do not support any set operations
INSERT INTO
raw_events_first(user_id)

View File

@ -307,7 +307,7 @@ WHERE
GROUP BY
raw_events_first.user_id;
-- We do not support CTEs
-- We do not support some CTEs
WITH fist_table_agg AS
(SELECT sum(value_1) as v1_agg, user_id FROM raw_events_first GROUP BY user_id)
INSERT INTO agg_events
@ -317,7 +317,7 @@ INSERT INTO agg_events
FROM
fist_table_agg;
-- We do not support CTEs in the INSERT as well
-- We do support some CTEs
INSERT INTO agg_events
WITH sub_cte AS (SELECT 1)
SELECT