Take fillfactor into account in the new COPY bulk heap insert code.

Jeff Janes
This commit is contained in:
Heikki Linnakangas 2011-11-26 12:11:00 +02:00
parent 32fb4546e3
commit dea5f6cefe

View File

@ -2093,8 +2093,11 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
char *scratch = NULL; char *scratch = NULL;
Page page; Page page;
bool needwal; bool needwal;
Size saveFreeSpace;
needwal = !(options & HEAP_INSERT_SKIP_WAL) && RelationNeedsWAL(relation); needwal = !(options & HEAP_INSERT_SKIP_WAL) && RelationNeedsWAL(relation);
saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
HEAP_DEFAULT_FILLFACTOR);
/* Toast and set header data in all the tuples */ /* Toast and set header data in all the tuples */
heaptuples = palloc(ntuples * sizeof(HeapTuple)); heaptuples = palloc(ntuples * sizeof(HeapTuple));
@ -2157,7 +2160,7 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
{ {
HeapTuple heaptup = heaptuples[ndone + nthispage]; HeapTuple heaptup = heaptuples[ndone + nthispage];
if (PageGetHeapFreeSpace(page) < MAXALIGN(heaptup->t_len)) if (PageGetHeapFreeSpace(page) - saveFreeSpace < MAXALIGN(heaptup->t_len))
break; break;
RelationPutHeapTuple(relation, buffer, heaptup); RelationPutHeapTuple(relation, buffer, heaptup);