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:
@ -77,9 +77,11 @@ typedef struct Counters
|
||||
int64 rows; /* total # of retrieved or affected rows */
|
||||
int64 shared_blks_hit; /* # of shared buffer hits */
|
||||
int64 shared_blks_read; /* # of shared disk blocks read */
|
||||
int64 shared_blks_dirtied; /* # of shared disk blocks dirtied */
|
||||
int64 shared_blks_written; /* # of shared disk blocks written */
|
||||
int64 local_blks_hit; /* # of local buffer hits */
|
||||
int64 local_blks_read; /* # of local disk blocks read */
|
||||
int64 local_blks_dirtied; /* # of local disk blocks dirtied */
|
||||
int64 local_blks_written; /* # of local disk blocks written */
|
||||
int64 temp_blks_read; /* # of temp blocks read */
|
||||
int64 temp_blks_written; /* # of temp blocks written */
|
||||
@ -652,12 +654,16 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
|
||||
pgBufferUsage.shared_blks_hit - bufusage.shared_blks_hit;
|
||||
bufusage.shared_blks_read =
|
||||
pgBufferUsage.shared_blks_read - bufusage.shared_blks_read;
|
||||
bufusage.shared_blks_dirtied =
|
||||
pgBufferUsage.shared_blks_dirtied - bufusage.shared_blks_dirtied;
|
||||
bufusage.shared_blks_written =
|
||||
pgBufferUsage.shared_blks_written - bufusage.shared_blks_written;
|
||||
bufusage.local_blks_hit =
|
||||
pgBufferUsage.local_blks_hit - bufusage.local_blks_hit;
|
||||
bufusage.local_blks_read =
|
||||
pgBufferUsage.local_blks_read - bufusage.local_blks_read;
|
||||
bufusage.local_blks_dirtied =
|
||||
pgBufferUsage.local_blks_dirtied - bufusage.local_blks_dirtied;
|
||||
bufusage.local_blks_written =
|
||||
pgBufferUsage.local_blks_written - bufusage.local_blks_written;
|
||||
bufusage.temp_blks_read =
|
||||
@ -766,9 +772,11 @@ pgss_store(const char *query, double total_time, uint64 rows,
|
||||
e->counters.rows += rows;
|
||||
e->counters.shared_blks_hit += bufusage->shared_blks_hit;
|
||||
e->counters.shared_blks_read += bufusage->shared_blks_read;
|
||||
e->counters.shared_blks_dirtied += bufusage->shared_blks_dirtied;
|
||||
e->counters.shared_blks_written += bufusage->shared_blks_written;
|
||||
e->counters.local_blks_hit += bufusage->local_blks_hit;
|
||||
e->counters.local_blks_read += bufusage->local_blks_read;
|
||||
e->counters.local_blks_dirtied += bufusage->local_blks_dirtied;
|
||||
e->counters.local_blks_written += bufusage->local_blks_written;
|
||||
e->counters.temp_blks_read += bufusage->temp_blks_read;
|
||||
e->counters.temp_blks_written += bufusage->temp_blks_written;
|
||||
@ -793,7 +801,8 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
#define PG_STAT_STATEMENTS_COLS 14
|
||||
#define PG_STAT_STATEMENTS_COLS_V1_0 14
|
||||
#define PG_STAT_STATEMENTS_COLS 16
|
||||
|
||||
/*
|
||||
* Retrieve statement statistics.
|
||||
@ -810,6 +819,7 @@ pg_stat_statements(PG_FUNCTION_ARGS)
|
||||
bool is_superuser = superuser();
|
||||
HASH_SEQ_STATUS hash_seq;
|
||||
pgssEntry *entry;
|
||||
bool sql_supports_dirty_counters = true;
|
||||
|
||||
if (!pgss || !pgss_hash)
|
||||
ereport(ERROR,
|
||||
@ -830,6 +840,8 @@ pg_stat_statements(PG_FUNCTION_ARGS)
|
||||
/* Build a tuple descriptor for our result type */
|
||||
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
|
||||
elog(ERROR, "return type must be a row type");
|
||||
if (tupdesc->natts == PG_STAT_STATEMENTS_COLS_V1_0)
|
||||
sql_supports_dirty_counters = false;
|
||||
|
||||
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
|
||||
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
||||
@ -887,14 +899,19 @@ pg_stat_statements(PG_FUNCTION_ARGS)
|
||||
values[i++] = Int64GetDatumFast(tmp.rows);
|
||||
values[i++] = Int64GetDatumFast(tmp.shared_blks_hit);
|
||||
values[i++] = Int64GetDatumFast(tmp.shared_blks_read);
|
||||
if (sql_supports_dirty_counters)
|
||||
values[i++] = Int64GetDatumFast(tmp.shared_blks_dirtied);
|
||||
values[i++] = Int64GetDatumFast(tmp.shared_blks_written);
|
||||
values[i++] = Int64GetDatumFast(tmp.local_blks_hit);
|
||||
values[i++] = Int64GetDatumFast(tmp.local_blks_read);
|
||||
if (sql_supports_dirty_counters)
|
||||
values[i++] = Int64GetDatumFast(tmp.local_blks_dirtied);
|
||||
values[i++] = Int64GetDatumFast(tmp.local_blks_written);
|
||||
values[i++] = Int64GetDatumFast(tmp.temp_blks_read);
|
||||
values[i++] = Int64GetDatumFast(tmp.temp_blks_written);
|
||||
|
||||
Assert(i == PG_STAT_STATEMENTS_COLS);
|
||||
Assert(i == sql_supports_dirty_counters ? \
|
||||
PG_STAT_STATEMENTS_COLS : PG_STAT_STATEMENTS_COLS_V1_0);
|
||||
|
||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
||||
}
|
||||
|
Reference in New Issue
Block a user