Merge pull request #392 from citusdata/bugfix/#258-spurious-notice-message-with-any

Fix spurious NOTICE messages with ANY/ALL
pull/415/head
Ahmet Eren Basak 2016-03-25 14:42:13 +02:00
commit ac05e561ed
3 changed files with 52 additions and 6 deletions

View File

@ -2896,8 +2896,25 @@ HashableClauseMutator(Node *originalNode, Var *partitionColumn)
}
else if (IsA(originalNode, ScalarArrayOpExpr))
{
ereport(NOTICE, (errmsg("cannot use shard pruning with ANY (array expression)"),
errhint("Consider rewriting the expression with OR clauses.")));
ScalarArrayOpExpr *arrayOperatorExpression = (ScalarArrayOpExpr *) originalNode;
Node *leftOpExpression = linitial(arrayOperatorExpression->args);
Node *strippedLeftOpExpression = strip_implicit_coercions(leftOpExpression);
char *operatorName = get_opname(arrayOperatorExpression->opno);
int equalsCompare = strncmp(operatorName, EQUAL_OPERATOR_STRING, NAMEDATALEN);
bool usingEqualityOperator = (equalsCompare == 0);
/*
* Citus cannot prune hash-distributed shards with ANY/ALL. We show a NOTICE
* if the expression is ANY/ALL performed on the partition column with equality.
*/
if (usingEqualityOperator && strippedLeftOpExpression != NULL &&
equal(strippedLeftOpExpression, partitionColumn))
{
ereport(NOTICE, (errmsg("cannot use shard pruning with "
"ANY/ALL (array expression)"),
errhint("Consider rewriting the expression with "
"OR/AND clauses.")));
}
}
/*

View File

@ -175,11 +175,30 @@ DEBUG: predicate pruning for shardId 111
explain statements for distributed queries are currently unsupported
(1 row)
-- Check that we don't support pruning for ANY (array expression)
-- Check that we don't support pruning for ANY (array expression) and give
-- a notice message when used with the partition column
EXPLAIN SELECT count(*) FROM orders_hash_partitioned
WHERE o_orderkey = ANY ('{1,2,3}');
NOTICE: cannot use shard pruning with ANY/ALL (array expression)
HINT: Consider rewriting the expression with OR/AND clauses.
QUERY PLAN
----------------------------------------------------------------------
explain statements for distributed queries are currently unsupported
(1 row)
-- Check that we don't show the message if the operator is not
-- equality operator
EXPLAIN SELECT count(*) FROM orders_hash_partitioned
WHERE o_orderkey < ALL ('{1,2,3}');
QUERY PLAN
----------------------------------------------------------------------
explain statements for distributed queries are currently unsupported
(1 row)
-- Check that we don't give a spurious hint message when non-partition
-- columns are used with ANY/IN/ALL
EXPLAIN SELECT count(*) FROM orders_hash_partitioned
WHERE o_orderkey = 1 OR o_totalprice IN (2, 5);
NOTICE: cannot use shard pruning with ANY (array expression)
HINT: Consider rewriting the expression with OR clauses.
QUERY PLAN
----------------------------------------------------------------------
explain statements for distributed queries are currently unsupported

View File

@ -91,8 +91,18 @@ EXPLAIN SELECT count(*) FROM
EXPLAIN SELECT count(*) FROM orders_hash_partitioned WHERE o_orderkey = abs(-1);
-- Check that we don't support pruning for ANY (array expression)
-- Check that we don't support pruning for ANY (array expression) and give
-- a notice message when used with the partition column
EXPLAIN SELECT count(*) FROM orders_hash_partitioned
WHERE o_orderkey = ANY ('{1,2,3}');
-- Check that we don't show the message if the operator is not
-- equality operator
EXPLAIN SELECT count(*) FROM orders_hash_partitioned
WHERE o_orderkey < ALL ('{1,2,3}');
-- Check that we don't give a spurious hint message when non-partition
-- columns are used with ANY/IN/ALL
EXPLAIN SELECT count(*) FROM orders_hash_partitioned
WHERE o_orderkey = 1 OR o_totalprice IN (2, 5);