From 3dc0d7bda7e708e72f2d29ce8bb989ff17645b58 Mon Sep 17 00:00:00 2001 From: Lirong Jian Date: Thu, 29 Oct 2015 15:39:11 +0800 Subject: [PATCH] HAWQ-82. Allocate query resource for EXPLAIN statement --- 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(-) diff --git a/src/backend/cdb/cdbpathlocus.c b/src/backend/cdb/cdbpathlocus.c index a84debf26f..c11db93f6d 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; diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index ba53a80b59..9f3987bf6f 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"); diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 89c211883b..d3986c689b 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)); diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index d95bbcbc26..f23fc9ac72 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 " diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index ae81adfcc7..a0d7ec396b 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; diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 020b419bfa..f2e4350189 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 diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index b38b06c263..e216c57375 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;