@@ -77,9 +77,11 @@ typedef struct Counters
77
77
int64 rows ; /* total # of retrieved or affected rows */
78
78
int64 shared_blks_hit ; /* # of shared buffer hits */
79
79
int64 shared_blks_read ; /* # of shared disk blocks read */
80
+ int64 shared_blks_dirtied ; /* # of shared disk blocks dirtied */
80
81
int64 shared_blks_written ; /* # of shared disk blocks written */
81
82
int64 local_blks_hit ; /* # of local buffer hits */
82
83
int64 local_blks_read ; /* # of local disk blocks read */
84
+ int64 local_blks_dirtied ; /* # of local disk blocks dirtied */
83
85
int64 local_blks_written ; /* # of local disk blocks written */
84
86
int64 temp_blks_read ; /* # of temp blocks read */
85
87
int64 temp_blks_written ; /* # of temp blocks written */
@@ -652,12 +654,16 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
652
654
pgBufferUsage .shared_blks_hit - bufusage .shared_blks_hit ;
653
655
bufusage .shared_blks_read =
654
656
pgBufferUsage .shared_blks_read - bufusage .shared_blks_read ;
657
+ bufusage .shared_blks_dirtied =
658
+ pgBufferUsage .shared_blks_dirtied - bufusage .shared_blks_dirtied ;
655
659
bufusage .shared_blks_written =
656
660
pgBufferUsage .shared_blks_written - bufusage .shared_blks_written ;
657
661
bufusage .local_blks_hit =
658
662
pgBufferUsage .local_blks_hit - bufusage .local_blks_hit ;
659
663
bufusage .local_blks_read =
660
664
pgBufferUsage .local_blks_read - bufusage .local_blks_read ;
665
+ bufusage .local_blks_dirtied =
666
+ pgBufferUsage .local_blks_dirtied - bufusage .local_blks_dirtied ;
661
667
bufusage .local_blks_written =
662
668
pgBufferUsage .local_blks_written - bufusage .local_blks_written ;
663
669
bufusage .temp_blks_read =
@@ -766,9 +772,11 @@ pgss_store(const char *query, double total_time, uint64 rows,
766
772
e -> counters .rows += rows ;
767
773
e -> counters .shared_blks_hit += bufusage -> shared_blks_hit ;
768
774
e -> counters .shared_blks_read += bufusage -> shared_blks_read ;
775
+ e -> counters .shared_blks_dirtied += bufusage -> shared_blks_dirtied ;
769
776
e -> counters .shared_blks_written += bufusage -> shared_blks_written ;
770
777
e -> counters .local_blks_hit += bufusage -> local_blks_hit ;
771
778
e -> counters .local_blks_read += bufusage -> local_blks_read ;
779
+ e -> counters .local_blks_dirtied += bufusage -> local_blks_dirtied ;
772
780
e -> counters .local_blks_written += bufusage -> local_blks_written ;
773
781
e -> counters .temp_blks_read += bufusage -> temp_blks_read ;
774
782
e -> counters .temp_blks_written += bufusage -> temp_blks_written ;
@@ -793,7 +801,8 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
793
801
PG_RETURN_VOID ();
794
802
}
795
803
796
- #define PG_STAT_STATEMENTS_COLS 14
804
+ #define PG_STAT_STATEMENTS_COLS_V1_0 14
805
+ #define PG_STAT_STATEMENTS_COLS 16
797
806
798
807
/*
799
808
* Retrieve statement statistics.
@@ -810,6 +819,7 @@ pg_stat_statements(PG_FUNCTION_ARGS)
810
819
bool is_superuser = superuser ();
811
820
HASH_SEQ_STATUS hash_seq ;
812
821
pgssEntry * entry ;
822
+ bool sql_supports_dirty_counters = true;
813
823
814
824
if (!pgss || !pgss_hash )
815
825
ereport (ERROR ,
@@ -830,6 +840,8 @@ pg_stat_statements(PG_FUNCTION_ARGS)
830
840
/* Build a tuple descriptor for our result type */
831
841
if (get_call_result_type (fcinfo , NULL , & tupdesc ) != TYPEFUNC_COMPOSITE )
832
842
elog (ERROR , "return type must be a row type" );
843
+ if (tupdesc -> natts == PG_STAT_STATEMENTS_COLS_V1_0 )
844
+ sql_supports_dirty_counters = false;
833
845
834
846
per_query_ctx = rsinfo -> econtext -> ecxt_per_query_memory ;
835
847
oldcontext = MemoryContextSwitchTo (per_query_ctx );
@@ -887,14 +899,19 @@ pg_stat_statements(PG_FUNCTION_ARGS)
887
899
values [i ++ ] = Int64GetDatumFast (tmp .rows );
888
900
values [i ++ ] = Int64GetDatumFast (tmp .shared_blks_hit );
889
901
values [i ++ ] = Int64GetDatumFast (tmp .shared_blks_read );
902
+ if (sql_supports_dirty_counters )
903
+ values [i ++ ] = Int64GetDatumFast (tmp .shared_blks_dirtied );
890
904
values [i ++ ] = Int64GetDatumFast (tmp .shared_blks_written );
891
905
values [i ++ ] = Int64GetDatumFast (tmp .local_blks_hit );
892
906
values [i ++ ] = Int64GetDatumFast (tmp .local_blks_read );
907
+ if (sql_supports_dirty_counters )
908
+ values [i ++ ] = Int64GetDatumFast (tmp .local_blks_dirtied );
893
909
values [i ++ ] = Int64GetDatumFast (tmp .local_blks_written );
894
910
values [i ++ ] = Int64GetDatumFast (tmp .temp_blks_read );
895
911
values [i ++ ] = Int64GetDatumFast (tmp .temp_blks_written );
896
912
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 );
898
915
899
916
tuplestore_putvalues (tupstore , tupdesc , values , nulls );
900
917
}
0 commit comments