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-485. Wrong results in rollup with plan_append_aggs_with_rewrite.
Date Fri, 04 Mar 2016 01:35:27 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 5ba4e7bd3 -> 99c370b4f


HAWQ-485. Wrong results in rollup with plan_append_aggs_with_rewrite.


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

Branch: refs/heads/master
Commit: 99c370b4f82be50b86d11ccb88a9c6a4179497a5
Parents: 5ba4e7b
Author: zhenglin tao <zhenglin.taozl@gmail.com>
Authored: Thu Mar 3 15:27:15 2016 +0800
Committer: zhenglin tao <zhenglin.taozl@gmail.com>
Committed: Fri Mar 4 09:35:08 2016 +0800

----------------------------------------------------------------------
 src/backend/optimizer/plan/plangroupext.c | 25 ++++++++++++++++----
 src/backend/optimizer/plan/planner.c      |  4 +++-
 src/backend/optimizer/plan/setrefs.c      | 32 ++++++++++++++++++++------
 3 files changed, 49 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/99c370b4/src/backend/optimizer/plan/plangroupext.c
----------------------------------------------------------------------
diff --git a/src/backend/optimizer/plan/plangroupext.c b/src/backend/optimizer/plan/plangroupext.c
index 665f303..efc5355 100644
--- a/src/backend/optimizer/plan/plangroupext.c
+++ b/src/backend/optimizer/plan/plangroupext.c
@@ -2281,6 +2281,8 @@ typedef struct ReplaceGroupColsContext
 	 * appear inside an Aggref.
 	 */
 	bool in_aggref;
+
+	int ressortgroupref;
 } ReplaceGroupColsContext;
 
 
@@ -2293,13 +2295,26 @@ replace_grouping_columns_mutator(Node *node, void *v_cxt)
 	if (node == NULL)
 		return NULL;
 
+	if (IsA(node, TargetEntry))
+	{
+		cxt->ressortgroupref = ((TargetEntry *) node)->ressortgroupref;
+	}
+
 	Assert(IsA(cxt->grpcols, List));	
 
 	foreach (lc, cxt->grpcols)
 	{
 		Node *grpcol = lfirst(lc);
-		if (equal(node, grpcol))
-			break;
+
+		Assert(IsA(grpcol, TargetEntry));
+
+		TargetEntry *grpcoltle = (TargetEntry *) grpcol;
+
+		if (equal(node, (Node *)(grpcoltle->expr)))
+		{
+			if (cxt->ressortgroupref == 0 || cxt->ressortgroupref == grpcoltle->ressortgroupref)
+				break;
+		}
 	}
 
 	if (IsA(node, Aggref))
@@ -2323,10 +2338,11 @@ replace_grouping_columns_mutator(Node *node, void *v_cxt)
 		/* Generate a NULL constant to replace the node. */
 		Const *null;
 		Node *grpcol = lfirst(lc);
+		TargetEntry *grpcoltle = (TargetEntry *) grpcol;
 
 		if (!cxt->in_aggref)
 		{
-			null = makeNullConst(exprType((Node *)grpcol), -1);
+			null = makeNullConst(exprType((Node *)(grpcoltle->expr)), -1);
 			return (Node *)null;
 		}
 	}
@@ -2361,11 +2377,12 @@ replace_grouping_columns(Node *node,
 	{
 		TargetEntry *te = get_tle_by_resno(sub_tlist, grpColIdx[attno]);
 		Assert(te != NULL);
-		grpcols = lappend(grpcols, te->expr);
+		grpcols = lappend(grpcols, te);
 	}
 
 	cxt.grpcols = grpcols;
 	cxt.in_aggref = false;
+	cxt.ressortgroupref = 0;
 	
 	new_node = replace_grouping_columns_mutator((Node *)node, (void *)&cxt);
 	list_free(grpcols);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/99c370b4/src/backend/optimizer/plan/planner.c
----------------------------------------------------------------------
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 824558b..be057e0 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -2070,7 +2070,9 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
 
 						if ( IsA(tle->expr, Var) && tle->resname == NULL )
 						{
-							TargetEntry *vartle = tlist_member((Node*)tle->expr, tlist);
+							TargetEntry *vartle = tlist_member_with_ressortgroupref((Node*)tle->expr,
+																					tlist,
+																					tle->ressortgroupref);
 
 							if ( vartle != NULL && vartle->resname != NULL )
 								tle->resname = pstrdup(vartle->resname);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/99c370b4/src/backend/optimizer/plan/setrefs.c
----------------------------------------------------------------------
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 2f70516..e3b2096 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -88,6 +88,7 @@ typedef struct
 		indexed_tlist *subplan_itlist;
 		int			rtoffset;
 		bool		use_scan_slot;
+		int 		ressortgroupref;
 	} fix_upper_expr_context;
 
 /*
@@ -125,7 +126,8 @@ static Var *search_indexed_tlist_for_var(Var *var,
 										 int rtoffset);
 static Var *search_indexed_tlist_for_non_var(Node *node,
 											 indexed_tlist *itlist,
-											 Index newvarno);
+											 Index newvarno,
+											 int ressortgroupref);
 static List *fix_join_expr(PlannerGlobal *glob,
 						   List *clauses,
 						   indexed_tlist *outer_itlist,
@@ -1590,7 +1592,7 @@ set_upper_references(PlannerGlobal *glob, Plan *plan,
 			newexpr = copyObject(tle->expr);
 		else
 			newexpr = fix_upper_expr(glob,
-					(Node *) tle->expr,
+					(Node *) tle,
 					subplan_itlist,
 					rtoffset,
 					use_scan_slot);
@@ -1845,11 +1847,13 @@ search_indexed_tlist_for_var(Var *var, indexed_tlist *itlist,
  */
 static Var *
 search_indexed_tlist_for_non_var(Node *node,
-								 indexed_tlist *itlist, Index newvarno)
+								 indexed_tlist *itlist,
+								 Index newvarno,
+								 int ressortgroupref)
 {
 	TargetEntry *tle;
 	
-	tle = tlist_member(node, itlist->tlist);
+	tle = tlist_member_with_ressortgroupref(node, itlist->tlist, ressortgroupref);
 	if (tle)
 	{
 		/* Found a matching subplan output expression */
@@ -2067,7 +2071,8 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
 	{
 		newvar = search_indexed_tlist_for_non_var(node,
 												  context->outer_itlist,
-												  OUTER);
+												  OUTER,
+												  0);
 		if (newvar)
 			return (Node *) newvar;
 	}
@@ -2076,7 +2081,8 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
 	{
 		newvar = search_indexed_tlist_for_non_var(node,
 												  context->inner_itlist,
-												  INNER);
+												  INNER,
+												  0);
 		if (newvar)
 			return (Node *) newvar;
 	}
@@ -2134,6 +2140,17 @@ fix_upper_expr(PlannerGlobal *glob,
 	context.rtoffset = rtoffset;
 	context.use_scan_slot = use_scan_slot;
 	
+	if (node != NULL && IsA(node, TargetEntry))
+	{
+		TargetEntry *tle = (TargetEntry *) node;
+		node = (Node *) tle->expr;
+		context.ressortgroupref = tle->ressortgroupref;
+	}
+	else
+	{
+		context.ressortgroupref = 0;
+	}
+
 	return fix_upper_expr_mutator(node, &context);
 }
 
@@ -2169,7 +2186,8 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
 	{
 		newvar = search_indexed_tlist_for_non_var(node,
 												  context->subplan_itlist,
-												  slot_varno);
+												  slot_varno,
+												  context->ressortgroupref);
 		if (newvar)
 			return (Node *) newvar;
 	}


Mime
View raw message