diff --git a/doc/src/sgml/ref/explain.sgml b/doc/src/sgml/ref/explain.sgml index 49c61cce69..26809d68d5 100644 --- a/doc/src/sgml/ref/explain.sgml +++ b/doc/src/sgml/ref/explain.sgml @@ -256,8 +256,9 @@ ROLLBACK; Include information on memory consumption by the query planning phase. - Report the precise amount of storage used by planner in-memory - structures, and total memory considering allocation overhead. + Specifically, include the precise amount of storage used by planner + in-memory structures, as well as total memory considering allocation + overhead. The parameter defaults to FALSE. diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 0a18a7abd8..2fa93998a3 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -660,7 +660,7 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, ExplainPropertyFloat("Planning Time", "ms", 1000.0 * plantime, 3, es); } - if (mem_counts) + if (es->memory && mem_counts != NULL) { ExplainOpenGroup("Planner Memory", "Planner Memory", true, es); show_planner_memory(es, mem_counts); @@ -3813,9 +3813,9 @@ show_planner_memory(ExplainState *es, if (es->format == EXPLAIN_FORMAT_TEXT) { appendStringInfo(es->str, - "Planner Memory: used=%zu bytes allocated=%zu bytes", - mem_counts->totalspace - mem_counts->freespace, - mem_counts->totalspace); + "Planner Memory: used=%lld bytes allocated=%lld bytes", + (long long) (mem_counts->totalspace - mem_counts->freespace), + (long long) mem_counts->totalspace); appendStringInfoChar(es->str, '\n'); } else diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 7e947e023b..e1577c791a 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -590,9 +590,12 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, if (es->memory) { /* - * Create a new memory context to measure planner's memory consumption - * accurately. We should use the same type of memory context as the - * planner would use. That's usually AllocSet but ensure that. + * In order to measure planner's memory consumption accurately, create + * a separate AllocSet memory context. + * + * XXX if planner is called under some other memory context type, this + * code overrides that. Do we need support to create context of + * programmatically determined type? */ Assert(IsA(CurrentMemoryContext, AllocSetContext)); planner_ctx = AllocSetContextCreate(CurrentMemoryContext,