summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbbas2012-04-17 13:10:57 +0000
committerAbbas2012-04-17 13:10:57 +0000
commit9aed10c153494d8ac8b7d3876642ba9bc542d035 (patch)
tree69ccfe57369fca7e449f0d7b8782b68aa3d1b302 /src
parent05375e85426e55f11b45a13e0804f51d3223d8c5 (diff)
Fix for node reduction in case of varchar data type.
Node reduction was not working in case of varchar data types and the reason was that the function pgxc_find_distcol_expr was not handling the RelabelType. This patch provide the proper handling. Also the patch changes the expected output of the test case xc_distkey to reflect changes in explain.
Diffstat (limited to 'src')
-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);