hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ztao1...@apache.org
Subject incubator-hawq git commit: HAWQ-442. Fix bug that wrong results in rollup which contains the same expr targetlist.
Date Mon, 29 Feb 2016 02:57:13 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 98e6c144c -> cd864be03


HAWQ-442. Fix bug that wrong results in rollup which contains the same expr targetlist.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/cd864be0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/cd864be0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/cd864be0

Branch: refs/heads/master
Commit: cd864be03ed4c16e4f92fb2358c2ba5f4da01f41
Parents: 98e6c14
Author: zhenglin tao <zhenglin.taozl@gmail.com>
Authored: Fri Feb 26 14:13:17 2016 +0800
Committer: zhenglin tao <zhenglin.taozl@gmail.com>
Committed: Mon Feb 29 10:57:01 2016 +0800

----------------------------------------------------------------------
 src/backend/cdb/cdbgroup.c         | 14 +++++++++-----
 src/backend/optimizer/util/tlist.c | 21 +++++++++++++++++++++
 src/include/optimizer/tlist.h      |  4 ++++
 3 files changed, 34 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cd864be0/src/backend/cdb/cdbgroup.c
----------------------------------------------------------------------
diff --git a/src/backend/cdb/cdbgroup.c b/src/backend/cdb/cdbgroup.c
index 09b3da8..e049bc6 100644
--- a/src/backend/cdb/cdbgroup.c
+++ b/src/backend/cdb/cdbgroup.c
@@ -649,11 +649,16 @@ cdb_grouping_planner(PlannerInfo* root,
 		{
 			TargetEntry *tle = (TargetEntry*)lfirst(lc);
 			
+			/*
+			 * the first tlist whose expression is equal() to the expression of tle
+			 * may not be the desired one. We should also check if ressortgroupref is
+			 * same if ressortgroupref > 0
+			 */
 			if ( IsA(tle->expr, Var) && tle->resname == NULL )
 			{
 				TargetEntry *vartle =
-					tlist_member((Node*)tle->expr, group_context->tlist);
-				
+						tlist_member_with_ressortgroupref((Node*)tle->expr,
+								                          group_context->tlist, tle->ressortgroupref);
 				if ( vartle != NULL && vartle->resname != NULL )
 					tle->resname = pstrdup(vartle->resname);
 			}
@@ -3365,7 +3370,7 @@ Node* deconstruct_expr_mutator(Node *node, MppGroupContext *ctx)
 	 * a Var node referring to the (lower) preliminary aggregation's
 	 * target list.
 	 */
-	tle = tlist_member(node, ctx->grps_tlist);
+	tle = tlist_member_with_ressortgroupref(node, ctx->grps_tlist, ctx->split_aggref_sortgroupref);
 	if ( tle != NULL )
 	{
 		return  (Node*) makeVar(grp_varno, tle->resno,
@@ -3940,8 +3945,7 @@ add_second_stage_agg(PlannerInfo *root,
 		parse->targetList = copyObject(upper_tlist); /* Match range. */
 	}
 
-	result_plan = add_subqueryscan(root, p_current_pathkeys, 
-								   1, subquery, result_plan);
+	result_plan = add_subqueryscan(root, p_current_pathkeys, 1, subquery, result_plan);
 
 	/* Add an Agg node */
 	/* convert current_numGroups to long int */

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cd864be0/src/backend/optimizer/util/tlist.c
----------------------------------------------------------------------
diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c
index 35d813a..9590ead 100644
--- a/src/backend/optimizer/util/tlist.c
+++ b/src/backend/optimizer/util/tlist.c
@@ -77,6 +77,27 @@ tlist_member(Node *node, List *targetlist)
 }
 
 /*
+ * tlist_member_with_ressortgroupref
+ *    Compared with tlist_member, there is an additional check on ressortgroupref
+ */
+TargetEntry *
+tlist_member_with_ressortgroupref(Node *node, List *targetlist, int ressortgroupref) {
+	ListCell   *temp;
+
+	foreach(temp, targetlist)
+	{
+		TargetEntry *tlentry = (TargetEntry *) lfirst(temp);
+
+		Assert(IsA(tlentry, TargetEntry));
+
+		if (equal(node, tlentry->expr) && (ressortgroupref == 0 ||
+										   ressortgroupref == tlentry->ressortgroupref) )
+			return tlentry;
+	}
+	return NULL;
+}
+
+/*
  * tlist_members
  *	  Finds all members of the given tlist whose expression is
  *	  equal() to the given expression.	Result is NIL if no such member.

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cd864be0/src/include/optimizer/tlist.h
----------------------------------------------------------------------
diff --git a/src/include/optimizer/tlist.h b/src/include/optimizer/tlist.h
index e654551..a070e52 100644
--- a/src/include/optimizer/tlist.h
+++ b/src/include/optimizer/tlist.h
@@ -38,6 +38,10 @@
 // return the first target entries that match the node expression
 extern TargetEntry *tlist_member(Node *node, List *targetlist);
 
+// return the TargetEntry that match both the node expression and ressortgroupref
+extern TargetEntry *tlist_member_with_ressortgroupref(Node *node, List *targetlist,
+													  int ressortgroupref);
+
 // return a list a target entries that match the node expression
 extern List *tlist_members(Node *node, List *targetlist);
 


Mime
View raw message