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. * placements.
* *
* The function errors out if the subquery is not router select query (i.e., * 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 * static Task *
RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInterval, RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInterval,
@ -602,15 +602,6 @@ ErrorIfInsertSelectQueryNotSupported(Query *queryTree, RangeTblEntry *insertRte,
"SELECT queries"))); "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 */ /* we don't support LIMIT, OFFSET and WINDOW functions */
ErrorIfMultiTaskRouterSelectQueryUnsupported(subquery); ErrorIfMultiTaskRouterSelectQueryUnsupported(subquery);
@ -681,19 +672,6 @@ ErrorIfMultiTaskRouterSelectQueryUnsupported(Query *query)
"INSERT ... SELECT queries"))); "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() */ /* see comment on AddUninstantiatedPartitionColumnEqualityQual() */
if (subquery->setOperations != NULL) if (subquery->setOperations != NULL)
{ {
@ -781,9 +759,8 @@ ErrorIfInsertPartitionColumnDoesNotMatchSelect(Query *query, RangeTblEntry *inse
* AddUninstantiatedPartitionColumnEqualityQual adds an equality qual * AddUninstantiatedPartitionColumnEqualityQual adds an equality qual
* to the SELECT query of the given originalQuery. The function currently * to the SELECT query of the given originalQuery. The function currently
* does NOT add the quals if * does NOT add the quals if
* (i) CTEs are present on the top level query * (i) Set operations are present on the top level query
* (ii) Set operations are present on the top level query * (ii) Target list does not include a bare partition column.
* (iii) Target list does not include a bare partition column.
* *
* Note that if the input query is not an INSERT .. SELECT the assertion fails. * 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 13300009
DEBUG: sent COMMIT over connection 13300010 DEBUG: sent COMMIT over connection 13300010
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 WITH fist_table_agg AS
(SELECT sum(value_1) as v1_agg, user_id FROM raw_events_first GROUP BY user_id) (SELECT sum(value_1) as v1_agg, user_id FROM raw_events_first GROUP BY user_id)
INSERT INTO agg_events INSERT INTO agg_events
@ -987,9 +987,8 @@ INSERT INTO agg_events
DEBUG: StartTransactionCommand DEBUG: StartTransactionCommand
DEBUG: StartTransaction DEBUG: StartTransaction
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 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 ERROR: SELECT query should return bare partition column on the same ordinal position with INSERT query's partition column
DETAIL: Common table expressions are not allowed in INSERT ... SELECT queries -- We do support some CTEs
-- We do not support CTEs in the INSERT as well
INSERT INTO agg_events INSERT INTO agg_events
WITH sub_cte AS (SELECT 1) WITH sub_cte AS (SELECT 1)
SELECT SELECT
@ -999,8 +998,35 @@ INSERT INTO agg_events
DEBUG: StartTransactionCommand DEBUG: StartTransactionCommand
DEBUG: StartTransaction DEBUG: StartTransaction
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: 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 DEBUG: predicate pruning for shardId 13300001
DETAIL: Common table expressions are not allowed in INSERT ... SELECT queries 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 -- We do not support any set operations
INSERT INTO INSERT INTO
raw_events_first(user_id) raw_events_first(user_id)

View File

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