mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Make EXPLAIN (BUFFERS) track blocks dirtied, as well as those written.
Also expose the new counters through pg_stat_statements. Patch by me. Review by Fujii Masao and Greg Smith.
This commit is contained in:
@ -1183,12 +1183,14 @@ ExplainNode(PlanState *planstate, List *ancestors,
|
||||
{
|
||||
bool has_shared = (usage->shared_blks_hit > 0 ||
|
||||
usage->shared_blks_read > 0 ||
|
||||
usage->shared_blks_written);
|
||||
usage->shared_blks_dirtied > 0 ||
|
||||
usage->shared_blks_written > 0);
|
||||
bool has_local = (usage->local_blks_hit > 0 ||
|
||||
usage->local_blks_read > 0 ||
|
||||
usage->local_blks_written);
|
||||
usage->local_blks_dirtied > 0 ||
|
||||
usage->local_blks_written > 0);
|
||||
bool has_temp = (usage->temp_blks_read > 0 ||
|
||||
usage->temp_blks_written);
|
||||
usage->temp_blks_written > 0);
|
||||
|
||||
/* Show only positive counter values. */
|
||||
if (has_shared || has_local || has_temp)
|
||||
@ -1205,6 +1207,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
|
||||
if (usage->shared_blks_read > 0)
|
||||
appendStringInfo(es->str, " read=%ld",
|
||||
usage->shared_blks_read);
|
||||
if (usage->shared_blks_dirtied > 0)
|
||||
appendStringInfo(es->str, " dirtied=%ld",
|
||||
usage->shared_blks_dirtied);
|
||||
if (usage->shared_blks_written > 0)
|
||||
appendStringInfo(es->str, " written=%ld",
|
||||
usage->shared_blks_written);
|
||||
@ -1220,6 +1225,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
|
||||
if (usage->local_blks_read > 0)
|
||||
appendStringInfo(es->str, " read=%ld",
|
||||
usage->local_blks_read);
|
||||
if (usage->local_blks_dirtied > 0)
|
||||
appendStringInfo(es->str, " dirtied=%ld",
|
||||
usage->local_blks_dirtied);
|
||||
if (usage->local_blks_written > 0)
|
||||
appendStringInfo(es->str, " written=%ld",
|
||||
usage->local_blks_written);
|
||||
@ -1243,9 +1251,11 @@ ExplainNode(PlanState *planstate, List *ancestors,
|
||||
{
|
||||
ExplainPropertyLong("Shared Hit Blocks", usage->shared_blks_hit, es);
|
||||
ExplainPropertyLong("Shared Read Blocks", usage->shared_blks_read, es);
|
||||
ExplainPropertyLong("Shared Dirtied Blocks", usage->shared_blks_dirtied, es);
|
||||
ExplainPropertyLong("Shared Written Blocks", usage->shared_blks_written, es);
|
||||
ExplainPropertyLong("Local Hit Blocks", usage->local_blks_hit, es);
|
||||
ExplainPropertyLong("Local Read Blocks", usage->local_blks_read, es);
|
||||
ExplainPropertyLong("Local Dirtied Blocks", usage->local_blks_dirtied, es);
|
||||
ExplainPropertyLong("Local Written Blocks", usage->local_blks_written, es);
|
||||
ExplainPropertyLong("Temp Read Blocks", usage->temp_blks_read, es);
|
||||
ExplainPropertyLong("Temp Written Blocks", usage->temp_blks_written, es);
|
||||
|
@ -137,9 +137,11 @@ BufferUsageAccumDiff(BufferUsage *dst,
|
||||
{
|
||||
dst->shared_blks_hit += add->shared_blks_hit - sub->shared_blks_hit;
|
||||
dst->shared_blks_read += add->shared_blks_read - sub->shared_blks_read;
|
||||
dst->shared_blks_dirtied += add->shared_blks_dirtied - sub->shared_blks_dirtied;
|
||||
dst->shared_blks_written += add->shared_blks_written - sub->shared_blks_written;
|
||||
dst->local_blks_hit += add->local_blks_hit - sub->local_blks_hit;
|
||||
dst->local_blks_read += add->local_blks_read - sub->local_blks_read;
|
||||
dst->local_blks_dirtied += add->local_blks_dirtied - sub->local_blks_dirtied;
|
||||
dst->local_blks_written += add->local_blks_written - sub->local_blks_written;
|
||||
dst->temp_blks_read += add->temp_blks_read - sub->temp_blks_read;
|
||||
dst->temp_blks_written += add->temp_blks_written - sub->temp_blks_written;
|
||||
|
@ -988,6 +988,7 @@ MarkBufferDirty(Buffer buffer)
|
||||
if (dirtied)
|
||||
{
|
||||
VacuumPageDirty++;
|
||||
pgBufferUsage.shared_blks_dirtied++;
|
||||
if (VacuumCostActive)
|
||||
VacuumCostBalance += VacuumCostPageDirty;
|
||||
if (ProcGlobal->bgwriterLatch)
|
||||
|
@ -276,6 +276,10 @@ MarkLocalBufferDirty(Buffer buffer)
|
||||
Assert(LocalRefCount[bufid] > 0);
|
||||
|
||||
bufHdr = &LocalBufferDescriptors[bufid];
|
||||
|
||||
if (!(bufHdr->flags & BM_DIRTY))
|
||||
pgBufferUsage.local_blks_dirtied++;
|
||||
|
||||
bufHdr->flags |= BM_DIRTY;
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,11 @@ typedef struct BufferUsage
|
||||
{
|
||||
long shared_blks_hit; /* # of shared buffer hits */
|
||||
long shared_blks_read; /* # of shared disk blocks read */
|
||||
long shared_blks_dirtied; /* # of shared blocks dirtied */
|
||||
long shared_blks_written; /* # of shared disk blocks written */
|
||||
long local_blks_hit; /* # of local buffer hits */
|
||||
long local_blks_read; /* # of local disk blocks read */
|
||||
long local_blks_dirtied; /* # of shared blocks dirtied */
|
||||
long local_blks_written; /* # of local disk blocks written */
|
||||
long temp_blks_read; /* # of temp blocks read */
|
||||
long temp_blks_written; /* # of temp blocks written */
|
||||
|
Reference in New Issue
Block a user