File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2324,6 +2324,17 @@ FreeBulkInsertState(BulkInsertState bistate)
23242324	pfree (bistate );
23252325}
23262326
2327+ /* 
2328+  * ReleaseBulkInsertStatePin - release a buffer currently held in bistate 
2329+  */ 
2330+ void 
2331+ ReleaseBulkInsertStatePin (BulkInsertState  bistate )
2332+ {
2333+ 	if  (bistate -> current_buf  !=  InvalidBuffer )
2334+ 		ReleaseBuffer (bistate -> current_buf );
2335+ 	bistate -> current_buf  =  InvalidBuffer ;
2336+ }
2337+ 
23272338
23282339/* 
23292340 *	heap_insert		- insert tuple into a heap 
Original file line number Diff line number Diff line change @@ -2307,6 +2307,7 @@ CopyFrom(CopyState cstate)
23072307	uint64 		processed  =  0 ;
23082308	bool 		useHeapMultiInsert ;
23092309	int 			nBufferedTuples  =  0 ;
2310+ 	int 			prev_leaf_part_index  =  -1 ;
23102311
23112312#define  MAX_BUFFERED_TUPLES  1000
23122313	HeapTuple   * bufferedTuples  =  NULL ;	/* initialize to silence warning */ 
@@ -2561,6 +2562,17 @@ CopyFrom(CopyState cstate)
25612562			Assert (leaf_part_index  >= 0  && 
25622563				   leaf_part_index  <  cstate -> num_partitions );
25632564
2565+ 			/* 
2566+ 			 * If this tuple is mapped to a partition that is not same as the 
2567+ 			 * previous one, we'd better make the bulk insert mechanism gets a 
2568+ 			 * new buffer. 
2569+ 			 */ 
2570+ 			if  (prev_leaf_part_index  !=  leaf_part_index )
2571+ 			{
2572+ 				ReleaseBulkInsertStatePin (bistate );
2573+ 				prev_leaf_part_index  =  leaf_part_index ;
2574+ 			}
2575+ 
25642576			/* 
25652577			 * Save the old ResultRelInfo and switch to the one corresponding 
25662578			 * to the selected partition. 
Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ extern void setLastTid(const ItemPointer tid);
147147
148148extern  BulkInsertState  GetBulkInsertState (void );
149149extern  void  FreeBulkInsertState (BulkInsertState );
150+ extern  void  ReleaseBulkInsertStatePin (BulkInsertState  bistate );
150151
151152extern  Oid  heap_insert (Relation  relation , HeapTuple  tup , CommandId  cid ,
152153			int  options , BulkInsertState  bistate );
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments