Merge pull request #535 from citusdata/fix/equality_operator_check

Change equality operator check for operator expressions
pull/548/head
Murat Tuncer 2016-06-06 12:51:28 +03:00
commit 3c0673be51
5 changed files with 35 additions and 31 deletions

View File

@ -3364,8 +3364,7 @@ SupportedLateralQuery(Query *parentQuery, Query *lateralQuery)
{
OpExpr *operatorExpression = NULL;
List *argumentList = NIL;
char *operatorName = NULL;
int equalsOperator = 0;
bool equalsOperator = false;
Expr *leftArgument = NULL;
Expr *rightArgument = NULL;
Expr *outerQueryExpression = NULL;
@ -3396,15 +3395,8 @@ SupportedLateralQuery(Query *parentQuery, Query *lateralQuery)
continue;
}
/*
* We accept all column types that can be joined with an equals sign as
* valid. These include columns that have cross-type equals operators
* (such as int48eq) and columns that can be casted at run-time (such as
* from numeric to int4).
*/
operatorName = get_opname(operatorExpression->opno);
equalsOperator = strncmp(operatorName, EQUAL_OPERATOR_STRING, NAMEDATALEN);
if (equalsOperator != 0)
equalsOperator = OperatorImplementsEquality(operatorExpression->opno);
if (!equalsOperator)
{
continue;
}

View File

@ -928,15 +928,8 @@ IsJoinClause(Node *clause)
bool equiJoin = false;
bool joinBetweenDifferentTables = false;
/*
* We accept all column types that can be joined with an equals sign as
* valid. These include columns that have cross-type equals operators
* (such as int48eq) and columns that can be casted at run-time (such as
* from numeric to int4).
*/
char *operatorName = get_opname(operatorExpression->opno);
int equalsOperator = strncmp(operatorName, EQUAL_OPERATOR_STRING, NAMEDATALEN);
if (equalsOperator == 0)
bool equalsOperator = OperatorImplementsEquality(operatorExpression->opno);
if (equalsOperator)
{
equiJoin = true;
}
@ -1956,3 +1949,29 @@ MultiSubqueryPushdownTable(RangeTblEntry *subqueryRangeTableEntry)
return subqueryTableNode;
}
/*
* OperatorImplementsEquality returns true if the given opno represents an
* equality operator. The function retrieves btree interpretation list for this
* opno and check if BTEqualStrategyNumber strategy is present.
*/
bool
OperatorImplementsEquality(Oid opno)
{
bool equalityOperator = false;
List *btreeIntepretationList = get_op_btree_interpretation(opno);
ListCell *btreeInterpretationCell = NULL;
foreach(btreeInterpretationCell, btreeIntepretationList)
{
OpBtreeInterpretation *btreeIntepretation = (OpBtreeInterpretation *)
lfirst(btreeInterpretationCell);
if (btreeIntepretation->strategy == BTEqualStrategyNumber)
{
equalityOperator = true;
break;
}
}
return equalityOperator;
}

View File

@ -2861,9 +2861,8 @@ HashableClauseMutator(Node *originalNode, Var *partitionColumn)
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);
bool usingEqualityOperator = OperatorImplementsEquality(
arrayOperatorExpression->opno);
/*
* Citus cannot prune hash-distributed shards with ANY/ALL. We show a NOTICE

View File

@ -1009,8 +1009,6 @@ ColumnMatchExpressionAtTopLevelConjunction(Node *node, Var *column)
OpExpr *opExpr = (OpExpr *) node;
bool simpleExpression = SimpleOpExpression((Expr *) opExpr);
bool columnInExpr = false;
char *operatorName = NULL;
int operatorNameComparison = 0;
bool usingEqualityOperator = false;
if (!simpleExpression)
@ -1024,10 +1022,7 @@ ColumnMatchExpressionAtTopLevelConjunction(Node *node, Var *column)
return false;
}
operatorName = get_opname(opExpr->opno);
operatorNameComparison = strncmp(operatorName, EQUAL_OPERATOR_STRING,
NAMEDATALEN);
usingEqualityOperator = (operatorNameComparison == 0);
usingEqualityOperator = OperatorImplementsEquality(opExpr->opno);
return usingEqualityOperator;
}

View File

@ -22,8 +22,6 @@
#include "nodes/pg_list.h"
/* Defines the operator string used for equi joins */
#define EQUAL_OPERATOR_STRING "="
#define SUBQUERY_RANGE_TABLE_ID -1
#define SUBQUERY_RELATION_ID 10000
#define HEAP_ANALYTICS_SUBQUERY_RELATION_ID 10001
@ -201,6 +199,7 @@ extern List * TableEntryList(List *rangeTableList);
extern bool ExtractRangeTableRelationWalker(Node *node, List **rangeTableList);
extern bool ExtractRangeTableEntryWalker(Node *node, List **rangeTableList);
extern List * pull_var_clause_default(Node *node);
extern bool OperatorImplementsEquality(Oid opno);
#endif /* MULTI_LOGICAL_PLANNER_H */