diff -cpr HEAD/src/backend/storage/buffer/bufmgr.c BufFileCount/src/backend/storage/buffer/bufmgr.c
*** HEAD/src/backend/storage/buffer/bufmgr.c	Mon Aug 11 20:05:11 2008
--- BufFileCount/src/backend/storage/buffer/bufmgr.c	Tue Sep 16 10:27:22 2008
*************** bool		zero_damaged_pages = false;
*** 64,73 ****
  int			bgwriter_lru_maxpages = 100;
  double		bgwriter_lru_multiplier = 2.0;
  
! 
! long		NDirectFileRead;	/* some I/O's are direct file access. bypass
! 								 * bufmgr */
! long		NDirectFileWrite;	/* e.g., I/O in psort and hashjoin. */
  
  
  /* local state for StartBufferIO and related functions */
--- 64,75 ----
  int			bgwriter_lru_maxpages = 100;
  double		bgwriter_lru_multiplier = 2.0;
  
! /*
!  * Some I/O's are direct file access and bypass bufmgr. They occur
!  * typically in disk sorting, hashjoin and materializing using BufFile.
!  */
! long		BufFileReadCount;
! long		BufFileWriteCount;
  
  
  /* local state for StartBufferIO and related functions */
*************** ShowBufferUsage(void)
*** 1572,1578 ****
  					 ReadLocalBufferCount - LocalBufferHitCount, LocalBufferFlushCount, localhitrate);
  	appendStringInfo(&str,
  					 "!\tDirect blocks: %10ld read, %10ld written\n",
! 					 NDirectFileRead, NDirectFileWrite);
  
  	return str.data;
  }
--- 1574,1580 ----
  					 ReadLocalBufferCount - LocalBufferHitCount, LocalBufferFlushCount, localhitrate);
  	appendStringInfo(&str,
  					 "!\tDirect blocks: %10ld read, %10ld written\n",
! 					 BufFileReadCount, BufFileWriteCount);
  
  	return str.data;
  }
*************** ResetBufferUsage(void)
*** 1586,1593 ****
  	LocalBufferHitCount = 0;
  	ReadLocalBufferCount = 0;
  	LocalBufferFlushCount = 0;
! 	NDirectFileRead = 0;
! 	NDirectFileWrite = 0;
  }
  
  /*
--- 1588,1595 ----
  	LocalBufferHitCount = 0;
  	ReadLocalBufferCount = 0;
  	LocalBufferFlushCount = 0;
! 	BufFileReadCount = 0;
! 	BufFileWriteCount = 0;
  }
  
  /*
diff -cpr HEAD/src/backend/storage/file/buffile.c BufFileCount/src/backend/storage/file/buffile.c
*** HEAD/src/backend/storage/file/buffile.c	Fri May  2 10:08:27 2008
--- BufFileCount/src/backend/storage/file/buffile.c	Tue Sep 16 10:27:22 2008
***************
*** 34,39 ****
--- 34,40 ----
  
  #include "postgres.h"
  
+ #include "executor/execdebug.h"
  #include "storage/fd.h"
  #include "storage/buffile.h"
  
*************** BufFileLoadBuffer(BufFile *file)
*** 238,243 ****
--- 239,245 ----
  		file->nbytes = 0;
  	file->offsets[file->curFile] += file->nbytes;
  	/* we choose not to advance curOffset here */
+ 	BufFileReadCount++;
  }
  
  /*
*************** BufFileDumpBuffer(BufFile *file)
*** 300,305 ****
--- 302,308 ----
  		file->offsets[file->curFile] += bytestowrite;
  		file->curOffset += bytestowrite;
  		wpos += bytestowrite;
+ 		BufFileWriteCount++;
  	}
  	file->dirty = false;
  
diff -cpr HEAD/src/include/executor/execdebug.h BufFileCount/src/include/executor/execdebug.h
*** HEAD/src/include/executor/execdebug.h	Wed Jan  2 04:45:57 2008
--- BufFileCount/src/include/executor/execdebug.h	Tue Sep 16 10:27:22 2008
*************** extern int	NIndexTupleInserted;
*** 190,208 ****
  #define MJ_DEBUG_PROC_NODE(slot)
  #endif   /* EXEC_MERGEJOINDEBUG */
  
! /* ----------------------------------------------------------------
!  *		DO NOT DEFINE THESE EVER OR YOU WILL BURN!
!  * ----------------------------------------------------------------
!  */
! /* ----------------
!  *		NOTYET is placed around any code not yet implemented
!  *		in the executor.  Only remove these when actually implementing
!  *		said code.
!  * ----------------
!  */
! #undef NOTYET
! 
! extern long NDirectFileRead;
! extern long NDirectFileWrite;
  
  #endif   /* ExecDebugIncluded */
--- 190,197 ----
  #define MJ_DEBUG_PROC_NODE(slot)
  #endif   /* EXEC_MERGEJOINDEBUG */
  
! /* event counters in buffile.c */
! extern long BufFileReadCount;
! extern long BufFileWriteCount;
  
  #endif   /* ExecDebugIncluded */
