summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/pgxc/plan/planner.c14
-rw-r--r--src/test/regress/expected/xc_distkey.out54
2 files changed, 41 insertions, 27 deletions
diff --git a/src/backend/pgxc/plan/planner.c b/src/backend/pgxc/plan/planner.c
index e1017ce8f9..e155fa9b8f 100644
--- a/src/backend/pgxc/plan/planner.c
+++ b/src/backend/pgxc/plan/planner.c
@@ -1327,6 +1327,20 @@ pgxc_find_distcol_expr(Index varno, PartAttrNumber partAttrNum,
lexpr = linitial(op->args);
rexpr = lsecond(op->args);
+
+ /*
+ * If either of the operands is a RelabelType, extract the Var in the RelabelType.
+ * A RelabelType represents a "dummy" type coercion between two binary compatible datatypes.
+ * If we do not handle these then our optimization does not work in case of varchar
+ * For example if col is of type varchar and is the dist key then
+ * select * from vc_tab where col = 'abcdefghijklmnopqrstuvwxyz';
+ * should be shipped to one of the nodes only
+ */
+ if (IsA(lexpr, RelabelType))
+ lexpr = ((RelabelType*)lexpr)->arg;
+ if (IsA(rexpr, RelabelType))
+ rexpr = ((RelabelType*)rexpr)->arg;
+
/*
* If either of the operands is a Var expression, assume the other
* one is distribution column expression. If none is Var check next
diff --git a/src/test/regress/expected/xc_distkey.out b/src/test/regress/expected/xc_distkey.out
index 6b6cd29628..90b0f813ae 100644
--- a/src/test/regress/expected/xc_distkey.out
+++ b/src/test/regress/expected/xc_distkey.out
@@ -39,15 +39,15 @@ select * from nu_tab where 789.412 = a;
(1 row)
explain (costs false, num_nodes true, nodes false) select * from nu_tab where a = 123.456;
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
explain (costs false, num_nodes true, nodes false) select * from nu_tab where 789.412 = a;
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
create table tx_tab(a text) distribute by modulo(a);
@@ -85,15 +85,15 @@ select * from tx_tab where 'Did the quick brown fox jump over the lazy dog?' = a
(1 row)
explain (costs false, num_nodes true, nodes false) select * from tx_tab where a = 'hello world';
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
explain (costs false, num_nodes true, nodes false) select * from tx_tab where a = 'Did the quick brown fox jump over the lazy dog?';
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
create table vc_tab(a varchar(255)) distribute by modulo(a);
@@ -128,22 +128,22 @@ select * from vc_tab where 'A quick brown fox' = a;
(1 row)
explain (costs false, num_nodes true, nodes false) select * from vc_tab where a = 'abcdefghijklmnopqrstuvwxyz';
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
explain (costs false, num_nodes true, nodes false) select * from vc_tab where a = 'A quick brown fox';
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
-- This test a bug in examine_conditions_walker where a = constant is optimized but constant = a was not
explain (costs false, num_nodes true, nodes false) select * from vc_tab where 'A quick brown fox' = a;
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
create table f8_tab(a float8) distribute by modulo(a);
@@ -329,15 +329,15 @@ select * from i4_tab where 2147483647 = a;
(1 row)
explain (costs false, num_nodes true, nodes false) select * from i4_tab where 65530 = a;
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
explain (costs false, num_nodes true, nodes false) select * from i4_tab where a = 2147483647;
- QUERY PLAN
------------------------------------------------------
- Data Node Scan (primary node count=0, node count=1)
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Data Node Scan (primary node count=0, node count=1) on "__REMOTE_FQS_QUERY__"
(1 row)
create table bo_tab(a bool) distribute by modulo(a);