You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by ji...@apache.org on 2015/10/29 09:13:49 UTC

incubator-hawq git commit: HAWQ-82. Allocate query resource for EXPLAIN statement

Repository: incubator-hawq
Updated Branches:
  refs/heads/master f2fabc85b -> 3dc0d7bda


HAWQ-82. Allocate query resource for EXPLAIN statement


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

Branch: refs/heads/master
Commit: 3dc0d7bda7e708e72f2d29ce8bb989ff17645b58
Parents: f2fabc8
Author: Lirong Jian <ji...@gmail.com>
Authored: Thu Oct 29 15:39:11 2015 +0800
Committer: Lirong Jian <ji...@gmail.com>
Committed: Thu Oct 29 15:39:28 2015 +0800

----------------------------------------------------------------------
 src/backend/cdb/cdbpathlocus.c          |  4 ++--
 src/backend/commands/explain.c          |  4 ++--
 src/backend/commands/prepare.c          |  2 +-
 src/backend/optimizer/plan/createplan.c | 20 ++++++++++----------
 src/backend/optimizer/plan/planner.c    | 12 ------------
 src/backend/optimizer/plan/subselect.c  |  2 +-
 src/include/nodes/relation.h            |  2 --
 7 files changed, 16 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3dc0d7bd/src/backend/cdb/cdbpathlocus.c
----------------------------------------------------------------------
diff --git a/src/backend/cdb/cdbpathlocus.c b/src/backend/cdb/cdbpathlocus.c
index a84debf..c11db93 100644
--- a/src/backend/cdb/cdbpathlocus.c
+++ b/src/backend/cdb/cdbpathlocus.c
@@ -270,7 +270,7 @@ cdbpathlocus_from_baserel(struct PlannerInfo   *root,
 {
     CdbPathLocus result;
     GpPolicy   *policy = rel->cdbpolicy;
-    bool allocatedResource = root->glob->allocatedResource;
+    bool allocatedResource = (root->glob->resource != NULL);
 	
     if ( Gp_role != GP_ROLE_DISPATCH )
     {
@@ -282,7 +282,7 @@ cdbpathlocus_from_baserel(struct PlannerInfo   *root,
     {
 		    /* Are the rows distributed by hashing on specified columns? */
 		    bool isRelationRuntimeHash = true;
-		    if (root->glob->resource != NULL && root->glob->relsType != NIL) {
+		    if (allocatedResource && root->glob->relsType != NIL) {
 			      List* relsType = root->glob->relsType;
 			      Oid baseRelOid = 0;
 			      ListCell *lc;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3dc0d7bd/src/backend/commands/explain.c
----------------------------------------------------------------------
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index ba53a80..9f3987b 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -319,7 +319,7 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, const char *queryString,
 
 	/* plan the query */
 	//pstmt = planner(query, cursorOptions, params);
- 	plan = pg_plan_query(query,/*0,*/ params, stmt->analyze ? QRL_ONCE : QRL_NONE);
+ 	plan = pg_plan_query(query,/*0,*/ params, QRL_ONCE);
 
 	/*
 	 * Update snapshot command ID to ensure this query sees results of any
@@ -790,7 +790,7 @@ ExplainOnePlan_internal(PlannedStmt *plannedstmt,
     /*
      * Display final elapsed time.
      */
-	if (stmt->analyze)
+	if (stmt->analyze || stmt->verbose)
 	{
 		dispatcher_print_statistics(buf, estate->dispatch_data);
 		appendStringInfo(buf, "Data locality statistics:\n");

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3dc0d7bd/src/backend/commands/prepare.c
----------------------------------------------------------------------
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 89c2118..d3986c6 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -668,7 +668,7 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, ExplainStmt *stmt, const char * query
 	
 	
 	query_list = copyObject(entry->query_list); /* planner scribbles on query tree */
-	stmt_list = pg_plan_queries(query_list, paramLI, false, stmt->analyze ? QRL_ONCE : QRL_NONE);
+	stmt_list = pg_plan_queries(query_list, paramLI, false, QRL_ONCE);
 	
 	Assert(list_length(query_list) == list_length(stmt_list));
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3dc0d7bd/src/backend/optimizer/plan/createplan.c
----------------------------------------------------------------------
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index d95bbcb..f23fc9a 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -1226,7 +1226,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 	Oid				fmtErrTblOid = InvalidOid;
 	List			*segments = NIL;
 	ListCell		*lc;
-	bool hasResource = ctx->root->glob->allocatedResource;
+	bool allocatedResource = (ctx->root->glob->resource != NULL);
 
 	/* various processing flags */
 	bool			using_execute = false; /* true if EXECUTE is used */
@@ -1253,7 +1253,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 	scan_clauses = order_qual_clauses(ctx->root, scan_clauses);
 
 	/* get the total valid primary segdb count */
-	if (hasResource)
+	if (allocatedResource)
 	{
 	  segments = ctx->root->glob->resource->segments;
 	  total_primaries = list_length(segments);
@@ -1284,7 +1284,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 
 	/* various validations */
 
-	if(rel->writable && hasResource)
+	if(rel->writable && allocatedResource)
 		ereport(ERROR,
 				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 				errmsg("it is not possible to read from a WRITABLE external table."),
@@ -1428,7 +1428,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 			/*
 			 * We failed to find a segdb for this URI.
 			 */
-			if(hasResource && (!found_match))
+			if(allocatedResource && (!found_match))
 			{
 				if(uri->protocol == URI_FILE)
 				{
@@ -1535,7 +1535,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 				 total_primaries);
 		}
 
-		if(hasResource && (list_length(rel->locationlist) > num_segs_participating))
+		if(allocatedResource && (list_length(rel->locationlist) > num_segs_participating))
 			ereport(ERROR,
 					(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
 					 errmsg("There are more external files (URLs) than primary "
@@ -1564,7 +1564,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 					break;
 				}
 
-				if(hasResource && (list_length(modifiedloclist) > num_segs_participating))
+				if(allocatedResource && (list_length(modifiedloclist) > num_segs_participating))
 				{
 					elog(ERROR, "External scan location list failed building distribution.");
 				}
@@ -1622,7 +1622,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 			 * when is_custom_hd is true it means that the HD segment allocation algorithm
 			 * is activated and in this case it is not necessarily true that all segments are allocated
 			 */
-			if(hasResource && (!found_match))
+			if(allocatedResource && (!found_match))
 			{
 				/* should never happen */
 				elog(LOG, "external tables gpfdist(s) allocation error. "
@@ -1737,7 +1737,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 				}
 			}
 
-			if (hasResource && (!match_found))
+			if (allocatedResource && (!match_found))
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
 						 errmsg("Could not assign a segment database for "
@@ -1764,7 +1764,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 				}
 			}
 
-			if(hasResource && (!match_found))
+			if(allocatedResource && (!match_found))
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
 						 errmsg("Could not assign a segment database for "
@@ -1779,7 +1779,7 @@ create_externalscan_plan(CreatePlanContext *ctx, Path *best_path,
 
 			int		num_segs_to_use = atoi(on_clause + strlen("TOTAL_SEGS:"));
 
-			if(hasResource && (num_segs_to_use > total_primaries))
+			if(allocatedResource && (num_segs_to_use > total_primaries))
 				ereport(ERROR,
 						(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
 						 errmsg("Table defined with EXECUTE ON %d but there "

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3dc0d7bd/src/backend/optimizer/plan/planner.c
----------------------------------------------------------------------
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index ae81adf..a0d7ec3 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -578,18 +578,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
 	
 	parse = normalize_query(parse);
 
-	if (NULL == resource)
-	{
-	  glob->allocatedResource = false;
-	}
-	else
-	{
-	  /*
-	   * determine the segment number for this query.
-	   */
-	  glob->allocatedResource = true;
-	}
-
 	glob->resource = resource;
 
 	glob->relsType =relsType;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3dc0d7bd/src/backend/optimizer/plan/subselect.c
----------------------------------------------------------------------
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index 020b419..f2e4350 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -348,7 +348,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, SubLinkType subLinkType,
 {
 	Query	   *subquery = NULL;
 	double		tuple_fraction = 1.0;
-	bool hasResource = root->glob->allocatedResource;
+	bool hasResource = (root->glob->resource != NULL);
 	/*
 	 * Copy the source Query node.	This is a quick and dirty kluge to resolve
 	 * the fact that the parser can generate trees with multiple links to the

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/3dc0d7bd/src/include/nodes/relation.h
----------------------------------------------------------------------
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index b38b06c..e216c57 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -108,8 +108,6 @@ typedef struct PlannerGlobal
 	
 	struct QueryResource *resource;	/* the resource for the plan to be optimized and executed */
 
-	bool allocatedResource;     /* indicate whether resource has been allocated */
-
 	List* relsType; /* relation and relation runtime type list. for hash table may convert to random table in runtime*/
 } PlannerGlobal;