1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-09 13:09:39 +03:00

Extend EXPLAIN to support output in XML or JSON format.

There are probably still some adjustments to be made in the details
of the output, but this gets the basic structure in place.

Robert Haas
This commit is contained in:
Tom Lane
2009-08-10 05:46:50 +00:00
parent 18894c401f
commit 9bd27b7c9e
12 changed files with 1153 additions and 364 deletions

View File

@@ -91,7 +91,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.92 2009/08/01 20:59:17 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.93 2009/08/10 05:46:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2200,21 +2200,20 @@ tuplesort_restorepos(Tuplesortstate *state)
}
/*
* tuplesort_explain - produce a line of information for EXPLAIN ANALYZE
* tuplesort_get_stats - extract summary statistics
*
* This can be called after tuplesort_performsort() finishes to obtain
* printable summary information about how the sort was performed.
*
* The result is a palloc'd string.
* spaceUsed is measured in kilobytes.
*/
char *
tuplesort_explain(Tuplesortstate *state)
void
tuplesort_get_stats(Tuplesortstate *state,
const char **sortMethod,
const char **spaceType,
long *spaceUsed)
{
char *result = (char *) palloc(100);
long spaceUsed;
/*
* Note: it might seem we should print both memory and disk usage for a
* Note: it might seem we should provide both memory and disk usage for a
* disk-based sort. However, the current code doesn't track memory space
* accurately once we have begun to return tuples to the caller (since we
* don't account for pfree's the caller is expected to do), so we cannot
@@ -2223,38 +2222,34 @@ tuplesort_explain(Tuplesortstate *state)
* tell us how much is actually used in sortcontext?
*/
if (state->tapeset)
spaceUsed = LogicalTapeSetBlocks(state->tapeset) * (BLCKSZ / 1024);
{
*spaceType = "Disk";
*spaceUsed = LogicalTapeSetBlocks(state->tapeset) * (BLCKSZ / 1024);
}
else
spaceUsed = (state->allowedMem - state->availMem + 1023) / 1024;
{
*spaceType = "Memory";
*spaceUsed = (state->allowedMem - state->availMem + 1023) / 1024;
}
switch (state->status)
{
case TSS_SORTEDINMEM:
if (state->boundUsed)
snprintf(result, 100,
"Sort Method: top-N heapsort Memory: %ldkB",
spaceUsed);
*sortMethod = "top-N heapsort";
else
snprintf(result, 100,
"Sort Method: quicksort Memory: %ldkB",
spaceUsed);
*sortMethod = "quicksort";
break;
case TSS_SORTEDONTAPE:
snprintf(result, 100,
"Sort Method: external sort Disk: %ldkB",
spaceUsed);
*sortMethod = "external sort";
break;
case TSS_FINALMERGE:
snprintf(result, 100,
"Sort Method: external merge Disk: %ldkB",
spaceUsed);
*sortMethod = "external merge";
break;
default:
snprintf(result, 100, "sort still in progress");
*sortMethod = "still in progress";
break;
}
return result;
}