@@ -77,9 +77,11 @@ typedef struct Counters
7777int64 rows ;/* total # of retrieved or affected rows */
7878int64 shared_blks_hit ;/* # of shared buffer hits */
7979int64 shared_blks_read ;/* # of shared disk blocks read */
80+ int64 shared_blks_dirtied ;/* # of shared disk blocks dirtied */
8081int64 shared_blks_written ;/* # of shared disk blocks written */
8182int64 local_blks_hit ;/* # of local buffer hits */
8283int64 local_blks_read ;/* # of local disk blocks read */
84+ int64 local_blks_dirtied ;/* # of local disk blocks dirtied */
8385int64 local_blks_written ;/* # of local disk blocks written */
8486int64 temp_blks_read ;/* # of temp blocks read */
8587int64 temp_blks_written ;/* # of temp blocks written */
@@ -652,12 +654,16 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
652654pgBufferUsage .shared_blks_hit - bufusage .shared_blks_hit ;
653655bufusage .shared_blks_read =
654656pgBufferUsage .shared_blks_read - bufusage .shared_blks_read ;
657+ bufusage .shared_blks_dirtied =
658+ pgBufferUsage .shared_blks_dirtied - bufusage .shared_blks_dirtied ;
655659bufusage .shared_blks_written =
656660pgBufferUsage .shared_blks_written - bufusage .shared_blks_written ;
657661bufusage .local_blks_hit =
658662pgBufferUsage .local_blks_hit - bufusage .local_blks_hit ;
659663bufusage .local_blks_read =
660664pgBufferUsage .local_blks_read - bufusage .local_blks_read ;
665+ bufusage .local_blks_dirtied =
666+ pgBufferUsage .local_blks_dirtied - bufusage .local_blks_dirtied ;
661667bufusage .local_blks_written =
662668pgBufferUsage .local_blks_written - bufusage .local_blks_written ;
663669bufusage .temp_blks_read =
@@ -766,9 +772,11 @@ pgss_store(const char *query, double total_time, uint64 rows,
766772e -> counters .rows += rows ;
767773e -> counters .shared_blks_hit += bufusage -> shared_blks_hit ;
768774e -> counters .shared_blks_read += bufusage -> shared_blks_read ;
775+ e -> counters .shared_blks_dirtied += bufusage -> shared_blks_dirtied ;
769776e -> counters .shared_blks_written += bufusage -> shared_blks_written ;
770777e -> counters .local_blks_hit += bufusage -> local_blks_hit ;
771778e -> counters .local_blks_read += bufusage -> local_blks_read ;
779+ e -> counters .local_blks_dirtied += bufusage -> local_blks_dirtied ;
772780e -> counters .local_blks_written += bufusage -> local_blks_written ;
773781e -> counters .temp_blks_read += bufusage -> temp_blks_read ;
774782e -> counters .temp_blks_written += bufusage -> temp_blks_written ;
@@ -793,7 +801,8 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
793801PG_RETURN_VOID ();
794802}
795803
796- #define PG_STAT_STATEMENTS_COLS 14
804+ #define PG_STAT_STATEMENTS_COLS_V1_0 14
805+ #define PG_STAT_STATEMENTS_COLS 16
797806
798807/*
799808 * Retrieve statement statistics.
@@ -810,6 +819,7 @@ pg_stat_statements(PG_FUNCTION_ARGS)
810819bool is_superuser = superuser ();
811820HASH_SEQ_STATUS hash_seq ;
812821pgssEntry * entry ;
822+ bool sql_supports_dirty_counters = true;
813823
814824if (!pgss || !pgss_hash )
815825ereport (ERROR ,
@@ -830,6 +840,8 @@ pg_stat_statements(PG_FUNCTION_ARGS)
830840/* Build a tuple descriptor for our result type */
831841if (get_call_result_type (fcinfo ,NULL ,& tupdesc )!= TYPEFUNC_COMPOSITE )
832842elog (ERROR ,"return type must be a row type" );
843+ if (tupdesc -> natts == PG_STAT_STATEMENTS_COLS_V1_0 )
844+ sql_supports_dirty_counters = false;
833845
834846per_query_ctx = rsinfo -> econtext -> ecxt_per_query_memory ;
835847oldcontext = MemoryContextSwitchTo (per_query_ctx );
@@ -887,14 +899,19 @@ pg_stat_statements(PG_FUNCTION_ARGS)
887899values [i ++ ]= Int64GetDatumFast (tmp .rows );
888900values [i ++ ]= Int64GetDatumFast (tmp .shared_blks_hit );
889901values [i ++ ]= Int64GetDatumFast (tmp .shared_blks_read );
902+ if (sql_supports_dirty_counters )
903+ values [i ++ ]= Int64GetDatumFast (tmp .shared_blks_dirtied );
890904values [i ++ ]= Int64GetDatumFast (tmp .shared_blks_written );
891905values [i ++ ]= Int64GetDatumFast (tmp .local_blks_hit );
892906values [i ++ ]= Int64GetDatumFast (tmp .local_blks_read );
907+ if (sql_supports_dirty_counters )
908+ values [i ++ ]= Int64GetDatumFast (tmp .local_blks_dirtied );
893909values [i ++ ]= Int64GetDatumFast (tmp .local_blks_written );
894910values [i ++ ]= Int64GetDatumFast (tmp .temp_blks_read );
895911values [i ++ ]= Int64GetDatumFast (tmp .temp_blks_written );
896912
897- Assert (i == PG_STAT_STATEMENTS_COLS );
913+ Assert (i == sql_supports_dirty_counters ? \
914+ PG_STAT_STATEMENTS_COLS :PG_STAT_STATEMENTS_COLS_V1_0 );
898915
899916tuplestore_putvalues (tupstore ,tupdesc ,values ,nulls );
900917}