undo enabling set operations for INSERT .. SELECT

pull/1282/head
Onder Kalaci 2017-04-03 13:57:11 +03:00
parent 4c41096370
commit 0644e72539
8 changed files with 23 additions and 63 deletions

View File

@ -721,24 +721,7 @@ AddToAttributeEquivalenceClass(AttributeEquivalenceClass **attributeEquivalanceC
varToBeAdded = (Var *) subqueryTargetEntry->expr;
/* we need to handle set operations separately */
if (subquery->setOperations)
{
SetOperationStmt *unionStatement =
(SetOperationStmt *) subquery->setOperations;
RangeTblRef *leftRangeTableReference = (RangeTblRef *) unionStatement->larg;
RangeTblRef *rightRangeTableReference = (RangeTblRef *) unionStatement->rarg;
varToBeAdded->varno = leftRangeTableReference->rtindex;
AddToAttributeEquivalenceClass(attributeEquivalanceClass,
baseRelOptInfo->subroot, varToBeAdded);
varToBeAdded->varno = rightRangeTableReference->rtindex;
AddToAttributeEquivalenceClass(attributeEquivalanceClass,
baseRelOptInfo->subroot, varToBeAdded);
}
else if (varToBeAdded && IsA(varToBeAdded, Var) && varToBeAdded->varlevelsup == 0)
if (varToBeAdded && IsA(varToBeAdded, Var) && varToBeAdded->varlevelsup == 0)
{
AddToAttributeEquivalenceClass(attributeEquivalanceClass,
baseRelOptInfo->subroot, varToBeAdded);

View File

@ -879,16 +879,10 @@ MultiTaskRouterSelectQuerySupported(Query *query)
if (subquery->setOperations != NULL)
{
SetOperationStmt *setOperationStatement =
(SetOperationStmt *) subquery->setOperations;
if (setOperationStatement->op != SETOP_UNION)
{
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"INTERSECT and EXCEPT set operations are not "
"allowed in INSERT ... SELECT queries",
NULL, NULL);
}
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"Set operations are not allowed in INSERT ... SELECT "
"queries",
NULL, NULL);
}
/*

View File

@ -1132,14 +1132,13 @@ SELECT
FROM
((SELECT user_id FROM raw_events_first) UNION
(SELECT user_id FROM raw_events_second)) as foo;
ERROR: cannot perform distributed planning for the given modification
DETAIL: Select query cannot be pushed down to the worker.
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- We do not support any set operations
INSERT INTO
raw_events_first(user_id)
(SELECT user_id FROM raw_events_first) INTERSECT
(SELECT user_id FROM raw_events_first);
ERROR: INTERSECT and EXCEPT set operations are not allowed in INSERT ... SELECT queries
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- We do not support any set operations
INSERT INTO
raw_events_first(user_id)
@ -1148,7 +1147,7 @@ SELECT
FROM
((SELECT user_id FROM raw_events_first WHERE user_id = 15) EXCEPT
(SELECT user_id FROM raw_events_second where user_id = 17)) as foo;
ERROR: INTERSECT and EXCEPT set operations are not allowed in INSERT ... SELECT queries
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- some supported LEFT joins
INSERT INTO agg_events (user_id)
SELECT

View File

@ -69,13 +69,9 @@ FROM (
) t2 ON (t1.user_id = t2.user_id)
GROUP BY t1.user_id, hasdone_event
) t GROUP BY user_id, hasdone_event;
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- get some statistics from the aggregated results to ensure the results are correct
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
count | count | avg
-------+-------+---------------------
8 | 8 | 16.1250000000000000
(1 row)
-- SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
------------------------------------
------------------------------------
-- Funnel, grouped by the number of times a user has done an event
@ -147,13 +143,9 @@ GROUP BY
count_pay, user_id
ORDER BY
count_pay;
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- get some statistics from the aggregated results to ensure the results are correct
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
count | count | avg
-------+-------+---------------------
8 | 8 | 45.0000000000000000
(1 row)
-- SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
------------------------------------
------------------------------------
-- Most recently seen users_table events_table

View File

@ -101,6 +101,7 @@ FROM (
WHERE t1.user_id = 20
GROUP BY t1.user_id, hasdone_event
) t GROUP BY user_id, hasdone_event;
ERROR: Set operations are not allowed in INSERT ... SELECT queries
------------------------------------
------------------------------------
-- Funnel grouped by whether or not a user has done an event -- two shards query
@ -144,13 +145,9 @@ FROM (
WHERE (t1.user_id = 20 OR t1.user_id = 17)
GROUP BY t1.user_id, hasdone_event
) t GROUP BY user_id, hasdone_event;
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- get some statistics from the aggregated results to ensure the results are correct
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second;
count | count | avg
-------+-------+---------------------
2 | 2 | 18.5000000000000000
(1 row)
-- SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second;
------------------------------------
------------------------------------
-- Most recently seen users_table events_table -- single shard query

View File

@ -66,8 +66,7 @@ FROM (
) t2 ON (t1.user_id = t2.user_id)
GROUP BY t1.user_id, hasdone_event
) t GROUP BY user_id, hasdone_event;
ERROR: cannot perform distributed planning for the given modification
DETAIL: Select query cannot be pushed down to the worker.
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- not pushable since the JOIN is not an equi join right part of the UNION
-- is not joined on the partition key
INSERT INTO agg_results_third (user_id, value_1_agg, value_2_agg )
@ -108,8 +107,7 @@ FROM (
) t2 ON (t1.user_id = t2.user_id)
GROUP BY t1.user_id, hasdone_event
) t GROUP BY user_id, hasdone_event;
ERROR: cannot perform distributed planning for the given modification
DETAIL: Select query cannot be pushed down to the worker.
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- the LEFT JOIN conditon is not on the partition column (i.e., is it part_key divided by 2)
INSERT INTO agg_results_third (user_id, value_1_agg, value_2_agg )
SELECT user_id, sum(array_length(events_table, 1)), length(hasdone_event)
@ -149,8 +147,7 @@ FROM (
) t2 ON (t1.user_id = (t2.user_id)/2)
GROUP BY t1.user_id, hasdone_event
) t GROUP BY user_id, hasdone_event;
ERROR: cannot perform distributed planning for the given modification
DETAIL: Select query cannot be pushed down to the worker.
ERROR: Set operations are not allowed in INSERT ... SELECT queries
------------------------------------
------------------------------------
-- Funnel, grouped by the number of times a user has done an event
@ -223,8 +220,7 @@ GROUP BY
count_pay, user_id
ORDER BY
count_pay;
ERROR: cannot perform distributed planning for the given modification
DETAIL: Select query cannot be pushed down to the worker.
ERROR: Set operations are not allowed in INSERT ... SELECT queries
-- not pushable since the JOIN condition is not equi JOIN
-- (subquery_1 JOIN subquery_2)
INSERT INTO agg_results_third (user_id, value_1_agg, value_2_agg)
@ -292,8 +288,7 @@ GROUP BY
count_pay, user_id
ORDER BY
count_pay;
ERROR: cannot perform distributed planning for the given modification
DETAIL: Select query cannot be pushed down to the worker.
ERROR: Set operations are not allowed in INSERT ... SELECT queries
------------------------------------
------------------------------------
-- Most recently seen users_table events_table

View File

@ -71,7 +71,7 @@ FROM (
) t GROUP BY user_id, hasdone_event;
-- get some statistics from the aggregated results to ensure the results are correct
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
-- SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
------------------------------------
------------------------------------
@ -148,7 +148,7 @@ ORDER BY
count_pay;
-- get some statistics from the aggregated results to ensure the results are correct
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
-- SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results;
------------------------------------
------------------------------------

View File

@ -146,7 +146,7 @@ FROM (
) t GROUP BY user_id, hasdone_event;
-- get some statistics from the aggregated results to ensure the results are correct
SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second;
-- SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second;
------------------------------------