Commit dea5f6ce authored by Heikki Linnakangas's avatar Heikki Linnakangas

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

Jeff Janes
parent 32fb4546
...@@ -2093,8 +2093,11 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples, ...@@ -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, ...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment